diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 57b504f..7e4304c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -21,6 +21,10 @@ @perms = user_perms & [Perm.grant_permissions, Perm.modify_templates, Perm.modify_guidance, Perm.use_api, Perm.change_org_details] end + def update_preferences + + end + ## # POST - updates the permissions for a user # redirects to the admin_index action 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..e69de29 --- /dev/null +++ b/app/views/devise/registrations/_password_details.html.erb 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..b72279d --- /dev/null +++ b/app/views/devise/registrations/_personal_details.html.erb @@ -0,0 +1,155 @@ +
+ <%= _("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.") %> +
+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put, class: "roadmap-form white_background"}) do |f| %> + + + +<% end %> + + + + diff --git a/app/views/users/_notification_preferences.html.erb b/app/views/users/_notification_preferences.html.erb new file mode 100644 index 0000000..5a79ec9 --- /dev/null +++ b/app/views/users/_notification_preferences.html.erb @@ -0,0 +1,59 @@ +<%= link_to 'Select all', '#' %> | + <%= link_to 'Deselect all', '#' %>
+<% byebug %> +All Users
+DMP owners and co-owners
+DMP administrators
+