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 standard index endpoint

ulfertsa7a37ea47a86
diff --git a/lib/api/v3/principals/principals_api.rb b/lib/api/v3/principals/principals_api.rb
index a9061621a12..c2b7840f620 100644
--- a/lib/api/v3/principals/principals_api.rb
+++ b/lib/api/v3/principals/principals_api.rb
@@ -30,27 +30,12 @@ module API
module V3
module Principals
class PrincipalsAPI < ::API::OpenProjectAPI
- helpers ::API::Utilities::PageSizeHelper
-
resource :principals do
- get do
- query = ParamsToQueryService.new(Principal, current_user).call(params)
-
- if query.valid?
- principals = query
- .results
- .where(id: Principal.visible(current_user))
- .includes(:preference)
-
- ::API::V3::Users::PaginatedUserCollectionRepresenter.new(principals,
- self_link: api_v3_paths.principals,
- page: to_i_or_nil(params[:offset]),
- per_page: resolve_page_size(params[:pageSize]),
- current_user: current_user)
- else
- raise ::API::Errors::InvalidQuery.new(query.errors.full_messages)
- end
- end
+ get &::API::V3::Utilities::Endpoints::Index
+ .new(model: Principal,
+ scope: -> { Principal.visible(current_user).includes(:preference) },
+ render_representer: ::API::V3::Users::PaginatedUserCollectionRepresenter)
+ .mount
end
end
end
diff --git a/lib/api/v3/users/users_api.rb b/lib/api/v3/users/users_api.rb
index 337f9226e69..401f06a45ce 100644
--- a/lib/api/v3/users/users_api.rb
+++ b/lib/api/v3/users/users_api.rb
@@ -33,8 +33,6 @@ module API
module V3
module Users
class UsersAPI < ::API::OpenProjectAPI
- helpers ::API::Utilities::PageSizeHelper
-
helpers do
def user_transition(allowed)
if allowed
@@ -47,30 +45,21 @@ module API
fail ::API::Errors::InvalidUserStatusTransition
end
end
-
- def authorize_user_cru_allowed
- authorize_by_with_raise(current_user.allowed_to_globally?(:manage_user))
- end
end
resources :users do
post &::API::V3::Utilities::Endpoints::Create.new(model: User).mount
- get do
- authorize_user_cru_allowed
-
- query = ParamsToQueryService.new(User, current_user).call(params)
-
- if query.valid?
- users = query.results.includes(:preference)
- PaginatedUserCollectionRepresenter.new(users,
- self_link: api_v3_paths.users,
- page: to_i_or_nil(params[:offset]),
- per_page: resolve_page_size(params[:pageSize]),
- current_user: current_user)
- else
- raise ::API::Errors::InvalidQuery.new(query.errors.full_messages)
+ # The namespace only exists to add the after_validation callback
+ namespace '' do
+ after_validation do
+ authorize_by_with_raise(current_user.allowed_to_globally?(:manage_user))
end
+
+ get &::API::V3::Utilities::Endpoints::Index.new(model: User,
+ scope: -> { User.user.includes(:preference) },
+ render_representer: PaginatedUserCollectionRepresenter)
+ .mount
end
mount ::API::V3::Users::Schemas::UserSchemaAPI
diff --git a/spec/requests/api/v3/user/user_resource_spec.rb b/spec/requests/api/v3/user/user_resource_spec.rb
index e27b493dc3b..7bd10661682 100644
--- a/spec/requests/api/v3/user/user_resource_spec.rb
+++ b/spec/requests/api/v3/user/user_resource_spec.rb
@@ -58,7 +58,7 @@ describe 'API v3 User resource',
end
shared_examples 'flow with permitted user' do
- it 'should respond with 200' do
+ it 'responds with 200' do
expect(subject.status).to eq(200)
end
@@ -78,12 +78,13 @@ describe 'API v3 User resource',
it 'has the users index path for link self href' do
expect(subject.body)
- .to be_json_eql((api_v3_paths.users + '?offset=1&pageSize=30').to_json)
+ .to be_json_eql("#{api_v3_paths.users}?filters=%5B%5D" \
+ "\u0026offset=1\u0026pageSize=20\u0026sortBy=%5B%5B%22id%22%2C%22asc%22%5D%5D".to_json)
.at_path('_links/self/href')
end
context 'if pageSize = 1 and offset = 2' do
- let(:get_path) { api_v3_paths.users + '?pageSize=1&offset=2' }
+ let(:get_path) { api_v3_paths.path_for(:users, page_size: 1, offset: 2) }
it 'contains the current user in the response' do
expect(subject.body)