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

Refactor: simplify code

Christophe Bliard3167f462fe7c
diff --git a/app/contracts/projects/archive_contract.rb b/app/contracts/projects/archive_contract.rb
index 4efb22ba8ee..ca7bb32a1a8 100644
--- a/app/contracts/projects/archive_contract.rb
+++ b/app/contracts/projects/archive_contract.rb
@@ -57,14 +57,14 @@ module Projects
end
def validate_can_archive_subprojects
- return if errors.any?
+ # prevent adding another error if there is already one present
+ return if errors.present?
- subprojects_with_missing_permission = model.descendants.reject do |subproject|
- user.allowed_to?(:archive_project, subproject)
- end
- if subprojects_with_missing_permission.any?
- errors.add :base, :archive_permission_missing_on_subprojects
- end
+ subprojects = model.descendants
+ return if subprojects.empty?
+ return if user.allowed_to?(:archive_project, subprojects)
+
+ errors.add :base, :archive_permission_missing_on_subprojects
end
end
end