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

Users with edit permission are also allowed to edit public queries

Klaus Zandersf6809fcbbb98
diff --git a/app/contracts/queries/projects/project_queries/base_contract.rb b/app/contracts/queries/projects/project_queries/base_contract.rb
index 446f0b23316..0bb16063e79 100644
--- a/app/contracts/queries/projects/project_queries/base_contract.rb
+++ b/app/contracts/queries/projects/project_queries/base_contract.rb
@@ -65,10 +65,10 @@ module Queries::Projects::ProjectQueries
def allowed_to_modify_public_query
return unless model.public?
+ return if user.allowed_in_project_query?(:edit_project_query, model)
+ return if user.allowed_globally?(:manage_public_project_queries)
- unless user.allowed_globally?(:manage_public_project_queries)
- errors.add :base, :need_permission_to_modify_public_query
- end
+ errors.add :base, :need_permission_to_modify_public_query
end
def name_select_included
diff --git a/spec/contracts/queries/projects/project_queries/shared_contract_examples.rb b/spec/contracts/queries/projects/project_queries/shared_contract_examples.rb
index 6cff8337a1a..c8056e3c0b4 100644
--- a/spec/contracts/queries/projects/project_queries/shared_contract_examples.rb
+++ b/spec/contracts/queries/projects/project_queries/shared_contract_examples.rb
@@ -70,7 +70,7 @@ RSpec.shared_examples_for "project queries contract" do
it_behaves_like "contract is valid"
end
- context "if the list is public and the editing user has the permission" do
+ context "if the list is public and the editing user has the global permission" do
let(:query_user) { build_stubbed(:user) }
before do
@@ -86,7 +86,7 @@ RSpec.shared_examples_for "project queries contract" do
it_behaves_like "contract is valid"
end
- context "if the list is public and the editing user does not have the permission" do
+ context "if the list is public and the editing user does not have the global permission" do
let(:query_user) { build_stubbed(:user) }
before do
@@ -100,6 +100,22 @@ RSpec.shared_examples_for "project queries contract" do
it_behaves_like "contract is invalid", base: :need_permission_to_modify_public_query
end
+ context "if the list is public and the editing user does not have the global permission but has edit rights on the item" do
+ let(:query_user) { build_stubbed(:user) }
+
+ before do
+ query.change_by_system do
+ query.public = true
+ end
+
+ mock_permissions_for(current_user) do |mock|
+ mock.allow_in_project_query :edit_project_query, project_query: query
+ end
+ end
+
+ it_behaves_like "contract is valid"
+ end
+
context "if the list is public and the editing user does not have the permission, even if they are the owner" do
let(:query_user) { current_user }