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
Changes project archive process to only archive active subprojects
DubeySandeep478dad486514
diff --git a/app/contracts/projects/archive_contract.rb b/app/contracts/projects/archive_contract.rbindex ca7bb32a1a8..05f84f82599 100644--- a/app/contracts/projects/archive_contract.rb+++ b/app/contracts/projects/archive_contract.rb@@ -61,8 +61,10 @@ module Projectsreturn if errors.present?subprojects = model.descendants- return if subprojects.empty?- return if user.allowed_to?(:archive_project, subprojects)+ # Only active projects are allowed to be archived.+ active_subprojects = subprojects.select {|p| p.active?}+ return if active_subprojects.empty?+ return if user.allowed_to?(:archive_project, active_subprojects)errors.add :base, :archive_permission_missing_on_subprojectsenddiff --git a/app/services/projects/archive_service.rb b/app/services/projects/archive_service.rbindex a1facb5320d..d6ea1706b67 100644--- a/app/services/projects/archive_service.rb+++ b/app/services/projects/archive_service.rb@@ -48,7 +48,8 @@ module Projectsdef archive_project(project)# We do not care for validations but want the timestamps to be updated- project.update_attribute(:active, false)+ # for the changed models.+ project.update_attribute(:active, false) if project.active?endendenddiff --git a/spec/contracts/projects/archive_contract_spec.rb b/spec/contracts/projects/archive_contract_spec.rbindex cf61ad67c33..b91f035978a 100644--- a/spec/contracts/projects/archive_contract_spec.rb+++ b/spec/contracts/projects/archive_contract_spec.rb@@ -72,6 +72,24 @@ describe Projects::ArchiveContract doinclude_examples 'contract is valid'end++ context 'when some of subprojects are archived but not all' do+ before do+ subproject1.update_column(:active, false)+ create(:member, user: current_user, project: subproject2, roles: [archivist_role])+ end++ include_examples 'contract is valid'+ end++ context 'when all of subprojects are archived' do+ before do+ subproject1.update_column(:active, false)+ subproject2.update_column(:active, false)+ end++ include_examples 'contract is valid'+ endendinclude_examples 'contract is valid for active admins and invalid for regular users'