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
Add methods for access to queries
Klaus Zanders47ce22cd76fd
diff --git a/app/models/queries/projects/project_query.rb b/app/models/queries/projects/project_query.rbindex 0165aa9eeef..9a1d7736d32 100644--- a/app/models/queries/projects/project_query.rb+++ b/app/models/queries/projects/project_query.rb@@ -48,16 +48,18 @@ class Queries::Projects::ProjectQuery < ApplicationRecordscopes :allowed_todef visible?(user = User.current)- public? || user == self.user+ public? ||+ user == self.user ||+ user.allowed_in_project_query?(:view_project_query, self)end- def can_edit?(user = User.current)+ def editable?(user = User.current)# non public queries can only be edited by the owner(!public? && user == self.user) ||# public queries can be edited by users with the global permission (regardless of ownership)(public? && user.allowed_globally?(:manage_public_project_queries)) ||# or by users with the edit permission on the query- user.allowed_to?(:edit_project_query, self)+ user.allowed_in_project_query?(:edit_project_query, self)enddef self.modeldiff --git a/spec/models/queries/projects/project_query_spec.rb b/spec/models/queries/projects/project_query_spec.rbindex d095a0349df..cb19bf27363 100644--- a/spec/models/queries/projects/project_query_spec.rb+++ b/spec/models/queries/projects/project_query_spec.rb@@ -442,6 +442,92 @@ RSpec.describe Queries::Projects::ProjectQuery doit { is_expected.not_to be_visible(user) }end++ context "and the query has been shared with the user" do+ before do+ mock_permissions_for(user) do |mock|+ mock.allow_in_project_query(:view_project_query, project_query: subject)+ end+ end++ it { is_expected.to be_visible(user) }+ end+ end+ end++ describe "#editable?" do+ subject { build(:project_query, user: owner, public:) }++ context "when the query is private" do+ let(:public) { false }++ context "and the user is the owner" do+ let(:owner) { user }++ it { is_expected.to be_editable(user) }+ end++ context "and the user is not the owner" do+ let(:owner) { build(:user) }++ it { is_expected.not_to be_editable(user) }++ context "and the query has been shared with the user" do+ before do+ mock_permissions_for(user) do |mock|+ mock.allow_in_project_query(:edit_project_query, project_query: subject)+ end+ end++ it { is_expected.to be_editable(user) }+ end+ end+ end++ context "when the query is public" do+ let(:public) { true }++ context "and the user is the owner" do+ let(:owner) { user }++ it { is_expected.not_to be_editable(user) }++ context "and the user has the global permission" do+ before do+ mock_permissions_for(user) do |mock|+ mock.allow_globally(:manage_public_project_queries)+ end+ end++ it { is_expected.to be_editable(user) }+ end+ end++ context "and the user is not the owner" do+ let(:owner) { build(:user) }++ it { is_expected.not_to be_editable(user) }++ context "and the user has the global permission" do+ before do+ mock_permissions_for(user) do |mock|+ mock.allow_globally(:manage_public_project_queries)+ end+ end++ it { is_expected.to be_editable(user) }+ end++ context "and the query has been shared with the user" do+ before do+ mock_permissions_for(user) do |mock|+ mock.allow_in_project_query(:edit_project_query, project_query: subject)+ end+ end++ it { is_expected.to be_editable(user) }+ end+ endendendend