Skip to content

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

[#57928] make users removable from global role

Tobias Dillmanna37b36dc1b74
diff --git a/app/contracts/members/delete_base_contract.rb b/app/contracts/members/delete_base_contract.rb
new file mode 100644
index 00000000000..b0041998d9e
--- /dev/null
+++ b/app/contracts/members/delete_base_contract.rb
@@ -0,0 +1,41 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module Members
+ # Abstract contract for deleting members. Should not be used directly. Look at the child classes for
+ # individual use cases.
+ class DeleteBaseContract < ::DeleteContract
+ validate :member_is_deletable
+
+ protected
+
+ def member_is_deletable
+ errors.add(:base, :not_deletable) unless model.some_roles_deletable?
+ end
+ end
+end
diff --git a/app/contracts/members/delete_contract.rb b/app/contracts/members/delete_contract.rb
index f876029feaa..a9c95a40e08 100644
--- a/app/contracts/members/delete_contract.rb
+++ b/app/contracts/members/delete_contract.rb
@@ -27,15 +27,7 @@
#++
module Members
- class DeleteContract < ::DeleteContract
+ class DeleteContract < DeleteBaseContract
delete_permission :manage_members
-
- validate :member_is_deletable
-
- private
-
- def member_is_deletable
- errors.add(:base, :not_deletable) unless model.some_roles_deletable?
- end
end
end
diff --git a/app/contracts/members/global_delete_contract.rb b/app/contracts/members/global_delete_contract.rb
new file mode 100644
index 00000000000..5ff9c0ff7ef
--- /dev/null
+++ b/app/contracts/members/global_delete_contract.rb
@@ -0,0 +1,33 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module Members
+ class GlobalDeleteContract < DeleteBaseContract
+ delete_permission :admin
+ end
+end
diff --git a/app/services/members/delete_service.rb b/app/services/members/delete_service.rb
index 0bf8ff9ad19..b29e067a7f9 100644
--- a/app/services/members/delete_service.rb
+++ b/app/services/members/delete_service.rb
@@ -60,4 +60,13 @@ class Members::DeleteService < BaseServices::Delete
.new(member.principal, current_user: user, contract_class: EmptyContract)
.call
end
+
+ def default_contract_class
+ # We have different contracts for project roles and global roles
+ if model.project.present?
+ "#{namespace}::DeleteContract".constantize
+ else
+ "#{namespace}::GlobalDeleteContract".constantize
+ end
+ end
end
diff --git a/spec/features/users/user_memberships_spec.rb b/spec/features/users/user_memberships_spec.rb
index 7aadd630045..f89a4950ecf 100644
--- a/spec/features/users/user_memberships_spec.rb
+++ b/spec/features/users/user_memberships_spec.rb
@@ -39,6 +39,24 @@ RSpec.describe "user memberships through user page", :js, :with_cuprite do
current_user { create(:admin) }
it_behaves_like "principal membership management flows"
+
+ context "when setting global permissions" do
+ let(:global_role) { create(:global_role) }
+ let!(:global_user) { create(:global_member, principal:, roles: [global_role]) }
+
+ it "removes a global user (bug #57928)" do
+ # Check if user with global role is there
+ principal_page.visit!
+ principal_page.open_global_roles_tab!
+ principal_page.expect_global_roles(["Global Role 1"])
+
+ # Remove the global role from the user
+ principal_page.remove_global_role!("Global Role 1")
+
+ # Verify that it is gone
+ principal_page.expect_global_roles([])
+ end
+ end
end
it_behaves_like "global user principal membership management flows", :manage_user
diff --git a/spec/support/pages/admin/individual_principals/edit.rb b/spec/support/pages/admin/individual_principals/edit.rb
index d9accf52db7..80760b9ed08 100644
--- a/spec/support/pages/admin/individual_principals/edit.rb
+++ b/spec/support/pages/admin/individual_principals/edit.rb
@@ -111,6 +111,25 @@ module Pages
results_selector: "body"
end
+ def open_global_roles_tab!
+ within(".PageHeader-tabNav") do
+ click_on "Global roles"
+ end
+ end
+
+ def expect_global_roles(roles)
+ roles_in_on_page = page.find_all("#table_principal_roles tr td.role")
+
+ expect(roles_in_on_page.map(&:text)).to eq(roles)
+ end
+
+ def remove_global_role!(role)
+ within("#table_principal_roles") do
+ role_td = find("tr td.role", text: role)
+ role_td.ancestor("tr").find("td.buttons a").click
+ end
+ end
+
def activate!
within ".toolbar-items" do
click_button "Activate"