OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Ensure admins cannot be edited by anybody but active admins
Christophe Bliard74fe9e5e07ee
diff --git a/app/contracts/users/update_contract.rb b/app/contracts/users/update_contract.rbindex f24b67b99cf..e37d136ec1e 100644--- a/app/contracts/users/update_contract.rb+++ b/app/contracts/users/update_contract.rb@@ -39,7 +39,6 @@ module Users# - the user has the global manage_user permission and is not editing an admindef user_allowed_to_updatereturn if editing_themself?- return if user.admin?return if can_manage_this_user?errors.add :base, :error_unauthorized@@ -49,8 +48,10 @@ module Usersuser == modelend+ # Only admins can edit other admins+ # Only users with manage_user permission can edit other usersdef can_manage_this_user?- user.allowed_to_globally?(:manage_user) && !model.admin?+ user.allowed_to_globally?(:manage_user) && (user.admin? || !model.admin?)endendenddiff --git a/spec/contracts/users/update_contract_spec.rb b/spec/contracts/users/update_contract_spec.rbindex 5f45d0155b4..527b71d06cb 100644--- a/spec/contracts/users/update_contract_spec.rb+++ b/spec/contracts/users/update_contract_spec.rb@@ -41,7 +41,9 @@ RSpec.describe Users::UpdateContract dofirstname: user_firstname,lastname: user_lastname,login: user_login,- mail: user_mail+ mail: user_mail,+ password: nil,+ password_confirmation: nil}end@@ -50,14 +52,17 @@ RSpec.describe Users::UpdateContract dodescribe 'can lock the user' dobefore do- # needed for the stub- user.password = user.password_confirmation = nil-user.status = Principal.statuses[:locked]endit_behaves_like 'contract is valid'end++ describe 'cannot update an administrator' do+ let(:user) { build_stubbed(:admin, attributes) }++ it_behaves_like 'contract is invalid'+ endendcontext "when updated user is current user" do@@ -68,9 +73,6 @@ RSpec.describe Users::UpdateContract docontext 'when setting status' dobefore do- # needed for the stub- user.password = user.password_confirmation = nil-user.status = Principal.statuses[:locked]end