From 3421f1d124ecf34c620d75488c22fa3fab602721 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Thu, 11 Oct 2018 19:52:42 +0900 Subject: Expose id and name attributes to Applications API --- lib/api/entities.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 5a4b85f98cf..f5e33000a9f 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -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 -- cgit v1.2.1 From 6dd4ae0d87fd9a30ab9ce36b5127be36929f5692 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Thu, 11 Oct 2018 19:54:15 +0900 Subject: Support GET /applications and DELETE /applications/:id endpoints #52559 --- doc/api/applications.md | 51 ++++++++++++++++++++++++++++++++-- lib/api/applications.rb | 17 ++++++++++++ spec/requests/api/applications_spec.rb | 38 +++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/doc/api/applications.md b/doc/api/applications.md index 6d244594b71..d74a3cdf5c1 100644 --- a/doc/api/applications.md +++ b/doc/api/applications.md @@ -4,12 +4,12 @@ [ce-8160]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8160 +Only admin user can use the Applications API. + ## Create a application Create a application by posting a JSON payload. -User must be admin to do that. - Returns `200` if the request succeeds. ``` @@ -30,8 +30,55 @@ Example response: ```json { + "id":1, "application_id": "5832fc6e14300a0d962240a8144466eef4ee93ef0d218477e55f11cf12fc3737", + "application_name": "MyApplication", "secret": "ee1dd64b6adc89cf7e2c23099301ccc2c61b441064e9324d963c46902a85ec34", "callback_url": "http://redirect.uri" } ``` + +## List all applications + +List all registered applications. + +``` +GET /applications +``` + +```bash +curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/applications +``` + +Example response: + +```json +[ + { + "id":1, + "application_id": "5832fc6e14300a0d962240a8144466eef4ee93ef0d218477e55f11cf12fc3737", + "application_name": "MyApplication", + "callback_url": "http://redirect.uri" + } +] +``` + +> Note: the `secret` value will not be exposed by this API. + +## Delete an application + +Delete a specific application. + +Returns `204` if the request succeeds. + +``` +DELETE /applications/:id +``` + +Parameters: + +- `id` (required) - The id of the application (not the application_id) + +```bash +curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/applications/:id +``` diff --git a/lib/api/applications.rb b/lib/api/applications.rb index f29cd7fc003..1c940af95d7 100644 --- a/lib/api/applications.rb +++ b/lib/api/applications.rb @@ -24,6 +24,23 @@ module API render_validation_error! application end end + + desc 'Get applications' do + success Entities::ApplicationWithSecret + end + get do + applications = Doorkeeper::Application.all + present applications, with: Entities::Application + end + + # rubocop: disable CodeReuse/ActiveRecord + desc 'Delete an application' + delete ':id' do + Doorkeeper::Application.find_by(id: params[:id]).destroy + + status 204 + end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/spec/requests/api/applications_spec.rb b/spec/requests/api/applications_spec.rb index f56bc932f40..02dfbfa8fd7 100644 --- a/spec/requests/api/applications_spec.rb +++ b/spec/requests/api/applications_spec.rb @@ -5,6 +5,7 @@ describe API::Applications, :api do let(:admin_user) { create(:user, admin: true) } let(:user) { create(:user, admin: false) } + let(:application) { create(:application, name: 'application_name', redirect_uri: 'http://application.url', scopes: '') } describe 'POST /applications' do context 'authenticated and authorized user' do @@ -83,4 +84,41 @@ describe API::Applications, :api do end end end + + describe 'GET /applications' do + context 'authenticated and authorized user' do + it 'can list application' do + get api('/applications') + + expect(response).to have_gitlab_http_status(200) + expect(json_response).to be_a(Array) + end + end + + context 'non-authenticated user' do + it 'cannot list application' do + get api('/applications') + + expect(response).to have_http_status 401 + end + end + end + + describe 'DELETE /applications/:id' do + context 'authenticated and authorized user' do + it 'can delete an application' do + delete api("/applications/#{application.id}") + + expect(response).to have_gitlab_http_status(204) + end + end + + context 'non-authenticated user' do + it 'cannot delete an application' do + delete api("/applications/#{application.id}") + + expect(response).to have_http_status 401 + end + end + end end -- cgit v1.2.1 From 33c88f5e5192bec231656e4253263178d8004e63 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Thu, 11 Oct 2018 21:12:25 +0900 Subject: Fix tests --- spec/requests/api/applications_spec.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/requests/api/applications_spec.rb b/spec/requests/api/applications_spec.rb index 02dfbfa8fd7..f95b40fff17 100644 --- a/spec/requests/api/applications_spec.rb +++ b/spec/requests/api/applications_spec.rb @@ -88,7 +88,7 @@ describe API::Applications, :api do describe 'GET /applications' do context 'authenticated and authorized user' do it 'can list application' do - get api('/applications') + get api('/applications', admin_user) expect(response).to have_gitlab_http_status(200) expect(json_response).to be_a(Array) @@ -97,7 +97,7 @@ describe API::Applications, :api do context 'non-authenticated user' do it 'cannot list application' do - get api('/applications') + get api('/applications', user) expect(response).to have_http_status 401 end @@ -107,15 +107,17 @@ describe API::Applications, :api do describe 'DELETE /applications/:id' do context 'authenticated and authorized user' do it 'can delete an application' do - delete api("/applications/#{application.id}") - + expect do + delete api("/applications/#{application.id}", admin_user) + end.to change { Doorkeeper::Application.count }.by -1 + expect(response).to have_gitlab_http_status(204) end end context 'non-authenticated user' do it 'cannot delete an application' do - delete api("/applications/#{application.id}") + delete api("/applications/#{application.id}", user) expect(response).to have_http_status 401 end -- cgit v1.2.1 From f1645bf7e722096f570a706d37c3379f07a55a68 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Thu, 11 Oct 2018 22:35:17 +0900 Subject: Fix unauthorized user tests and add non-authenticated user tests --- spec/requests/api/applications_spec.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/spec/requests/api/applications_spec.rb b/spec/requests/api/applications_spec.rb index f95b40fff17..9240dd94990 100644 --- a/spec/requests/api/applications_spec.rb +++ b/spec/requests/api/applications_spec.rb @@ -95,6 +95,14 @@ describe API::Applications, :api do end end + context 'authorized user without authorization' do + it 'cannot list application' do + get api('/applications', user) + + expect(response).to have_http_status 403 + end + end + context 'non-authenticated user' do it 'cannot list application' do get api('/applications', user) @@ -109,16 +117,24 @@ describe API::Applications, :api do it 'can delete an application' do expect do delete api("/applications/#{application.id}", admin_user) - end.to change { Doorkeeper::Application.count }.by -1 - + end.to change { Doorkeeper::Application.count }.by(-1) + expect(response).to have_gitlab_http_status(204) end end - context 'non-authenticated user' do + context 'authorized user without authorization' do it 'cannot delete an application' do delete api("/applications/#{application.id}", user) + expect(response).to have_http_status 403 + end + end + + context 'non-authenticated user' do + it 'cannot delete an application' do + delete api("/applications/#{application.id}") + expect(response).to have_http_status 401 end end -- cgit v1.2.1 From 20bbac427ab2aea423d3f377c4319687520475a4 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Thu, 11 Oct 2018 23:32:44 +0900 Subject: Hit the database --- spec/requests/api/applications_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/requests/api/applications_spec.rb b/spec/requests/api/applications_spec.rb index 9240dd94990..77b4c5ecbba 100644 --- a/spec/requests/api/applications_spec.rb +++ b/spec/requests/api/applications_spec.rb @@ -5,7 +5,7 @@ describe API::Applications, :api do let(:admin_user) { create(:user, admin: true) } let(:user) { create(:user, admin: false) } - let(:application) { create(:application, name: 'application_name', redirect_uri: 'http://application.url', scopes: '') } + let!(:application) { create(:application, name: 'application_name', redirect_uri: 'http://application.url', scopes: '') } describe 'POST /applications' do context 'authenticated and authorized user' do @@ -107,7 +107,7 @@ describe API::Applications, :api do it 'cannot list application' do get api('/applications', user) - expect(response).to have_http_status 401 + expect(response).to have_http_status 403 end end end -- cgit v1.2.1 From 9fcf657889729e23587ec12a1c97c8d0cd43d992 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Fri, 12 Oct 2018 00:25:52 +0900 Subject: Differentiate test application values --- spec/requests/api/applications_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/api/applications_spec.rb b/spec/requests/api/applications_spec.rb index 77b4c5ecbba..5c383317b7e 100644 --- a/spec/requests/api/applications_spec.rb +++ b/spec/requests/api/applications_spec.rb @@ -5,7 +5,7 @@ describe API::Applications, :api do let(:admin_user) { create(:user, admin: true) } let(:user) { create(:user, admin: false) } - let!(:application) { create(:application, name: 'application_name', redirect_uri: 'http://application.url', scopes: '') } + let!(:application) { create(:application, name: 'another_application', redirect_uri: 'http://other_application.url', scopes: '') } describe 'POST /applications' do context 'authenticated and authorized user' do -- cgit v1.2.1 From 9e3804a843a9146e7bd77eb6abfe10417be7a549 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Fri, 12 Oct 2018 09:28:40 +0900 Subject: Non-authenticated user test should not have user passed in the API call !22296 --- spec/requests/api/applications_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/requests/api/applications_spec.rb b/spec/requests/api/applications_spec.rb index 5c383317b7e..3e732ed478e 100644 --- a/spec/requests/api/applications_spec.rb +++ b/spec/requests/api/applications_spec.rb @@ -105,9 +105,9 @@ describe API::Applications, :api do context 'non-authenticated user' do it 'cannot list application' do - get api('/applications', user) + get api('/applications') - expect(response).to have_http_status 403 + expect(response).to have_http_status 401 end end end -- cgit v1.2.1 From 2122727468a42bf8b5b4c0e7cb18b528cf4ea4ab Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Fri, 12 Oct 2018 09:31:22 +0900 Subject: Add changelog !22296 --- changelogs/unreleased/52559-applications-api-get-delete.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/52559-applications-api-get-delete.yml diff --git a/changelogs/unreleased/52559-applications-api-get-delete.yml b/changelogs/unreleased/52559-applications-api-get-delete.yml new file mode 100644 index 00000000000..19f98a2bb56 --- /dev/null +++ b/changelogs/unreleased/52559-applications-api-get-delete.yml @@ -0,0 +1,5 @@ +--- +title: Add Applications API endpoints for listing and deleting entries. +merge_request: 22296 +author: Jean-Baptiste Vasseur +type: added -- cgit v1.2.1 From 23d70f6281f7c099ff7ce5b9abe40d7afd5ab668 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Fri, 12 Oct 2018 09:40:11 +0900 Subject: Improve call for retrieving all applications !22296 --- lib/api/applications.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api/applications.rb b/lib/api/applications.rb index 1c940af95d7..8d83684e3a9 100644 --- a/lib/api/applications.rb +++ b/lib/api/applications.rb @@ -29,7 +29,7 @@ module API success Entities::ApplicationWithSecret end get do - applications = Doorkeeper::Application.all + applications = Doorkeeper::Application.where("owner_id IS NULL") present applications, with: Entities::Application end -- cgit v1.2.1 From 1dbbd0b9b01050ef929780474153dfc57a57efdc Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Fri, 12 Oct 2018 09:41:36 +0900 Subject: disable CodeReuse/ActiveRecord --- lib/api/applications.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/api/applications.rb b/lib/api/applications.rb index 8d83684e3a9..048e7bc81f9 100644 --- a/lib/api/applications.rb +++ b/lib/api/applications.rb @@ -25,6 +25,7 @@ module API end end + # rubocop: disable CodeReuse/ActiveRecord desc 'Get applications' do success Entities::ApplicationWithSecret end @@ -32,6 +33,7 @@ module API applications = Doorkeeper::Application.where("owner_id IS NULL") present applications, with: Entities::Application end + # rubocop: enable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord desc 'Delete an application' -- cgit v1.2.1 From abf7c10b67cfd7827370b25f1e4c64a3f615670b Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Fri, 12 Oct 2018 18:33:58 +0900 Subject: Do not return secret from GET /applications !22296 --- lib/api/applications.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api/applications.rb b/lib/api/applications.rb index 048e7bc81f9..9d0f7a093d5 100644 --- a/lib/api/applications.rb +++ b/lib/api/applications.rb @@ -27,7 +27,7 @@ module API # rubocop: disable CodeReuse/ActiveRecord desc 'Get applications' do - success Entities::ApplicationWithSecret + success Entities::Application end get do applications = Doorkeeper::Application.where("owner_id IS NULL") -- cgit v1.2.1 From c47aea75766fe3165cc9530fc9ccb5a4ac615e46 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Mon, 15 Oct 2018 20:07:56 +0900 Subject: Use have_gitlab_http_status following best practices !22296 --- spec/requests/api/applications_spec.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/requests/api/applications_spec.rb b/spec/requests/api/applications_spec.rb index 3e732ed478e..270e12bf201 100644 --- a/spec/requests/api/applications_spec.rb +++ b/spec/requests/api/applications_spec.rb @@ -16,7 +16,7 @@ describe API::Applications, :api do application = Doorkeeper::Application.find_by(name: 'application_name', redirect_uri: 'http://application.url') - expect(response).to have_http_status 201 + expect(response).to have_gitlab_http_status(201) expect(json_response).to be_a Hash expect(json_response['application_id']).to eq application.uid expect(json_response['secret']).to eq application.secret @@ -28,7 +28,7 @@ describe API::Applications, :api do post api('/applications', admin_user), name: 'application_name', redirect_uri: 'wrong_url_format', scopes: '' end.not_to change { Doorkeeper::Application.count } - expect(response).to have_http_status 400 + expect(response).to have_gitlab_http_status(400) expect(json_response).to be_a Hash expect(json_response['message']['redirect_uri'][0]).to eq('must be an absolute URI.') end @@ -38,7 +38,7 @@ describe API::Applications, :api do post api('/applications', admin_user), redirect_uri: 'http://application.url', scopes: '' end.not_to change { Doorkeeper::Application.count } - expect(response).to have_http_status 400 + expect(response).to have_gitlab_http_status(400) expect(json_response).to be_a Hash expect(json_response['error']).to eq('name is missing') end @@ -48,7 +48,7 @@ describe API::Applications, :api do post api('/applications', admin_user), name: 'application_name', scopes: '' end.not_to change { Doorkeeper::Application.count } - expect(response).to have_http_status 400 + expect(response).to have_gitlab_http_status(400) expect(json_response).to be_a Hash expect(json_response['error']).to eq('redirect_uri is missing') end @@ -58,7 +58,7 @@ describe API::Applications, :api do post api('/applications', admin_user), name: 'application_name', redirect_uri: 'http://application.url' end.not_to change { Doorkeeper::Application.count } - expect(response).to have_http_status 400 + expect(response).to have_gitlab_http_status(400) expect(json_response).to be_a Hash expect(json_response['error']).to eq('scopes is missing') end @@ -70,7 +70,7 @@ describe API::Applications, :api do post api('/applications', user), name: 'application_name', redirect_uri: 'http://application.url', scopes: '' end.not_to change { Doorkeeper::Application.count } - expect(response).to have_http_status 403 + expect(response).to have_gitlab_http_status(403) end end @@ -80,7 +80,7 @@ describe API::Applications, :api do post api('/applications'), name: 'application_name', redirect_uri: 'http://application.url' end.not_to change { Doorkeeper::Application.count } - expect(response).to have_http_status 401 + expect(response).to have_gitlab_http_status(401) end end end @@ -99,7 +99,7 @@ describe API::Applications, :api do it 'cannot list application' do get api('/applications', user) - expect(response).to have_http_status 403 + expect(response).to have_gitlab_http_status(403) end end @@ -107,7 +107,7 @@ describe API::Applications, :api do it 'cannot list application' do get api('/applications') - expect(response).to have_http_status 401 + expect(response).to have_gitlab_http_status(401) end end end @@ -127,7 +127,7 @@ describe API::Applications, :api do it 'cannot delete an application' do delete api("/applications/#{application.id}", user) - expect(response).to have_http_status 403 + expect(response).to have_gitlab_http_status(403) end end @@ -135,7 +135,7 @@ describe API::Applications, :api do it 'cannot delete an application' do delete api("/applications/#{application.id}") - expect(response).to have_http_status 401 + expect(response).to have_gitlab_http_status(401) end end end -- cgit v1.2.1 From 1ae9aefe5572cc62256f28e16163015f075b6c59 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Mon, 15 Oct 2018 23:03:08 +0900 Subject: Use application finder for Doorkeeper Applications --- app/finders/applications_finder.rb | 26 ++++++++++++++++++++++++++ lib/api/applications.rb | 9 +++------ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 app/finders/applications_finder.rb diff --git a/app/finders/applications_finder.rb b/app/finders/applications_finder.rb new file mode 100644 index 00000000000..14bd35105d2 --- /dev/null +++ b/app/finders/applications_finder.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class ApplicationsFinder + attr_reader :params + + def initialize(params = {}) + @params = params + end + + # rubocop: disable CodeReuse/ActiveRecord + def execute + applications = Doorkeeper::Application.where("owner_id IS NULL") + by_id(applications) + end + # rubocop: enable CodeReuse/ActiveRecord + + private + + # rubocop: disable CodeReuse/ActiveRecord + def by_id(applications) + return applications unless params[:id] + + Doorkeeper::Application.find_by(id: params[:id]) + end + # rubocop: enable CodeReuse/ActiveRecord +end diff --git a/lib/api/applications.rb b/lib/api/applications.rb index 9d0f7a093d5..92717e04543 100644 --- a/lib/api/applications.rb +++ b/lib/api/applications.rb @@ -25,24 +25,21 @@ module API end end - # rubocop: disable CodeReuse/ActiveRecord desc 'Get applications' do success Entities::Application end get do - applications = Doorkeeper::Application.where("owner_id IS NULL") + applications = ApplicationsFinder.new.execute present applications, with: Entities::Application end - # rubocop: enable CodeReuse/ActiveRecord - # rubocop: disable CodeReuse/ActiveRecord desc 'Delete an application' delete ':id' do - Doorkeeper::Application.find_by(id: params[:id]).destroy + application = ApplicationsFinder.new(params).execute + application.destroy status 204 end - # rubocop: enable CodeReuse/ActiveRecord end end end -- cgit v1.2.1 From 84b69a95bbe110cb688b7b6b6f20a53ff3819c89 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Thu, 18 Oct 2018 09:33:46 +0900 Subject: Test ApplicationsFinder !22296 --- spec/finders/applications_finder_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 spec/finders/applications_finder_spec.rb diff --git a/spec/finders/applications_finder_spec.rb b/spec/finders/applications_finder_spec.rb new file mode 100644 index 00000000000..a75eb9c9ca5 --- /dev/null +++ b/spec/finders/applications_finder_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ApplicationsFinder do + let(:application1) { create(:application, name: 'some_application', owner: nil, redirect_uri: 'http://some_application.url', scopes: '') } + let(:application2) { create(:application, name: 'another_application', owner: nil, redirect_uri: 'http://other_application.url', scopes: '') } + + describe '#execute' do + it 'returns an array of applications' do + found = described_class.new.execute + + expect(found).to match_array([application1,application2]) + end + it 'returns the application by id' do + params = { id: application1.id } + found = described_class.new(params).execute + + expect(found).to match(application1) + end + end +end -- cgit v1.2.1 From deeeffe09dfd331bc6068cea23346a35ef46ff45 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Thu, 18 Oct 2018 09:37:45 +0900 Subject: Source cleaning !22296 --- app/finders/applications_finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/finders/applications_finder.rb b/app/finders/applications_finder.rb index 14bd35105d2..88b1d17cf19 100644 --- a/app/finders/applications_finder.rb +++ b/app/finders/applications_finder.rb @@ -9,7 +9,7 @@ class ApplicationsFinder # rubocop: disable CodeReuse/ActiveRecord def execute - applications = Doorkeeper::Application.where("owner_id IS NULL") + applications = Doorkeeper::Application.where(owner_id: nil) by_id(applications) end # rubocop: enable CodeReuse/ActiveRecord -- cgit v1.2.1 From 6da97336522dfba8a02485f765be433ec4f4781a Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Thu, 18 Oct 2018 09:43:35 +0900 Subject: Use ApplicationsFinder !22296 --- app/controllers/admin/applications_controller.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/applications_controller.rb b/app/controllers/admin/applications_controller.rb index 00d2cc01192..2fcd38607be 100644 --- a/app/controllers/admin/applications_controller.rb +++ b/app/controllers/admin/applications_controller.rb @@ -6,11 +6,9 @@ class Admin::ApplicationsController < Admin::ApplicationController before_action :set_application, only: [:show, :edit, :update, :destroy] before_action :load_scopes, only: [:new, :create, :edit, :update] - # rubocop: disable CodeReuse/ActiveRecord def index - @applications = Doorkeeper::Application.where("owner_id IS NULL") + @applications = ApplicationsFinder.new.execute end - # rubocop: enable CodeReuse/ActiveRecord def show end @@ -49,11 +47,9 @@ class Admin::ApplicationsController < Admin::ApplicationController private - # rubocop: disable CodeReuse/ActiveRecord def set_application - @application = Doorkeeper::Application.where("owner_id IS NULL").find(params[:id]) + @application = ApplicationsFinder.new({ id: params[:id] }).execute end - # rubocop: enable CodeReuse/ActiveRecord # Only allow a trusted parameter "white list" through. def application_params -- cgit v1.2.1 From fbd372114de4930e94266fbfee2268643e72930f Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Thu, 18 Oct 2018 10:08:23 +0900 Subject: Code styling --- spec/finders/applications_finder_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/finders/applications_finder_spec.rb b/spec/finders/applications_finder_spec.rb index a75eb9c9ca5..14d6b35cc27 100644 --- a/spec/finders/applications_finder_spec.rb +++ b/spec/finders/applications_finder_spec.rb @@ -10,7 +10,7 @@ describe ApplicationsFinder do it 'returns an array of applications' do found = described_class.new.execute - expect(found).to match_array([application1,application2]) + expect(found).to match_array([application1, application2]) end it 'returns the application by id' do params = { id: application1.id } -- cgit v1.2.1 From 9f3408390102c3934e3a1e5f0edafe6f3d1c9862 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Thu, 18 Oct 2018 17:46:03 +0900 Subject: Remove useless braces !22296 --- app/controllers/admin/applications_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/applications_controller.rb b/app/controllers/admin/applications_controller.rb index 2fcd38607be..6fc336714b6 100644 --- a/app/controllers/admin/applications_controller.rb +++ b/app/controllers/admin/applications_controller.rb @@ -48,7 +48,7 @@ class Admin::ApplicationsController < Admin::ApplicationController private def set_application - @application = ApplicationsFinder.new({ id: params[:id] }).execute + @application = ApplicationsFinder.new(id: params[:id]).execute end # Only allow a trusted parameter "white list" through. -- cgit v1.2.1 From 192ccaebfc09c29bc62defb5f9a0fc69600600a1 Mon Sep 17 00:00:00 2001 From: JB Vasseur Date: Fri, 19 Oct 2018 08:28:44 +0900 Subject: Disable offense on the appropriate line only !22296 --- app/finders/applications_finder.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/finders/applications_finder.rb b/app/finders/applications_finder.rb index 88b1d17cf19..3ded90f3fd5 100644 --- a/app/finders/applications_finder.rb +++ b/app/finders/applications_finder.rb @@ -7,20 +7,16 @@ class ApplicationsFinder @params = params end - # rubocop: disable CodeReuse/ActiveRecord def execute - applications = Doorkeeper::Application.where(owner_id: nil) + applications = Doorkeeper::Application.where(owner_id: nil) # rubocop: disable CodeReuse/ActiveRecord by_id(applications) end - # rubocop: enable CodeReuse/ActiveRecord private - # rubocop: disable CodeReuse/ActiveRecord def by_id(applications) return applications unless params[:id] - Doorkeeper::Application.find_by(id: params[:id]) + Doorkeeper::Application.find_by(id: params[:id]) # rubocop: disable CodeReuse/ActiveRecord end - # rubocop: enable CodeReuse/ActiveRecord end -- cgit v1.2.1