1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

rubocop api controllers

This commit is contained in:
Sylvain 2019-01-16 13:07:19 +01:00
parent 526b9aab0c
commit c6cf86fa5c
5 changed files with 33 additions and 24 deletions

View File

@ -1,5 +1,5 @@
Metrics/LineLength:
Max: 125
Max: 140
Metrics/MethodLength:
Max: 30
Metrics/CyclomaticComplexity:

View File

@ -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

View File

@ -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

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class API::ApiController < ApplicationController

View File

@ -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
end
end