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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add `authorize_in_(any_)work_package` to API
Klaus Zandersbb7d50869280
diff --git a/lib/api/root_api.rb b/lib/api/root_api.rbindex f2a8d63d33a..1ac3c65bea5 100644--- a/lib/api/root_api.rb+++ b/lib/api/root_api.rb@@ -193,6 +193,40 @@ module APIauthorize_by_with_raise(authorized, &block)end+ # Checks that the current user has the given permission on any work package or project or raise {API::Errors::Unauthorized}.+ #+ # @param permission_or_permissions [String, [String], Hash] the permission name, an array of permissions or a hash+ # with controller and action keys. When an array of permissions is given, the user needs to have at least one of+ # those permissions, not all.+ #+ # @raise [API::Errors::Unauthorized] when permission is not met+ def authorize_in_any_work_package(permission_or_permissions, user: current_user, &block)+ permissions = Array.wrap(permission_or_permissions)+ authorized = permissions.any? do |permission|+ user.allowed_in_any_work_package?(permission)+ end++ authorize_by_with_raise(authorized, &block)+ end++ # Checks that the current user has the given permission on the given work package or raise {API::Errors::Unauthorized}.+ #+ # @param permission_or_permissions [String, [String], Hash] the permission name, an array of permissions or a hash+ # with controller and action keys. When an array of permissions is given, the user needs to have at least one of+ # those permissions, not all.+ #+ # @param work_package [Project] the work package the permission needs to be checked on+ #+ # @raise [API::Errors::Unauthorized] when permission is not met+ def authorize_in_work_package(permission_or_permissions, work_package:, user: current_user, &block)+ permissions = Array.wrap(permission_or_permissions)+ authorized = permissions.any? do |permission|+ user.allowed_in_work_package?(permission, work_package)+ end++ authorize_by_with_raise(authorized, &block)+ end+# Checks that the current user has the given permission globally or raise {API::Errors::Unauthorized}.## @param permission_or_permissions [String, [String], Hash] the permission name, an array of permissions or a hash