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 @@ -