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
Merge remote-tracking branch 'origin/dev' into implementation/62981-show-and-edit-linked-phases-on-work-packages
ulfertsad33c9305461
diff --cc config/initializers/permissions.rbindex 75315dc6ae7,c12aa8382d7..00cfa261538--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@@ -282,13 -282,12 +282,13 @@@ Rails.application.reloader.to_prepare dcontract_actions: { work_packages: %i[move] }wpt.permission :copy_work_packages,- {},+ { "work_packages/moves": %i[new create] },permissible_on: %i[work_package project],require: :loggedin,- dependencies: :view_work_packages+ dependencies: :view_work_packages,+ contract_actions: { work_packages: %i[copy] }- wpt.permission :add_work_package_notes,+ wpt.permission :add_work_package_comments,{# FIXME: Although the endpoint is removed, the code checking whether a user# is eligible to add work packages through the API still seems to rely on this.diff --cc spec/contracts/work_packages/update_contract_spec.rbindex cb5fc68fdf8,c7089ece9c8..56b5a21c68f--- a/spec/contracts/work_packages/update_contract_spec.rb+++ b/spec/contracts/work_packages/update_contract_spec.rb@@@ -51,225 -60,196 +51,225 @@@ RSpec.describe WorkPackages::UpdateContendend- subject(:contract) { described_class.new(work_package, user) }-- it_behaves_like "work package contract" do- let(:work_package) do- build_stubbed(:work_package,- project: work_package_project)- end+ let(:work_package) do+ persisted_work_packageend+ let(:user) { persisted_user }+ let(:permissions) { %i[view_work_packages edit_work_packages assign_versions] }- describe "lock_version" do- context "no lock_version present" do- before do- work_package.lock_version = nil- contract.validate+ describe "validations" do+ describe "general authorization" do+ context "without read access" do+ let(:permissions) { [:edit_work_packages] }++ it_behaves_like "contract is invalid", base: :error_not_foundend- it { expect(contract.errors.symbols_for(:base)).to include(:error_conflict) }+ context "without write access" do+ let(:permissions) { [:view_work_packages] }++ it_behaves_like "contract user is unauthorized"+ endend- context "lock_version changed" do- before do- work_package.lock_version += 1- contract.validate+ describe "lock_version" do+ context "without a lock_version present" do+ before do+ work_package.lock_version = nil+ end++ it_behaves_like "contract is invalid", base: :error_conflictend- it { expect(contract.errors.symbols_for(:base)).to include(:error_conflict) }- end+ context "with the lock_version changed" do+ before do+ work_package.lock_version += 1+ end- context "lock_version present and unchanged" do- before do- contract.validate+ it_behaves_like "contract is invalid", base: :error_conflictend- it { expect(contract.errors.symbols_for(:base)).not_to include(:error_conflict) }+ context "with lock_version present and unchanged" do+ it_behaves_like "contract is valid"+ endend- end- describe "authorization" do- let(:attributes) { {} }+ describe "project_id" do+ let(:target_project) { persisted_other_project }+ let(:target_permissions) { [:move_work_packages] }- before do- work_package.attributes = attributes- contract.validate- end+ before do+ mock_permissions_for(user) do |mock|+ mock.allow_in_project *permissions, project: persisted_project+ mock.allow_in_project *target_permissions, project: target_project+ end- context "full access" do- it "is valid" do- expect(contract.errors).to be_empty+ work_package.project = target_projectend- end- context "no read access" do- let(:permissions) { [:edit_work_packages] }-- it { expect(contract.errors.symbols_for(:base)).to include(:error_not_found) }- end+ it_behaves_like "contract is valid"- context "no write access" do- let(:permissions) { [:view_work_packages] }+ context "if the user lacks the permissions" do+ let(:target_permissions) { [] }- it { expect(contract.errors.symbols_for(:base)).to include(:error_unauthorized) }+ it_behaves_like "contract is invalid", project_id: :error_readonly+ endend- context "only comment permission" do- let(:permissions) { %i[view_work_packages add_work_package_comments] }+ describe "remaining_hours" do+ # not parent case covered by shared base contract+ context "when is a parent" do+ let(:work_package) { persisted_parent_work_package }++ context "when has not changed" do+ it_behaves_like "contract is valid"+ end- context "when only adding a journal" do- let(:attributes) { { journal_notes: "some notes" } }+ context "when has changed" do+ before do+ work_package.remaining_hours = 10+ end- it "is valid" do- expect(contract.errors).to be_empty+ it_behaves_like "contract is valid"endend+ end- context "when changing more than a journal" do- let(:attributes) { { journal_notes: "some notes", subject: "blubs" } }+ describe "ignore_non_working_days" do+ context "when having children and not being scheduled manually" do+ before do+ allow(work_package)+ .to receive(:leaf?)+ .and_return(false)- it "is invalid" do- expect(contract.errors.symbols_for(:base)).to include(:error_unauthorized)+ work_package.ignore_non_working_days = !work_package.ignore_non_working_days+ work_package.schedule_manually = falseend++ it_behaves_like "contract is invalid", ignore_non_working_days: :error_readonlyend- end- context "only assign_versions permission" do- let(:permissions) { %i[view_work_packages assign_versions] }+ context "when having children and being scheduled manually" do+ before do+ allow(work_package)+ .to receive(:leaf?)+ .and_return(false)- it "is valid" do- expect(contract.errors).to be_empty+ work_package.ignore_non_working_days = !work_package.ignore_non_working_days+ work_package.schedule_manually = true+ end++ it_behaves_like "contract is valid"endend- end- describe "project_id" do- let(:target_project) { create(:project, types: [type]) }- let(:target_permissions) { [:move_work_packages] }-- before do- mock_permissions_for(user) do |mock|- mock.allow_in_project *permissions, project: work_package_project- mock.allow_in_project *target_permissions, project: target_project+ describe "type" do+ let!(:milestone_type) do+ create(:type, is_milestone: true, projects: [work_package.project])end- allow(work_package).to receive(:project) do- if work_package.project_id == target_project.id- target_project- else- work_package_project+ context "when changing to a milestone type and having a child work package" do+ let!(:child_work_package) do+ create(:work_package,+ project: work_package.project,+ parent: work_package)end- end- work_package.project = target_project+ before do+ work_package.type = milestone_type+ end- contract.validate+ it_behaves_like "contract is invalid", type: :cannot_be_milestone_due_to_children+ endend- context "if the user has the permissions" do- it("is valid") { expect(contract.errors).to be_empty }- end+ describe "journal_notes" do+ context "when only adding a comment and having only the comment permission permission" do- let(:permissions) { %i[view_work_packages add_work_package_notes] }++ let(:permissions) { %i[view_work_packages add_work_package_comments] }- context "if the user lacks the permissions" do- let(:target_permissions) { [] }+ before do+ work_package.attributes = { journal_notes: "some notes" }+ end- it "is invalid" do- expect(contract.errors.symbols_for(:project_id)).to contain_exactly(:error_readonly)+ it_behaves_like "contract is valid"end- end- end- describe "version" do- let(:version) { build_stubbed(:version) }+ context "when changing more than a comment and having only the comment permission permission" do- let(:permissions) { %i[view_work_packages add_work_package_notes] }++ let(:permissions) { %i[view_work_packages add_work_package_comments] }++ before do+ work_package.attributes = { journal_notes: "some notes", subject: "blubs" }+ end- before do- allow(work_package)- .to receive(:assignable_versions)- .and_return([version])+ it_behaves_like "contract user is unauthorized"+ end- work_package.attributes = attributes+ context "when only adding a comment and having edit permissions" do+ before do+ work_package.attributes = { journal_notes: "some notes" }+ end- contract.validate+ it_behaves_like "contract is valid"+ endend- context "having full access" do- context "with an assignable_version" do- let(:attributes) { { version_id: version.id } }+ describe "readonly status" do+ context "with the status being readonly", with_ee: %i[readonly_work_packages] do+ shared_let(:readonly_status) { create(:status, is_readonly: true) }- it "is valid" do- expect(contract.errors).to be_empty+ before do+ work_package.status = readonly_status+ work_package.saveend- end- context "with an unassignable_version" do- let(:attributes) { { version_id: version.id + 1 } }+ describe "updating the priority (representative for default attributes)" do+ let(:new_priority) { build_stubbed(:priority) }++ before do+ work_package.priority = new_priority++ contract.validate+ end- it "adds an error" do- expect(contract.errors.symbols_for(:version_id))- .to include(:inclusion)+ it_behaves_like "contract is invalid",+ priority_id: :error_readonly,+ base: :readonly_statusend- end- end- context "write access" do- let(:permissions) { %i[view_work_packages edit_work_packages] }+ describe "updating the custom field values" do+ let(:cf1) { create(:string_wp_custom_field) }- context "if assigning a version" do- let(:attributes) { { version_id: version.id } }+ before do+ persisted_project.work_package_custom_fields << cf1+ persisted_type.custom_fields << cf1+ work_package.custom_field_values = { cf1.id => "test" }+ contract.validate+ end- it "adds an error" do- expect(contract.errors.symbols_for(:version_id))- .to include(:error_readonly)- end- end- end- end+ shared_examples_for "custom_field readonly errors" do+ it "adds an error to the written custom field attribute" do+ expect(contract.errors.symbols_for(cf1.attribute_name.to_sym))+ .to include(:error_readonly)+ end- describe "ignore_non_working_days" do- context "when having children and not being scheduled manually" do- before do- allow(work_package)- .to receive(:leaf?)- .and_return(false)+ it "adds an error to base to better explain" do+ expect(contract.errors.symbols_for(:base))+ .to include(:readonly_status)+ end+ end- work_package.ignore_non_working_days = !work_package.ignore_non_working_days- work_package.schedule_manually = false+ context "when the subject does not extends OpenProject::ChangedBySystem" do+ include_examples "custom_field readonly errors"+ end- contract.validate- end+ context "when the subject extends OpenProject::ChangedBySystem" do+ before do+ work_package.extend(OpenProject::ChangedBySystem)+ end- it "is invalid" do- expect(contract.errors.symbols_for(:ignore_non_working_days))- .to contain_exactly(:error_readonly)+ include_examples "custom_field readonly errors"+ end+ endendend