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 specs for copying projects without view_project_attribute permission
Dombi Attilab81c88af2232
diff --git a/spec/contracts/projects/create_contract_spec.rb b/spec/contracts/projects/create_contract_spec.rbindex 3012f0a9dd7..390cd06d6b1 100644--- a/spec/contracts/projects/create_contract_spec.rb+++ b/spec/contracts/projects/create_contract_spec.rb@@ -56,10 +56,10 @@ RSpec.describe Projects::CreateContract doendend- describe "writing read-only attributes" do+ describe "permissions" doshared_examples "can write" dolet(:value) { 1 }- it "can write", :aggregate_failures do+ it "can write the attribute", :aggregate_failures doexpect(contract.writable_attributes).to include(attribute.to_s)project.send(:"#{attribute}=", value)@@ -69,7 +69,7 @@ RSpec.describe Projects::CreateContract doshared_examples "can not write" dolet(:value) { 1 }- it "can not write", :aggregate_failures do+ it "can not write the attribute", :aggregate_failures doexpect(contract.writable_attributes).not_to include(attribute.to_s)project.send(:"#{attribute}=", value)@@ -78,7 +78,35 @@ RSpec.describe Projects::CreateContract doendend- describe "project attributes" do+ describe "writing read-only attributes" do+ context "when enabled for admin", with_settings: { apiv3_write_readonly_attributes: true } do+ let(:current_user) { build_stubbed(:admin) }++ it_behaves_like "can write" do+ let(:attribute) { :created_at }+ let(:value) { 10.days.ago }+ end++ it_behaves_like "can not write" do+ let(:attribute) { :updated_at }+ let(:value) { 1.day.ago }+ end+ end++ context "when disabled for admin", with_settings: { apiv3_write_readonly_attributes: false } do+ let(:current_user) { build_stubbed(:admin) }++ it_behaves_like "can not write" do+ let(:attribute) { :created_at }+ let(:value) { 1.day.ago }+ end++ it_behaves_like "can not write" do+ let(:attribute) { :updated_at }+ let(:value) { 1.day.ago }+ end+ end+let(:global_permissions) { [] }let(:current_user) { create(:user) }let!(:role) { create(:existing_project_role, permissions: project_permissions) }diff --git a/spec/requests/api/v3/projects/copy/copy_form_resource_spec.rb b/spec/requests/api/v3/projects/copy/copy_form_resource_spec.rbindex c582b6aedcc..4b855f08b9f 100644--- a/spec/requests/api/v3/projects/copy/copy_form_resource_spec.rb+++ b/spec/requests/api/v3/projects/copy/copy_form_resource_spec.rb@@ -46,13 +46,10 @@ RSpec.describe API::V3::Projects::Copy::CreateFormAPI, content_type: :json dolist_custom_field.id => list_custom_field.custom_options.last.id})end-- shared_let(:current_user) do+ let(:permissions) { %i(copy_projects view_project view_work_packages view_project_attributes) }+ let(:current_user) docreate(:user,- member_with_permissions: { source_project => %i[copy_projects- view_project- view_work_packages- view_project_attributes] })+ member_with_permissions: { source_project => permissions })endlet(:path) { api_v3_paths.project_copy_form(source_project.id) }@@ -89,6 +86,15 @@ RSpec.describe API::V3::Projects::Copy::CreateFormAPI, content_type: :json do.at_path("_embedded/payload/_links/customField#{list_custom_field.id}/title")end+ context "without view_project_attributes permission" do+ let(:permissions) { %i(copy_projects view_project view_work_packages) }++ it "does not activates custom fields from the source project" do+ expect(response.body)+ .not_to have_json_path("_embedded/payload/customField#{text_custom_field.id}")+ end+ end+it "contains a meta property with copy properties for every module" doProjects::CopyService.copyable_dependencies.each do |dep|identifier = dep[:identifier].to_s.camelize