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

Use allowed_based_on_permission_context? in BaseContract

Klaus Zandersf83282466829
diff --git a/app/contracts/base_contract.rb b/app/contracts/base_contract.rb
index cd7f9cb728a..c263038aa20 100644
--- a/app/contracts/base_contract.rb
+++ b/app/contracts/base_contract.rb
@@ -239,7 +239,7 @@ class BaseContract < Disposable::Twin
attributes
end
- def reduce_by_writable_permissions(attributes) # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize
+ def reduce_by_writable_permissions(attributes)
attribute_permissions = collect_ancestor_attributes(:attribute_permissions)
attributes.reject do |attribute|
@@ -251,10 +251,11 @@ class BaseContract < Disposable::Twin
next unless permissions
- # This will break once a model that does not respond to project is used.
- # This is intended to be worked on then with the additional knowledge.
- next if model.project.present? && permissions.any? { |perm| user.allowed_in_project?(perm, model.project) }
- next if model.project.blank? && permissions.any? { |perm| user.allowed_in_any_project?(perm) }
+ next if permissions.any? do |perm|
+ user.allowed_based_on_permission_context?(perm,
+ project: model.respond_to?(:project) ? model.project : nil,
+ entity: model)
+ end
true
end