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
remove entity members from global roles query
ulferts0429ed1d68a5
diff --git a/app/services/authorization/user_global_roles_query.rb b/app/services/authorization/user_global_roles_query.rbindex 56c0d366bfa..f45fc298615 100644--- a/app/services/authorization/user_global_roles_query.rb+++ b/app/services/authorization/user_global_roles_query.rb@@ -44,4 +44,10 @@ class Authorization::UserGlobalRolesQuery < Authorization::UserRolesQuerystatement.group(roles_table[:id]).where(users_table[:id].eq(user.id))end++ transformations.register users_members_join, :entity_restriction do |statement, _|+ statement+ .and(members_table[:entity_type].eq(nil))+ .and(members_table[:entity_id].eq(nil))+ endenddiff --git a/app/services/authorization/user_roles_query.rb b/app/services/authorization/user_roles_query.rbindex 1399c0033da..7843321b38f 100644--- a/app/services/authorization/user_roles_query.rb+++ b/app/services/authorization/user_roles_query.rb@@ -30,8 +30,8 @@ class Authorization::UserRolesQuery < Authorization::AbstractUserQueryself.model = Roleself.base_table = users_table- def self.query(*args)- arel = transformed_query(*args)+ def self.query(*)+ arel = transformed_query(*)model.where(roles_table[:id].in(arel))enddiff --git a/spec/services/authorization/user_global_roles_query_spec.rb b/spec/services/authorization/user_global_roles_query_spec.rbindex 35bed0f89e0..3767b3c8989 100644--- a/spec/services/authorization/user_global_roles_query_spec.rb+++ b/spec/services/authorization/user_global_roles_query_spec.rb@@ -48,7 +48,7 @@ RSpec.describe Authorization::UserGlobalRolesQuery doroles: [role2],principal: user)end- let(:global_permission) { OpenProject::AccessControl.permissions.find { |p| p.global? } }+ let(:global_permission) { OpenProject::AccessControl.permissions.find(&:global?) }let(:global_role) dobuild(:global_role,permissions: [global_permission.name])@@ -58,6 +58,12 @@ RSpec.describe Authorization::UserGlobalRolesQuery doprincipal: user,roles: [global_role])end+ let(:work_package_permission) { [:edit_work_packages] }+ let(:work_package_editor_role) { create(:work_package_role, permissions: work_package_permission) }+ let(:work_package) { create(:work_package, project:) }+ let(:work_package_member) do+ build(:member, entity: work_package, project: work_package.project, roles: [work_package_editor_role], principal: user)+ enddescribe '.query' dobefore do@@ -70,57 +76,69 @@ RSpec.describe Authorization::UserGlobalRolesQuery doexpect(described_class.query(user, project)).to be_a ActiveRecord::Relationend- context 'w/ the user being a member in a project' do+ context 'with the user being a member in a project' dobefore domember.save!endit 'is the member and non member role' do- expect(described_class.query(user)).to match_array [role, non_member]+ expect(described_class.query(user)).to contain_exactly(role, non_member)endend- context 'w/ the user being a member in two projects' do+ context 'with the user being a member in two projects' dobefore domember.save!member2.save!endit 'is both member and the non member role' do- expect(described_class.query(user)).to match_array [role, role2, non_member]+ expect(described_class.query(user)).to contain_exactly(role, role2, non_member)endend- context 'w/o the user being a member in a project' do+ context 'without the user being a member in a project' doit 'is the non member role' do- expect(described_class.query(user)).to match_array [non_member]+ expect(described_class.query(user)).to contain_exactly(non_member)endend- context 'w/ the user being anonymous' do+ context 'with the user being anonymous' doit 'is the anonymous role' do- expect(described_class.query(anonymous)).to match_array [anonymous_role]+ expect(described_class.query(anonymous)).to contain_exactly(anonymous_role)+ end+ end++ context 'with the user having a global role' do+ before do+ global_member.save!+ end++ it 'is the global role and non member role' do+ expect(described_class.query(user)).to contain_exactly(global_role, non_member)endend- context 'w/ the user having a global role' do+ context 'with the user having a global role and a member role' dobefore do+ member.save!global_member.save!endit 'is the global role and non member role' do- expect(described_class.query(user)).to match_array [global_role, non_member]+ expect(described_class.query(user)).to contain_exactly(global_role, role, non_member)endend- context 'w/ the user having a global role and a member role' do+ context 'with the user having a global role, a member role and a work package role' dobefore domember.save!global_member.save!+ work_package_member.save!endit 'is the global role and non member role' do- expect(described_class.query(user)).to match_array [global_role, role, non_member]+ expect(described_class.query(user)).to contain_exactly(global_role, role, non_member)endendend