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 project api specs for view_project_attributes permission
Dombi Attila354f2d3d1ffa
diff --git a/spec/requests/api/v3/projects/index_resource_spec.rb b/spec/requests/api/v3/projects/index_resource_spec.rbindex 1161f999ce0..9ca69e4da9b 100644--- a/spec/requests/api/v3/projects/index_resource_spec.rb+++ b/spec/requests/api/v3/projects/index_resource_spec.rb@@ -50,7 +50,8 @@ RSpec.describe "API v3 Project resource index", content_type: :json doproject.saveendend- let(:role) { create(:project_role) }+ let(:permissions) { [] }+ let(:role) { create(:project_role, permissions:) }let(:second_role) { create(:project_role) }let(:filters) { [] }let(:get_path) do@@ -388,4 +389,41 @@ RSpec.describe "API v3 Project resource index", content_type: :json do.to be_json_eql(expected.to_json).at_path("_embedded/elements/0/_links/workPackages/href")endend++ describe "permissions" do+ context "when a project without view project permission is present" do+ shared_let(:other_project) { create(:project) }+ shared_let(:project) { create(:project) }+ shared_let(:project_custom_field) do+ create(:project_custom_field_project_mapping, project:).project_custom_field+ end+ shared_let(:other_project_custom_field) do+ create(:project_custom_field_project_mapping, project: other_project).project_custom_field+ end++ let(:permissions) { [] }+ let(:other_permissions) { %i(view_project_attributes) }+ let(:other_role) { create(:project_role, permissions: other_permissions) }+ let(:current_user) do+ create(:user, member_with_roles: { project => role,+ other_project => other_role })+ end++ it_behaves_like "API V3 collection response", 2, 2, "Project" do+ let(:elements) { [project, other_project] }++ it "does not return the project attributes for the project" do+ expect(subject).not_to have_json_path(+ "_embedded/elements/0/#{project_custom_field.attribute_name(:camel_case)}"+ )+ end++ it "returns project attributes for other project with the view project permissions" do+ expect(subject).to have_json_path(+ "_embedded/elements/1/#{other_project_custom_field.attribute_name(:camel_case)}"+ )+ end+ end+ end+ endenddiff --git a/spec/requests/api/v3/projects/show_resource_spec.rb b/spec/requests/api/v3/projects/show_resource_spec.rbindex 3c0b0461ec7..da7f74ba114 100644--- a/spec/requests/api/v3/projects/show_resource_spec.rb+++ b/spec/requests/api/v3/projects/show_resource_spec.rb@@ -44,7 +44,8 @@ RSpec.describe "API v3 Project resource show", content_type: :json dolet(:other_project) docreate(:project, public: false)end- let(:role) { create(:project_role, permissions: [:view_project_attributes]) }+ let(:permissions) { %i(view_project_attributes) }+ let(:role) { create(:project_role, permissions:) }let(:custom_field) docreate(:text_project_custom_field)end@@ -116,20 +117,46 @@ RSpec.describe "API v3 Project resource show", content_type: :json do.not_to have_json_path("customField#{invisible_custom_field.id}/raw")end- context "with admin permissions" do- current_user { admin }+ describe "permissions" do+ context "with admin permissions" do+ current_user { admin }- it "includes invisible custom fields" do- custom_value- invisible_custom_value+ it "includes invisible custom fields" do+ custom_value+ invisible_custom_value- expect(subject.body)- .to be_json_eql(custom_value.value.to_json)- .at_path("customField#{custom_field.id}/raw")+ expect(subject.body)+ .to be_json_eql(custom_value.value.to_json)+ .at_path("customField#{custom_field.id}/raw")- expect(subject.body)- .to be_json_eql(invisible_custom_value.value.to_json)- .at_path("customField#{invisible_custom_field.id}/raw")+ expect(subject.body)+ .to be_json_eql(invisible_custom_value.value.to_json)+ .at_path("customField#{invisible_custom_field.id}/raw")+ end+ end++ context "without view_project_attributes permission" do+ let(:permissions) { [] }++ it "does not include custom fields" do+ custom_value+ invisible_custom_value++ expect(subject.body)+ .not_to have_json_path("customField#{custom_field.id}/raw")+ expect(subject.body)+ .not_to have_json_path("customField#{invisible_custom_field.id}/raw")+ end+ end++ context "when requesting project without sufficient permissions" do+ let(:get_path) { api_v3_paths.project other_project.id }++ before do+ response+ end++ it_behaves_like "not found"endend@@ -153,16 +180,6 @@ RSpec.describe "API v3 Project resource show", content_type: :json doit_behaves_like "not found"end- context "when requesting project without sufficient permissions" do- let(:get_path) { api_v3_paths.project other_project.id }-- before do- response- end-- it_behaves_like "not found"- end-context "when not being allowed to see the parent project" dolet!(:parent_memberships) do# no parent memberships