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

Fix more tests

Klaus Zanders623cc48f12fe
diff --git a/lib/api/v3/attachments/attachments_by_container_api.rb b/lib/api/v3/attachments/attachments_by_container_api.rb
index 7afd6a54a6f..c7464272deb 100644
--- a/lib/api/v3/attachments/attachments_by_container_api.rb
+++ b/lib/api/v3/attachments/attachments_by_container_api.rb
@@ -51,7 +51,13 @@ module API
# Additionally to what would be checked by the contract,
# we need to restrict permissions in some use cases of the mounts of this endpoint.
def restrict_permissions(permissions)
- authorize_in_project(permissions, project: container.project) unless permissions.empty?
+ return if permissions.empty?
+
+ if container.is_a?(WorkPackage)
+ authorize_in_work_package(permissions, work_package: container)
+ else
+ authorize_in_project(permissions, project: container.project)
+ end
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 01f0a5f1bad..42d4ab38ef1 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
@@ -210,7 +210,7 @@ module Redmine
permission_project_context = (project if respond_to?(:project))
Array(permissions).any? do |permission|
- user.allowed_based_on_permission_context?(permission, project: permission_project_context)
+ user.allowed_based_on_permission_context?(permission, project: permission_project_context, entity: self)
end
end
diff --git a/spec/models/work_packages/scopes/allowed_to_spec.rb b/spec/models/work_packages/scopes/allowed_to_spec.rb
index 6553ccaa574..b6ad5aa7562 100644
--- a/spec/models/work_packages/scopes/allowed_to_spec.rb
+++ b/spec/models/work_packages/scopes/allowed_to_spec.rb
@@ -154,7 +154,10 @@ RSpec.describe WorkPackage, '.allowed_to' do
subject { described_class.allowed_to(user, action) }
it 'returns the authorized work packages' do
- expect(subject).to contain_exactly(work_package_in_private_project, other_work_package_in_private_project)
+ expect(subject).to contain_exactly(
+ work_package_in_private_project,
+ other_work_package_in_private_project
+ )
end
context 'when the project is archived' do