diff options
Diffstat (limited to 'lib/api')
| -rw-r--r-- | lib/api/applications.rb | 16 | ||||
| -rw-r--r-- | lib/api/entities.rb | 4 | ||||
| -rw-r--r-- | lib/api/features.rb | 2 | ||||
| -rw-r--r-- | lib/api/helpers.rb | 8 | ||||
| -rw-r--r-- | lib/api/internal.rb | 4 | ||||
| -rw-r--r-- | lib/api/jobs.rb | 2 | ||||
| -rw-r--r-- | lib/api/users.rb | 14 |
7 files changed, 30 insertions, 20 deletions
diff --git a/lib/api/applications.rb b/lib/api/applications.rb index f29cd7fc003..92717e04543 100644 --- a/lib/api/applications.rb +++ b/lib/api/applications.rb @@ -24,6 +24,22 @@ module API render_validation_error! application end end + + desc 'Get applications' do + success Entities::Application + end + get do + applications = ApplicationsFinder.new.execute + present applications, with: Entities::Application + end + + desc 'Delete an application' + delete ':id' do + application = ApplicationsFinder.new(params).execute + application.destroy + + status 204 + end end end end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 5a4b85f98cf..18c30723d73 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -260,7 +260,7 @@ module API super(projects_relation).preload(:group) .preload(project_group_links: :group, fork_network: :root_project, - forked_project_link: :forked_from_project, + fork_network_member: :forked_from_project, forked_from_project: [:route, :forks, :tags, namespace: :route]) end # rubocop: enable CodeReuse/ActiveRecord @@ -1412,7 +1412,9 @@ module API end class Application < Grape::Entity + expose :id expose :uid, as: :application_id + expose :name, as: :application_name expose :redirect_uri, as: :callback_url end diff --git a/lib/api/features.rb b/lib/api/features.rb index 6f2422af13a..1331248699f 100644 --- a/lib/api/features.rb +++ b/lib/api/features.rb @@ -20,7 +20,7 @@ module API def gate_targets(params) targets = [] targets << Feature.group(params[:feature_group]) if params[:feature_group] - targets << User.find_by_username(params[:user]) if params[:user] + targets << UserFinder.new(params[:user]).find_by_username if params[:user] targets end diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index a7ba8066233..60bf977f0e4 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -96,15 +96,9 @@ module API LabelsFinder.new(current_user, search_params).execute end - # rubocop: disable CodeReuse/ActiveRecord def find_user(id) - if id =~ /^\d+$/ - User.find_by(id: id) - else - User.find_by(username: id) - end + UserFinder.new(id).find_by_id_or_username end - # rubocop: enable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord def find_project(id) diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 6a264c4cc6d..4dd6b19e353 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -40,7 +40,7 @@ module API elsif params[:user_id] User.find_by(id: params[:user_id]) elsif params[:username] - User.find_by_username(params[:username]) + UserFinder.new(params[:username]).find_by_username end protocol = params[:protocol] @@ -154,7 +154,7 @@ module API elsif params[:user_id] user = User.find_by(id: params[:user_id]) elsif params[:username] - user = User.find_by(username: params[:username]) + user = UserFinder.new(params[:username]).find_by_username end present user, with: Entities::UserSafe diff --git a/lib/api/jobs.rb b/lib/api/jobs.rb index fa992b9a440..697555c9605 100644 --- a/lib/api/jobs.rb +++ b/lib/api/jobs.rb @@ -151,7 +151,7 @@ module API present build, with: Entities::Job end - desc 'Trigger a actionable job (manual, scheduled, etc)' do + desc 'Trigger a actionable job (manual, delayed, etc)' do success Entities::Job detail 'This feature was added in GitLab 8.11' end diff --git a/lib/api/users.rb b/lib/api/users.rb index 501c5cf1df3..47382b09207 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -155,7 +155,6 @@ module API requires :username, type: String, desc: 'The username of the user' use :optional_attributes end - # rubocop: disable CodeReuse/ActiveRecord post do authenticated_as_admin! @@ -166,17 +165,16 @@ module API present user, with: Entities::UserPublic, current_user: current_user else conflict!('Email has already been taken') if User - .where(email: user.email) - .count > 0 + .by_any_email(user.email.downcase) + .any? conflict!('Username has already been taken') if User - .where(username: user.username) - .count > 0 + .by_username(user.username) + .any? render_validation_error!(user) end end - # rubocop: enable CodeReuse/ActiveRecord desc 'Update a user. Available only for admins.' do success Entities::UserPublic @@ -198,11 +196,11 @@ module API not_found!('User') unless user conflict!('Email has already been taken') if params[:email] && - User.where(email: params[:email]) + User.by_any_email(params[:email].downcase) .where.not(id: user.id).count > 0 conflict!('Username has already been taken') if params[:username] && - User.where(username: params[:username]) + User.by_username(params[:username]) .where.not(id: user.id).count > 0 user_params = declared_params(include_missing: false) |
