From c6cf86fa5ca5a1a6d39d1e81707cb16115759d8e Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 16 Jan 2019 13:07:19 +0100 Subject: [PATCH] rubocop api controllers --- .rubocop.yml | 2 +- app/controllers/api/admins_controller.rb | 2 +- app/controllers/api/age_ranges_controller.rb | 2 +- app/controllers/api/api_controller.rb | 2 + .../api/auth_providers_controller.rb | 49 +++++++++++-------- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 63c71c529..59ebb91cf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ Metrics/LineLength: - Max: 125 + Max: 140 Metrics/MethodLength: Max: 30 Metrics/CyclomaticComplexity: diff --git a/app/controllers/api/admins_controller.rb b/app/controllers/api/admins_controller.rb index 1b94cfcd8..ec2700b3d 100644 --- a/app/controllers/api/admins_controller.rb +++ b/app/controllers/api/admins_controller.rb @@ -34,7 +34,7 @@ class API::AdminsController < API::ApiController def destroy @admin = User.admins.find(params[:id]) - if current_user.admin? and @admin != current_user + if current_user.admin? && @admin != current_user @admin.destroy head :no_content else diff --git a/app/controllers/api/age_ranges_controller.rb b/app/controllers/api/age_ranges_controller.rb index f8805e3f1..169f4775b 100644 --- a/app/controllers/api/age_ranges_controller.rb +++ b/app/controllers/api/age_ranges_controller.rb @@ -22,7 +22,6 @@ class API::AgeRangesController < API::ApiController end end - def update authorize AgeRange if @age_range.update(age_range_params) @@ -42,6 +41,7 @@ class API::AgeRangesController < API::ApiController end private + def set_age_range @age_range = AgeRange.find(params[:id]) end diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 77a8f959e..2315de63a 100644 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class API::ApiController < ApplicationController diff --git a/app/controllers/api/auth_providers_controller.rb b/app/controllers/api/auth_providers_controller.rb index 173e401a7..3d063a91d 100644 --- a/app/controllers/api/auth_providers_controller.rb +++ b/app/controllers/api/auth_providers_controller.rb @@ -1,6 +1,10 @@ +# frozen_string_literal: true + +# API Controller for resources of type AuthProvider +# AuthProvider are used to connect users through single-sign on systems class API::AuthProvidersController < API::ApiController - before_action :set_provider, only: [:show, :update, :destroy] + before_action :set_provider, only: %i[show update destroy] def index @providers = policy_scope(AuthProvider) end @@ -57,33 +61,36 @@ class API::AuthProvidersController < API::ApiController NotificationCenter.call type: 'notify_user_auth_migration', receiver: user, attached_object: user - render json: {status: 'processing'}, status: :ok + render json: { status: 'processing' }, status: :ok else - render json: {status: 'error', error: I18n.t('members.current_authentication_method_no_code')}, status: :bad_request + render json: { status: 'error', error: I18n.t('members.current_authentication_method_no_code') }, status: :bad_request end else - render json: {status: 'error', error: I18n.t('members.requested_account_does_not_exists')}, status: :bad_request + render json: { status: 'error', error: I18n.t('members.requested_account_does_not_exists') }, status: :bad_request end end private - def set_provider - @provider = AuthProvider.find(params[:id]) - end + def set_provider + @provider = AuthProvider.find(params[:id]) + end - def provider_params - if params['auth_provider']['providable_type'] == DatabaseProvider.name - params.require(:auth_provider).permit(:name, :providable_type) - elsif params['auth_provider']['providable_type'] == OAuth2Provider.name - params.require(:auth_provider).permit(:name, :providable_type, providable_attributes: [ - :id, :base_url, :token_endpoint, :authorization_endpoint, :logout_endpoint, :profile_url, :client_id, :client_secret, - o_auth2_mappings_attributes: [ - :id, :local_model, :local_field, :api_field, :api_endpoint, :api_data_type, :_destroy, - transformation: [:type, :format, :true_value, :false_value, mapping: [:from, :to]] - ] - ]) - end + def provider_params + if params['auth_provider']['providable_type'] == DatabaseProvider.name + params.require(:auth_provider).permit(:name, :providable_type) + elsif params['auth_provider']['providable_type'] == OAuth2Provider.name + params.require(:auth_provider).permit(:name, :providable_type, + providable_attributes: [:id, :base_url, :token_endpoint, :authorization_endpoint, + :logout_endpoint, :profile_url, :client_id, :client_secret, + o_auth2_mappings_attributes: [:id, :local_model, :local_field, + :api_field, :api_endpoint, + :api_data_type, :_destroy, + transformation: [:type, + :format, + :true_value, + :false_value, + mapping: %i[from to]]]]) end - -end \ No newline at end of file + end +end