diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 540d199..134ce0d 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -2,7 +2,7 @@ class RegistrationsController < Devise::RegistrationsController def edit - @user.create_default_preferences + @user.create_default_preferences if @user.prefs == {} @languages = Language.all.order("name") @orgs = Org.where(parent_id: nil).order("name") @other_organisations = Org.where(parent_id: nil, is_other: true).pluck(:id) @@ -70,7 +70,6 @@ end end - def update if user_signed_in? then @orgs = Org.where(parent_id: nil).order("name") @@ -78,8 +77,11 @@ @other_organisations = Org.where(parent_id: nil, is_other: true).pluck(:id) @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) + if params[:skip_personal_details] == true + do_update_password(current_user, params) + else + do_update(require_password=needs_password?(current_user, params)) + end else render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) end @@ -117,23 +119,12 @@ if mandatory_params # has the user entered all the details if require_password # user is changing email or password if current_user.email != params[:user][:email] # if user is changing email - if params[:user][:current_password].blank? # password needs to be present + if params[:user][:password].blank? # password needs to be present message = _('Please enter your password to change email address.') successfully_updated = false else successfully_updated = current_user.update_with_password(password_update) end - elsif params[:user][:password].present? # if user is changing password - successfully_updated = false # shared across first 3 conditions - if params[:user][:current_password].blank? - message = _('Please enter your current password') - elsif params[:user][:password_confirmation].blank? - message = _('Please enter a password confirmation') - elsif params[:user][:password] != params[:user][:password_confirmation] - message = _('Password and comfirmation must match') - else - successfully_updated = current_user.update_with_password(password_update) - end else # potentially unreachable... but I dont like to leave off the else successfully_updated = current_user.update_with_password(password_update) end @@ -167,25 +158,16 @@ 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 + def do_update_password(current_user, params) + if params[:user][:current_password].blank? + message = _('Please enter your current password') + elsif params[:user][:password_confirmation].blank? + message = _('Please enter a password confirmation') + elsif params[:user][:new_password] != params[:user][:password_confirmation] + message = _('Password and comfirmation must match') + else + successfully_updated = current_user.update_with_password(password_update) 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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 57b504f..f8253e3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,7 +7,7 @@ # Displays number of roles[was project_group], name, email, and last sign in def admin_index authorize User - @users = current_user.org.users.includes(:roles) + @users = @user.org.users.includes(:roles) end ## @@ -17,20 +17,20 @@ def admin_grant_permissions @user = User.includes(:perms).find(params[:id]) authorize @user - user_perms = current_user.perms + user_perms = @user.perms @perms = user_perms & [Perm.grant_permissions, Perm.modify_templates, Perm.modify_guidance, Perm.use_api, Perm.change_org_details] end ## # POST - updates the permissions for a user # redirects to the admin_index action - # should add validation that the perms given are current perms of the current_user + # should add validation that the perms given are current perms of the @user def admin_update_permissions @user = User.includes(:perms).find(params[:id]) authorize @user perms_ids = params[:perm_ids].blank? ? [] : params[:perm_ids].map(&:to_i) perms = Perm.where( id: perms_ids) - current_user.perms.each do |perm| + @user.perms.each do |perm| if @user.perms.include? perm if ! perms.include? perm @user.perms.delete(perm) @@ -55,4 +55,28 @@ end end + def update_preferences + @user = User.find(params[:user_id]) + prefs = params[:prefs] + authorize @user, :update? + # Set all preferences to false + @user.prefs.each do |key, value| + value.each_key do |k| + @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| + @user.prefs[key.to_sym][k.to_sym] = true + end + end + end + + @user.save + redirect_to edit_user_registration_path(@user), notice: _('Preferences successfully updated.') + end + end diff --git a/app/models/user.rb b/app/models/user.rb index 08ed05b..08f6317 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -292,16 +292,17 @@ def self.create_default_preferences default_prefs = { users: { - permission_granted: true, - new_comment: true + new_comment: true, + admin_privileges: true, + added_as_coowner: true }, owners_and_coowners: { - visibility_changed: true, - user_added: true + visibility_changed: true }, admins: { template_published: true, - template_unpublished: true + template_unpublished: true, + feedback_requested: true } } end diff --git a/app/views/devise/registrations/_external_identifier.html.erb b/app/views/devise/registrations/_external_identifier.html.erb deleted file mode 100644 index 226b270..0000000 --- a/app/views/devise/registrations/_external_identifier.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -
- <% if id.nil? || id.identifier == '' %> - <%= link_to "#{_("Link account with #{scheme.description} ID")}", - Rails.application.routes.url_helpers.send( - "user_#{scheme.name.downcase}_omniauth_authorize_path" - ), - title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip", default: "") - %> - <% else %> - <% if scheme.user_landing_url.nil? %> - <%= _("Your account has been linked to #{scheme.description}.") %> - <% else %> - <%= link_to "#{_("Your account has been linked to #{scheme.description}.")}", "#{scheme.user_landing_url}/#{id.identifier}", target: '_blank', - title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip", default: "") %> - <% end %> - <%= link_to ''.html_safe, - destroy_user_identifier_path(id), method: :delete, - title: _("Unlink your account from #{scheme.description}. You can link again at any time."), - data: {confirm: _("Are you sure you want to unlink #{scheme.description} ID?")} %> - <% end %> -
diff --git a/app/views/devise/registrations/_external_identifier_orcid.html.erb b/app/views/devise/registrations/_external_identifier_orcid.html.erb new file mode 100644 index 0000000..2ba5cf0 --- /dev/null +++ b/app/views/devise/registrations/_external_identifier_orcid.html.erb @@ -0,0 +1,15 @@ +
+ <% if id.nil? || id.identifier == '' %> + <%= link_to 'Create or Connect your Orcid iD', Rails.application.routes.url_helpers.send("user_#{scheme.name.downcase}_omniauth_authorize_path"), id:"connect-orcid-button", target: '_blank', title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip", default: "") %> + <% else %> + <% if scheme.user_landing_url.nil? %> + <%= _("Your account has been linked to #{scheme.description}.") %> + <% else %> + <%= link_to (image_tag("#{scheme.logo_url}", id: 'orcid-id-logo')) + "#{scheme.user_landing_url}/#{id.identifier}", "#{scheme.user_landing_url}/#{id.identifier}", id: 'orcid-id', target: '_blank', title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip", default: "") %> + <% end %> + <%= link_to ''.html_safe, + destroy_user_identifier_path(id), method: :delete, + title: _("Unlink your account from #{scheme.description}. You can link again at any time."), + data: {confirm: _("Are you sure you want to unlink #{scheme.description} ID?")} %> + <% end %> +
\ No newline at end of file diff --git a/app/views/devise/registrations/_external_identifier_shibboleth.html.erb b/app/views/devise/registrations/_external_identifier_shibboleth.html.erb new file mode 100644 index 0000000..39078c1 --- /dev/null +++ b/app/views/devise/registrations/_external_identifier_shibboleth.html.erb @@ -0,0 +1,21 @@ +
+ <% if id.nil? || id.identifier == '' %> + <%= link_to "#{_("Link account with #{scheme.description} ID")}", + Rails.application.routes.url_helpers.send( + "user_#{scheme.name.downcase}_omniauth_authorize_path" + ), + title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip", default: "") + %> + <% else %> + <% if scheme.user_landing_url.nil? %> + <%= _("Your account has been linked to #{scheme.description}.") %> + <% else %> + <%= link_to "#{_("Your account has been linked to #{scheme.description}.")}", "#{scheme.user_landing_url}/#{id.identifier}", target: '_blank', + title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip", default: "") %> + <% end %> + <%= link_to ''.html_safe, + destroy_user_identifier_path(id), method: :delete, + title: _("Unlink your account from #{scheme.description}. You can link again at any time."), + data: {confirm: _("Are you sure you want to unlink #{scheme.description} ID?")} %> + <% end %> +
\ No newline at end of file diff --git a/app/views/devise/registrations/_password_details.html.erb b/app/views/devise/registrations/_password_details.html.erb index 8ac19a3..d953505 100644 --- a/app/views/devise/registrations/_password_details.html.erb +++ b/app/views/devise/registrations/_password_details.html.erb @@ -1,37 +1,52 @@ -
- <%= _('If you would like to change your password please complete the following fields.') %> +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put, class: "roadmap-form white_background"}) do |f| %> +
+ <%= _('If you would like to change your password please complete the following fields.') %> -
- - - -
+ <%= hidden_field_tag :skip_personal_details, "true" %> -
- - - -
- -
- - - -
- -
-
- - +
+ + +
+ +
+ + + +
+ +
+ + + +
+ +
+
+ + +
+
+
+ +
+ + <%= render partial: 'shared/accessible_submit_button', + locals: {id: 'update', + val: 'Save', + disabled_initially: false, + classes: 'small-input-button', + tooltip: _('Enter all of the required information above')} %> + <%= link_to 'Cancel', '#', style: 'text-decoration:none;' %>
-
\ No newline at end of file +<% end %> \ 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 index 7a0bd0a..7899829 100644 --- a/app/views/devise/registrations/_personal_details.html.erb +++ b/app/views/devise/registrations/_personal_details.html.erb @@ -1,9 +1,19 @@ -
+<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put, class: "roadmap-form white_background"}) do |f| %> + +
+

+ <%= _("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" %> + <%= hidden_field_tag :unlink_flag, "false", id: "unlink_flag" %> + <%= hidden_field_tag :skip_personal_details, "false" %>
@@ -38,6 +48,14 @@
+ + + +
+ +
<%= render partial: "shared/accessible_combobox", locals: {name: "#{resource_name}[org_name]", @@ -64,25 +82,20 @@ <% end %> <% @identifier_schemes.each do |scheme| %> - <% - if scheme.name != 'shibboleth' || - (scheme.name == 'shibboleth' && Rails.application.config.shibboleth_enabled) - %>
- + <% if scheme.name == 'shibboleth' %> + + <% else %> + + <% end %>
- <%= render partial: 'external_identifier', - locals: {scheme: scheme, - id: current_user.identifier_for(scheme)} %> + <%= render partial: "external_identifier_#{scheme.name}", + locals: { scheme: scheme, + id: current_user.identifier_for(scheme)} %>
- <% end %> <% end %> <% unless @user.api_token.blank? %> @@ -94,29 +107,31 @@
<%= link_to( _('How to use the API'), controller: "token_permission_types", action: "index")%>
<% end %> +
- - - - - +<% end %> -
-

- <%= _("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.") %> -

-
- + + \ No newline at end of file diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 0b5e000..ca84c15 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,50 +1,35 @@ <% javascript "views/devise/registrations/edit.js" %>

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

+
+ + +
+
+ <%= render partial: 'devise/registrations/personal_details' %> +
-
- <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put, class: "roadmap-form white_background"}) do |f| %> -
- + -
-
- <%= render partial: 'devise/registrations/personal_details', f: f %> -
- - - - +
- - -
- - <%= 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')} %> - <%= link_to 'Cancel', '#', style: 'text-decoration:none;' %> -
- <% end %> +
+ diff --git a/app/views/users/_notification_preferences.html.erb b/app/views/users/_notification_preferences.html.erb index 7dae888..9b79290 100644 --- a/app/views/users/_notification_preferences.html.erb +++ b/app/views/users/_notification_preferences.html.erb @@ -1,49 +1,67 @@ -

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

+

+ <%= 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' %> -
-
+ <%= form_tag(user_update_preferences_path, html: {method: :put, class: "roadmap-form"}) do |f| %> -

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' %> -
+ <%= hidden_field_tag :user_id, @user.id %> -
-

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' %> -
+

All Users

+
+ <%= 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' %> +
+
+ <%= check_box_tag 'prefs[users][added_as_coowner]', true, @user.prefs[:users][:added_as_coowner] %> + <%= label_tag 'prefs[users][added_as_coowner]', 'A plan has been shared with me', :class => 'checkbox-label' %> +
+
+ <%= check_box_tag 'prefs[users][admin_privileges]', true, @user.prefs[:users][:admin_privileges] %> + <%= label_tag 'prefs[users][admin_privileges]', 'Admin privileges granted to me', :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' %> +
+ +
+

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' %> +
+
+ <%= check_box_tag 'prefs[admins][feedback_requested]', true, @user.prefs[:admins][:feedback_requested] %> + <%= label_tag 'prefs[admins][feedback_requested]', 'A user has requested feedback on a DMP', :class => 'checkbox-label' %> +
+ +
+
+ + <%= submit_tag 'Save', class: 'btn btn-primary' %> + <%= link_to 'Cancel', '#', style: 'text-decoration:none;' %> +
+ <% end %>
- \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1cd4960..4cea84f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,6 +39,8 @@ get "/users/sign_out", :to => "devise/sessions#destroy" end + match '/users/update_preferences/' => 'users#update_preferences', as: 'user_update_preferences', via: [:put, :post] + # WAYFless access point - use query param idp #get 'auth/shibboleth' => 'users/omniauth_shibboleth_request#redirect', :as => 'user_omniauth_shibboleth' #get 'auth/shibboleth/assoc' => 'users/omniauth_shibboleth_request#associate', :as => 'user_shibboleth_assoc' diff --git a/lib/assets/stylesheets/dmproadmap/forms.scss b/lib/assets/stylesheets/dmproadmap/forms.scss index ad4f571..5b238f4 100644 --- a/lib/assets/stylesheets/dmproadmap/forms.scss +++ b/lib/assets/stylesheets/dmproadmap/forms.scss @@ -484,7 +484,8 @@ width: 95%; } -/* Edit Profile */ +/* ------------------------------------------------ */ +/* Orcid Component */ /* ------------------------------------------------ */ #connect-orcid-button{ border: 1px solid #D3D3D3; @@ -628,4 +629,4 @@ margin-left: 0; } } -} +} \ No newline at end of file