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_in_work_package? check in WorkPackage API

Klaus Zandersa7277bfe637b
diff --git a/lib/api/v3/custom_actions/custom_actions_api.rb b/lib/api/v3/custom_actions/custom_actions_api.rb
index e5b56232d4f..8bff2f26dbc 100644
--- a/lib/api/v3/custom_actions/custom_actions_api.rb
+++ b/lib/api/v3/custom_actions/custom_actions_api.rb
@@ -41,7 +41,7 @@ module API
helpers ::API::V3::WorkPackages::WorkPackagesSharedHelpers
after_validation do
- authorize_in_any_project(:edit_work_packages)
+ authorize_in_any_work_package(:edit_work_packages)
end
get do
diff --git a/lib/api/v3/work_packages/available_projects_on_edit_api.rb b/lib/api/v3/work_packages/available_projects_on_edit_api.rb
index c564342bae4..f2d6987a0e6 100644
--- a/lib/api/v3/work_packages/available_projects_on_edit_api.rb
+++ b/lib/api/v3/work_packages/available_projects_on_edit_api.rb
@@ -32,7 +32,7 @@ module API
class AvailableProjectsOnEditAPI < ::API::OpenProjectAPI
resource :available_projects do
after_validation do
- authorize_in_project(:edit_work_packages, project: @work_package.project)
+ authorize_in_work_package(:edit_work_packages, work_package: @work_package.project)
checked_permissions = Projects::ProjectCollectionRepresenter.checked_permissions
current_user.preload_projects_allowed_to(checked_permissions)
diff --git a/lib/api/v3/work_packages/create_project_form_representer.rb b/lib/api/v3/work_packages/create_project_form_representer.rb
index f0f15973949..1b308839b77 100644
--- a/lib/api/v3/work_packages/create_project_form_representer.rb
+++ b/lib/api/v3/work_packages/create_project_form_representer.rb
@@ -52,7 +52,7 @@ module API
end
link :commit do
- if current_user.allowed_in_project?(:edit_work_packages, represented.project) &&
+ if current_user.allowed_in_work_package?(:edit_work_packages, represented) &&
@errors.empty?
{
href: api_v3_paths.work_packages_by_project(represented.project_id),
diff --git a/lib/api/v3/work_packages/update_form_representer.rb b/lib/api/v3/work_packages/update_form_representer.rb
index 764e10960ee..1421bbd9c8c 100644
--- a/lib/api/v3/work_packages/update_form_representer.rb
+++ b/lib/api/v3/work_packages/update_form_representer.rb
@@ -52,7 +52,7 @@ module API
end
link :commit do
- if current_user.allowed_in_project?(:edit_work_packages, represented.project) &&
+ if current_user.allowed_in_work_package?(:edit_work_packages, represented) &&
@errors.empty?
{
href: api_v3_paths.work_package(represented.id),
diff --git a/lib/api/v3/work_packages/work_package_collection_representer.rb b/lib/api/v3/work_packages/work_package_collection_representer.rb
index 95242fed8c3..e52146616cd 100644
--- a/lib/api/v3/work_packages/work_package_collection_representer.rb
+++ b/lib/api/v3/work_packages/work_package_collection_representer.rb
@@ -187,9 +187,9 @@ module API
def current_user_allowed_to_edit_work_packages?
if project
- current_user.allowed_in_project?(:edit_work_packages, project)
+ current_user.allowed_in_any_work_package?(:edit_work_packages, in_project: project)
else
- current_user.allowed_in_any_project?(:edit_work_packages)
+ current_user.allowed_in_any_work_package?(:edit_work_packages)
end
end
diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rb
index 608e7809a6e..707649165a4 100644
--- a/lib/api/v3/work_packages/work_package_representer.rb
+++ b/lib/api/v3/work_packages/work_package_representer.rb
@@ -566,20 +566,20 @@ module API
def current_user_update_allowed?
@current_user_update_allowed ||=
- current_user.allowed_in_project?(:edit_work_packages, represented.project) ||
+ current_user.allowed_in_work_package?(:edit_work_packages, represented) ||
current_user.allowed_in_project?(:assign_versions, represented.project)
end
def view_time_entries_allowed?
@view_time_entries_allowed ||=
current_user.allowed_in_project?(:view_time_entries, represented.project) ||
- current_user.allowed_in_project?(:view_own_time_entries, represented.project)
+ current_user.allowed_in_work_package?(:view_own_time_entries, represented)
end
def log_time_allowed?
@log_time_allowed ||=
current_user.allowed_in_project?(:log_time, represented.project) ||
- current_user.allowed_in_project?(:log_own_time, represented.project)
+ current_user.allowed_in_work_package?(:log_own_time, represented)
end
def view_budgets_allowed?
@@ -588,7 +588,7 @@ module API
def export_work_packages_allowed?
@export_work_packages_allowed ||=
- current_user.allowed_in_project?(:export_work_packages, represented.project)
+ current_user.allowed_in_work_package?(:export_work_packages, represented)
end
def add_work_packages_allowed?