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

acts_as_attachable#attachments_addable? now supports permission arrays

Richard Richter0dd0380ddfff
diff --git a/lib/api/v3/attachments/attachments_by_work_package_api.rb b/lib/api/v3/attachments/attachments_by_work_package_api.rb
index 10573292aa5..363e25a4ded 100644
--- a/lib/api/v3/attachments/attachments_by_work_package_api.rb
+++ b/lib/api/v3/attachments/attachments_by_work_package_api.rb
@@ -50,12 +50,14 @@ module API
# while attachments are #addable? when the user has the :add_work_packages permission or
# the :edit_work_packages permission, we cannot differentiate here between adding to a newly
# created work package (for which :add_work_package would be required) and adding to an older
- # work package (for which :edit_work_packages would be required). We thus only allow
- # :edit_work_packages in this endpoint and require clients to upload uncontainered work packages
- # first and attach them on wp creation.
+ # work package (for which :edit_work_packages or :add_work_package_attachments would be required).
+ # We thus only allow :edit_work_packages in this endpoint and require clients to upload uncontainered work
+ # packages first and attach them on wp creation.
post &API::V3::Attachments::AttachmentsByContainerAPI.create(%i[edit_work_packages add_work_package_attachments])
namespace :prepare do
+ # TODO which version?
+ # post &API::V3::Attachments::AttachmentsByContainerAPI.prepare(%i[edit_work_packages add_work_package_attachments])
post &API::V3::Attachments::AttachmentsByContainerAPI.prepare([:edit_work_packages])
end
end
diff --git a/lib_static/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib_static/plugins/acts_as_attachable/lib/acts_as_attachable.rb
index 8819b057529..e71cd79e7ff 100644
--- a/lib_static/plugins/acts_as_attachable/lib/acts_as_attachable.rb
+++ b/lib_static/plugins/acts_as_attachable/lib/acts_as_attachable.rb
@@ -144,8 +144,10 @@ module Redmine
# Can this acts_as_attachable instance accept attachments from the given user
# @param user [User]
def attachments_addable?(user = User.current)
- user.allowed_to_globally?(attachable_options[:add_on_new_permission]) ||
- user.allowed_to_globally?(attachable_options[:add_on_persisted_permission])
+ (Array(attachable_options[:add_on_new_permission]) |
+ Array(attachable_options[:add_on_persisted_permission])).any? do |permission|
+ user.allowed_to_globally?(permission)
+ end
end
##