Skip to content

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

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.rb
index ca7bb32a1a8..05f84f82599 100644
--- a/app/contracts/projects/archive_contract.rb
+++ b/app/contracts/projects/archive_contract.rb
@@ -61,8 +61,10 @@ module Projects
return 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_subprojects
end
diff --git a/app/services/projects/archive_service.rb b/app/services/projects/archive_service.rb
index a1facb5320d..d6ea1706b67 100644
--- a/app/services/projects/archive_service.rb
+++ b/app/services/projects/archive_service.rb
@@ -48,7 +48,8 @@ module Projects
def 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?
end
end
end
diff --git a/spec/contracts/projects/archive_contract_spec.rb b/spec/contracts/projects/archive_contract_spec.rb
index 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 do
include_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'
+ end
end
include_examples 'contract is valid for active admins and invalid for regular users'