diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index ff58a25..78ecb7c 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -15,9 +15,9 @@
IdentifierScheme.all.each do |scheme|
oauth = session["devise.#{scheme.name.downcase}_data"] unless session["devise.#{scheme.name.downcase}_data"].nil?
end
-
+
@user = User.new
-
+
unless oauth.nil?
# The OAuth provider could not be determined or there was no unique UID!
if oauth[:provider].nil? || oauth[:uid].nil?
@@ -26,7 +26,7 @@
else
# Connect the new user with the identifier sent back by the OAuth provider
flash[:notice] = t('identifier_schemes.new_login_success')
- UserIdentifier.create(identifier_scheme: oauth[:provider].upcase,
+ UserIdentifier.create(identifier_scheme: oauth[:provider].upcase,
identifier: oauth[:uid],
user: @user)
end
@@ -78,6 +78,7 @@
@identifier_schemes = IdentifierScheme.where(active: true).order(:name)
@languages = Language.sorted_by_abbreviation
do_update(require_password=needs_password?(current_user, params))
+ update_preferences(current_user, params)
else
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
end
@@ -165,22 +166,43 @@
end
end
+ def update_preferences(current_user, params)
+ prefs = params[:prefs]
+ # Set all preferences to false
+ current_user.prefs.each do |key, value|
+ value.each_key do |k|
+ current_user.prefs[key][k] = false
+ end
+ end
+
+ # Sets the preferences the user wants to true
+ if prefs
+ prefs.each_key do |key|
+ prefs[key].each_key do |k|
+ current_user.prefs[key.to_sym][k.to_sym] = true
+ end
+ end
+ end
+
+ current_user.save
+ end
+
def sign_up_params
- params.require(:user).permit(:email, :password, :password_confirmation,
+ params.require(:user).permit(:email, :password, :password_confirmation,
:firstname, :surname, :recovery_email,
- :accept_terms, :other_organisation)
+ :accept_terms, :other_organisation, :prefs)
end
def update_params
params.require(:user).permit(:firstname, :org_id, :other_organisation,
- :language_id, :surname)
+ :language_id, :surname, :prefs)
end
def password_update
params.require(:user).permit(:email, :firstname, :current_password,
:org_id, :language_id, :password,
:password_confirmation, :surname,
- :other_organisation)
+ :other_organisation, :prefs)
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index c1350f6..03c68ba 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -6,10 +6,15 @@
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
- devise :invitable, :database_authenticatable, :registerable, :recoverable,
- :rememberable, :trackable, :validatable, :omniauthable,
+ devise :invitable, :database_authenticatable, :registerable, :recoverable,
+ :rememberable, :trackable, :validatable, :omniauthable,
:omniauth_providers => [:shibboleth, :orcid]
+
+ ##
+ # User Notification Preferences
+ serialize :prefs, Hash
+
##
# Associations
has_and_belongs_to_many :perms, join_table: :users_perms
@@ -26,14 +31,14 @@
q = "%#{query}%"
conditions = t[:title].matches(q)
columns = %i(
- grant_number identifier description principal_investigator data_contact
+ grant_number identifier description principal_investigator data_contact
)
columns = ['grant_number', 'identifier', 'description', 'principal_investigator', 'data_contact']
columns.each {|col| conditions = conditions.or(t[col].matches(q)) }
self.where(conditions)
end
end
-
+
has_many :user_identifiers
has_many :identifier_schemes, through: :user_identifiers
@@ -41,16 +46,21 @@
# Possibly needed for active_admin
# -relies on protected_attributes gem as syntax depricated in rails 4.2
#accepts_nested_attributes_for :roles
- #attr_accessible :password_confirmation, :encrypted_password, :remember_me,
- # :id, :email, :firstname, :last_login,:login_count, :orcid_id,
- # :password, :shibboleth_id, :user_status_id, :surname,
- # :user_type_id, :org_id, :skip_invitation, :other_organisation,
+ #attr_accessible :password_confirmation, :encrypted_password, :remember_me,
+ # :id, :email, :firstname, :last_login,:login_count, :orcid_id,
+ # :password, :shibboleth_id, :user_status_id, :surname,
+ # :user_type_id, :org_id, :skip_invitation, :other_organisation,
# :accept_terms, :role_ids, :dmponline3, :api_token,
- # :organisation, :language, :language_id, :org, :perms,
+ # :organisation, :language, :language_id, :org, :perms,
# :confirmed_at, :org_id
validates :email, email: true, allow_nil: true, uniqueness: {message: _("must be unique")}
+
+ validates :prefs, presence: true
+ before_validation :create_default_preferences, if: Proc.new { |x| x.prefs.empty? }
+ ## user.prefs = create_default_preferences
+
##
# Scopes
default_scope { includes(:org, :perms, :plans) }
@@ -62,13 +72,13 @@
# What do they do? do they do it efficiently, and do we need them?
# Determines the locale set for the user or the organisation he/she belongs
- # @return String or nil
+ # @return String or nil
def get_locale
if !self.language.nil?
return self.language.abbreviation
elsif !self.org.nil?
return self.org.get_locale
- else
+ else
return nil
end
end
@@ -126,7 +136,7 @@
def organisation=(new_org)
org_id = new_org.id unless new_org.nil?
end
-
+
##
# checks if the user is a super admin
# if the user has any privelege which requires them to see the super admin page
@@ -144,7 +154,7 @@
#
# @return [Boolean] true if the user is an organisation admin
def can_org_admin?
- return self.can_grant_permissions? || self.can_modify_guidance? ||
+ return self.can_grant_permissions? || self.can_modify_guidance? ||
self.can_modify_templates? || self.can_modify_org_details?
end
@@ -223,7 +233,7 @@
return org_type
end
=end
-
+
##
# removes the api_token from the user
# modifies the user model
@@ -254,11 +264,11 @@
# --------------------------------------------------------------
def self.from_omniauth(auth)
scheme = IdentifierScheme.find_by(name: auth.provider.downcase)
-
+
if scheme.nil?
throw Exception.new('Unknown OAuth provider: ' + auth.provider)
else
- joins(:user_identifiers).where('user_identifiers.identifier': auth.uid,
+ joins(:user_identifiers).where('user_identifiers.identifier': auth.uid,
'user_identifiers.identifier_scheme_id': scheme.id).first
end
end
@@ -271,6 +281,29 @@
end
+ ##
+ # User Notification Preferences
+ def create_default_preferences
+ self.prefs = self.class.create_default_preferences
+ end
+
+ def self.create_default_preferences
+ default_prefs = {
+ users: {
+ permission_granted: true,
+ new_comment: true
+ },
+ owners_and_coowners: {
+ visibility_changed: true,
+ user_added: true
+ },
+ admins: {
+ template_published: true,
+ template_unpublished: true
+ }
+ }
+ end
+
# TODO: Remove this, its never called.
# this generates a reset password link for a given user
# which can then be sent to them with the appropriate host
@@ -278,12 +311,12 @@
=begin
def reset_password_link
raw, enc = Devise.token_generator.generate(self.class, :reset_password_token)
- self.reset_password_token = enc
+ self.reset_password_token = enc
self.reset_password_sent_at = Time.now.utc
save(validate: false)
edit_user_password_path + '?reset_password_token=' + raw
end
=end
-
+
end
diff --git a/app/views/devise/registrations/_password_details.html.erb b/app/views/devise/registrations/_password_details.html.erb
new file mode 100644
index 0000000..8ac19a3
--- /dev/null
+++ b/app/views/devise/registrations/_password_details.html.erb
@@ -0,0 +1,37 @@
+
\ No newline at end of file
diff --git a/app/views/devise/registrations/_personal_details.html.erb b/app/views/devise/registrations/_personal_details.html.erb
new file mode 100644
index 0000000..2c54efa
--- /dev/null
+++ b/app/views/devise/registrations/_personal_details.html.erb
@@ -0,0 +1,115 @@
+
+ <%= _("Please note that your email address is used as your username. If you change this, remember to use your new email address on sign in.") %>
+