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 usages with context re-introduction

Klaus Zandersb188a18dfcd0
diff --git a/app/models/user.rb b/app/models/user.rb
index a49447a65ed..b304eb6daa4 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -466,7 +466,7 @@ class User < Principal
# Return user's roles for project
def roles_for_project(project)
- project_role_cache.fetch(project:)
+ project_role_cache.fetch(project)
end
alias :roles :roles_for_project
diff --git a/app/services/authorization/user_allowed_service.rb b/app/services/authorization/user_allowed_service.rb
index 8f9f91e1393..9f09458fdf2 100644
--- a/app/services/authorization/user_allowed_service.rb
+++ b/app/services/authorization/user_allowed_service.rb
@@ -90,7 +90,7 @@ class Authorization::UserAllowedService
# unless the permission is explicitly flagged not to be granted to admins.
return true if granted_to_admin?(action)
- has_authorized_role?(action, entity:)
+ has_authorized_role?(action, entity)
end
def allowed_to_in_project?(action, project)
@@ -108,7 +108,7 @@ class Authorization::UserAllowedService
# unless the permission is explicitly flagged not to be granted to admins.
return true if granted_to_admin?(action)
- has_authorized_role?(action, project:)
+ has_authorized_role?(action, project)
end
# Authorize if user is authorized on every element of the array
@@ -142,9 +142,9 @@ class Authorization::UserAllowedService
user.admin? && OpenProject::AccessControl.grant_to_admin?(action)
end
- def has_authorized_role?(action, project: nil, entity: nil)
+ def has_authorized_role?(action, context = nil)
project_role_cache
- .fetch(project:, entity:)
+ .fetch(context)
.any? do |role|
role.allowed_to?(action)
end
diff --git a/docs/development/concepts/permissions/README.md b/docs/development/concepts/permissions/README.md
index ba812faebf8..baea9f5469b 100644
--- a/docs/development/concepts/permissions/README.md
+++ b/docs/development/concepts/permissions/README.md
@@ -94,8 +94,8 @@ When a set of records is to be returned, e.g. for an index action, it is best to
|---------- | ------| ------ |
| All projects a user is allowed a permission in | `Authorization.projects(permission, user)` | `Authorization.projects(:view_work_packages, User.current)` |
| All users granted a permission in a project | `Authorization.users(permission, project: project)` | `Authorization.users(:view_work_packages, project: project)` |
-| All roles a user has in a project | `Authorization.roles(user, project)` | `Authorization.roles(User.current, project: project)` |
-| All roles a user has for a specific resource | `Authorization.roles(user, entity:` | `Authorization.roles(User.current, entity: work_package)` |
+| All roles a user has in a project | `Authorization.roles(user, project)` | `Authorization.roles(User.current, project)` |
+| All roles a user has for a specific resource | `Authorization.roles(user, entity)` | `Authorization.roles(User.current, work_package)` |
| All roles a user has globally | `Authorization.roles(user)` | `Authorization.roles(User.current)` |
Most of the time, a developer will not witness those queries as they are the embedded deeply within the existing scopes. E.g. the `visible` scopes defined for most AR models, under the hood rely on `Authorization.projects(permission, user)` by checking that the `project_id` attribute of the record is within that set of projects.
diff --git a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb
index b6d4207de82..8f332fab8d3 100644
--- a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb
@@ -1228,7 +1228,7 @@ RSpec.describe API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do
let(:setup) do
allow(Authorization)
.to receive(:roles)
- .with(current_user, project:, entity: nil)
+ .with(current_user, project)
.and_return(roles)
allow(roles)
diff --git a/spec/services/authorization/user_allowed_service_spec.rb b/spec/services/authorization/user_allowed_service_spec.rb
index ab14f1f629f..cc7e745fef1 100644
--- a/spec/services/authorization/user_allowed_service_spec.rb
+++ b/spec/services/authorization/user_allowed_service_spec.rb
@@ -69,7 +69,7 @@ RSpec.describe Authorization::UserAllowedService do
allow(Authorization)
.to receive(:roles)
- .with(user, project:, entity: nil)
+ .with(user, project)
.and_return(user_roles_in_project)
end
@@ -88,7 +88,7 @@ RSpec.describe Authorization::UserAllowedService do
Array(context).each do |project|
allow(Authorization)
.to receive(:roles)
- .with(user, project:, entity: nil)
+ .with(user, project)
.and_return(user_roles_in_project)
end
@@ -99,7 +99,7 @@ RSpec.describe Authorization::UserAllowedService do
expect(Authorization)
.to have_received(:roles)
.once
- .with(user, project:, entity: nil)
+ .with(user, project)
end
end
@@ -279,7 +279,7 @@ RSpec.describe Authorization::UserAllowedService do
before do
allow(Authorization)
.to receive(:roles)
- .with(user, project: nil, entity: nil)
+ .with(user, nil)
.and_return(user_roles_in_project)
allow(role)
@@ -307,7 +307,7 @@ RSpec.describe Authorization::UserAllowedService do
before do
allow(Authorization)
.to receive(:roles)
- .with(user, project: nil, entity: nil)
+ .with(user, nil)
.and_return(user_roles_in_project)
allow(role)