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
use standard index endpoint
ulfertsa7a37ea47a86
diff --git a/lib/api/v3/principals/principals_api.rb b/lib/api/v3/principals/principals_api.rbindex a9061621a12..c2b7840f620 100644--- a/lib/api/v3/principals/principals_api.rb+++ b/lib/api/v3/principals/principals_api.rb@@ -30,27 +30,12 @@ module APImodule V3module Principalsclass 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)+ .mountendendenddiff --git a/lib/api/v3/users/users_api.rb b/lib/api/v3/users/users_api.rbindex 337f9226e69..401f06a45ce 100644--- a/lib/api/v3/users/users_api.rb+++ b/lib/api/v3/users/users_api.rb@@ -33,8 +33,6 @@ module APImodule V3module Usersclass UsersAPI < ::API::OpenProjectAPI- helpers ::API::Utilities::PageSizeHelper-helpers dodef user_transition(allowed)if allowed@@ -47,30 +45,21 @@ module APIfail ::API::Errors::InvalidUserStatusTransitionendend-- def authorize_user_cru_allowed- authorize_by_with_raise(current_user.allowed_to_globally?(:manage_user))- endendresources :users dopost &::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)+ .mountendmount ::API::V3::Users::Schemas::UserSchemaAPIdiff --git a/spec/requests/api/v3/user/user_resource_spec.rb b/spec/requests/api/v3/user/user_resource_spec.rbindex 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',endshared_examples 'flow with permitted user' do- it 'should respond with 200' do+ it 'responds with 200' doexpect(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' doexpect(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')endcontext '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' doexpect(subject.body)