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 @@ +
+ <%= _('If you would like to change your password please complete the following fields.') %> + +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+
+ + +
+
+
\ 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.") %> +

+ +
+ <%= _('You can edit any of the details below.') %> + + <%#= hidden_field_tag :unlink_flag, "false", id: "unlink_flag" %> + +
+ + + +
+ +
+ + +
+
+ + +
+ +
+ + + +
+ +
+ + <%= render partial: "shared/accessible_combobox", + locals: {name: "#{resource_name}[org_name]", + id: "#{resource_name}_org_name", + default_selection: @default_org, + models: @orgs, + attribute: 'name', + classes: 'fixed-width-large left-indent'} %> +
+ + <% if MANY_LANGUAGES %> +
+ <% lang = current_user.language.nil? ? FastGettext.default_locale : current_user.language.abbreviation %> + + +
+ <% end %> + + <% @identifier_schemes.each do |scheme| %> + <% + if scheme.name != 'shibboleth' || + (scheme.name == 'shibboleth' && Rails.application.config.shibboleth_enabled) + %> +
+ +
+ <%= render partial: 'external_identifier', + locals: {scheme: scheme, + id: current_user.identifier_for(scheme)} %> +
+
+ <% end %> + <% end %> + + <% unless @user.api_token.blank? %> +
+ <%= f.label :api_token, _('API token') %> +
<%= @user.api_token %>
+ + +
<%= link_to( _('How to use the API'), controller: "token_permission_types", action: "index")%>
+
+ <% end %> +
+ + + + + diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 44733a9..db16237 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,172 +1,49 @@ <% javascript "devise/registrations/edit.js" %> - -
+

<%= _('Edit profile') %>

-

- <%= _("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| %> - -
- <%= _('You can edit any of the details below.') %> +
+ - <%= hidden_field_tag :unlink_flag, "false", id: "unlink_flag" %> - -
- - - +
+
+ <%= render partial: 'devise/registrations/personal_details', f: f %>
-
- - -
-
- - + -
- - - + +
+
-
- - <%= render partial: "shared/accessible_combobox", - locals: {name: "#{resource_name}[org_name]", - id: "#{resource_name}_org_name", - default_selection: @default_org, - models: @orgs, - attribute: 'name', - classes: 'fixed-width-large left-indent'} %> -
+
- <% if MANY_LANGUAGES %> -
- <% lang = current_user.language.nil? ? FastGettext.default_locale : current_user.language.abbreviation %> - - -
- <% end %> - - <% @identifier_schemes.each do |scheme| %> - <% - if scheme.name != 'shibboleth' || - (scheme.name == 'shibboleth' && Rails.application.config.shibboleth_enabled) - %> -
- -
- <%= render partial: 'external_identifier', - locals: {scheme: scheme, - id: current_user.identifier_for(scheme)} %> -
-
- <% end %> - <% end %> - - <% unless @user.api_token.blank? %> -
- <%= f.label :api_token, _('API token') %> -
<%= @user.api_token %>
- - -
<%= link_to( _('How to use the API'), controller: "token_permission_types", action: "index")%>
-
- <% end %> - -
- - <%= _('If you would like to change your password please complete the following fields.') %> - -
- - - -
- -
- - - -
- -
- - - -
- -
-
- - -
-
- -
- - <%= render partial: 'shared/accessible_submit_button', - locals: {id: 'update', - val: 'Save', - disabled_initially: true, - classes: 'small-input-button', - tooltip: _('Enter all of the required information above')} %> -
-
- +
+ + <%= render partial: 'shared/accessible_submit_button', + locals: {id: 'update', + val: 'Save', + disabled_initially: true, + classes: 'small-input-button', + tooltip: _('Enter all of the required information above')} %> +
<% end %> -
- - - - +
\ No newline at end of file diff --git a/app/views/users/_notification_preferences.html.erb b/app/views/users/_notification_preferences.html.erb new file mode 100644 index 0000000..603b6df --- /dev/null +++ b/app/views/users/_notification_preferences.html.erb @@ -0,0 +1,65 @@ +

<%= link_to 'Select all', '#', id: 'select_all' %> | +<%= link_to 'Deselect all', '#', id: 'deselect_all' %>

+ +
+

All Users

+
+ + + <%#= check_box_tag 'prefs[users][permission_granted]', true, @user.prefs[:users][:permission_granted] %> + <%#= label_tag 'prefs[users][permission_granted]', 'New permissions granted to me', :class => 'checkbox-label' %> +
+
+ + + <%#= check_box_tag 'prefs[users][new_comment]', true, @user.prefs[:users][:new_comment] %> + <%#= label_tag 'prefs[users][new_comment]', 'A new comment has been added to my DMP', :class => 'checkbox-label' %> +
+
+ +

DMP owners and co-owners

+
+ + + <%#= check_box_tag 'prefs[owners_and_coowners][visibility_changed]', true, @user.prefs[:owners_and_coowners][:visibility_changed] %> + <%#= label_tag 'prefs[owners_and_coowners][visibility_changed]', "My DMP's visibility has changed", :class => 'checkbox-label' %> +
+
+ + + <%#= check_box_tag 'prefs[owners_and_coowners][user_added]', true, @user.prefs[:owners_and_coowners][:user_added] %> + <%#= label_tag 'prefs[owners_and_coowners][user_added]', 'I have been made a co-owner of a DMP', :class => 'checkbox-label' %> +
+ +
+

DMP administrators

+
+ + + <%#= check_box_tag 'prefs[admins][template_published]', true, @user.prefs[:admins][:template_published] %> + <%#= label_tag 'prefs[admins][template_published]', 'An organisational template is published', :class => 'checkbox-label' %> +
+
+ + + <%#= check_box_tag 'prefs[admins][template_unpublished]', true, @user.prefs[:admins][:template_unpublished] %> + <%#= label_tag 'prefs[admins][template_unpublished]', 'An organisational template is unpublished', :class => 'checkbox-label' %> +
+
+ + + \ No newline at end of file diff --git a/db/migrate/20170606215136_add_preferences_to_users.rb b/db/migrate/20170606215136_add_preferences_to_users.rb new file mode 100644 index 0000000..f570a76 --- /dev/null +++ b/db/migrate/20170606215136_add_preferences_to_users.rb @@ -0,0 +1,10 @@ +class AddPreferencesToUsers < ActiveRecord::Migration + + def self.up + add_column :users, :prefs, :binary + end + + def self.down + remove_column :users, :prefs + end +end diff --git a/lib/assets/stylesheets/roadmap-tabs.scss b/lib/assets/stylesheets/roadmap-tabs.scss index 9913fd5..bd781df 100644 --- a/lib/assets/stylesheets/roadmap-tabs.scss +++ b/lib/assets/stylesheets/roadmap-tabs.scss @@ -2,20 +2,20 @@ /* Roadmap Tab Styling */ /* ------------------------------------------------ */ -.tabs { +.tabs #user_profile.tabs { list-style: none; margin: 0; li { display: inline; - + a { position: relative; float: left; display: block; padding: 10px 35px; margin-left: -1px; - left: 1px; + left: 1px; color: $white; background-color: $primary-color; text-decoration: none; @@ -29,7 +29,7 @@ background-color: $white; } } -.tabs:after { +.tabs:after #user_profile.tabs:after { visibility: hidden; display: block; font-size: 0; @@ -37,19 +37,18 @@ clear: both; height: 0; } -.tab-panels { +.tab-panels #user_profile.tab-panels { position: relative; - min-height: 250px; + min-height: 400px; } -.tabbed-area div.tab-panel { - background: white; - padding: 10px 20px; - min-height: 230px; +.tabbed-area div.tab-panel #user_profile.tabbed-area #user-profile.tab-panel { + padding: 10px 10px; + min-height: 300px; position: absolute; top: -1px; left: 0; width: 100%; } -.tab-panel div.active { +.tab-panel div.active #user_profile.tab-panel { z-index: 1; } \ No newline at end of file diff --git a/lib/assets/stylesheets/roadmap.scss b/lib/assets/stylesheets/roadmap.scss index a54c03e..d989e6a 100644 --- a/lib/assets/stylesheets/roadmap.scss +++ b/lib/assets/stylesheets/roadmap.scss @@ -127,3 +127,19 @@ width: 35%; } } + + +.checkbox-label { + display: inline-block; + font-size: 1em; + margin: 0; + padding: 2px; +} + +.checkbox-input { + border: none; + vertical-align: middle; + height: 17px; + margin: 0 4px 0 0; + padding: 0; +}