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:
parent
526b9aab0c
commit
c6cf86fa5c
@ -1,5 +1,5 @@
|
|||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
Max: 125
|
Max: 140
|
||||||
Metrics/MethodLength:
|
Metrics/MethodLength:
|
||||||
Max: 30
|
Max: 30
|
||||||
Metrics/CyclomaticComplexity:
|
Metrics/CyclomaticComplexity:
|
||||||
|
@ -34,7 +34,7 @@ class API::AdminsController < API::ApiController
|
|||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@admin = User.admins.find(params[:id])
|
@admin = User.admins.find(params[:id])
|
||||||
if current_user.admin? and @admin != current_user
|
if current_user.admin? && @admin != current_user
|
||||||
@admin.destroy
|
@admin.destroy
|
||||||
head :no_content
|
head :no_content
|
||||||
else
|
else
|
||||||
|
@ -22,7 +22,6 @@ class API::AgeRangesController < API::ApiController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def update
|
def update
|
||||||
authorize AgeRange
|
authorize AgeRange
|
||||||
if @age_range.update(age_range_params)
|
if @age_range.update(age_range_params)
|
||||||
@ -42,6 +41,7 @@ class API::AgeRangesController < API::ApiController
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_age_range
|
def set_age_range
|
||||||
@age_range = AgeRange.find(params[:id])
|
@age_range = AgeRange.find(params[:id])
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class API::ApiController < ApplicationController
|
class API::ApiController < ApplicationController
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
class API::AuthProvidersController < API::ApiController
|
||||||
|
|
||||||
before_action :set_provider, only: [:show, :update, :destroy]
|
before_action :set_provider, only: %i[show update destroy]
|
||||||
def index
|
def index
|
||||||
@providers = policy_scope(AuthProvider)
|
@providers = policy_scope(AuthProvider)
|
||||||
end
|
end
|
||||||
@ -57,33 +61,36 @@ class API::AuthProvidersController < API::ApiController
|
|||||||
NotificationCenter.call type: 'notify_user_auth_migration',
|
NotificationCenter.call type: 'notify_user_auth_migration',
|
||||||
receiver: user,
|
receiver: user,
|
||||||
attached_object: user
|
attached_object: user
|
||||||
render json: {status: 'processing'}, status: :ok
|
render json: { status: 'processing' }, status: :ok
|
||||||
else
|
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
|
end
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_provider
|
def set_provider
|
||||||
@provider = AuthProvider.find(params[:id])
|
@provider = AuthProvider.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def provider_params
|
def provider_params
|
||||||
if params['auth_provider']['providable_type'] == DatabaseProvider.name
|
if params['auth_provider']['providable_type'] == DatabaseProvider.name
|
||||||
params.require(:auth_provider).permit(:name, :providable_type)
|
params.require(:auth_provider).permit(:name, :providable_type)
|
||||||
elsif params['auth_provider']['providable_type'] == OAuth2Provider.name
|
elsif params['auth_provider']['providable_type'] == OAuth2Provider.name
|
||||||
params.require(:auth_provider).permit(:name, :providable_type, providable_attributes: [
|
params.require(:auth_provider).permit(:name, :providable_type,
|
||||||
:id, :base_url, :token_endpoint, :authorization_endpoint, :logout_endpoint, :profile_url, :client_id, :client_secret,
|
providable_attributes: [:id, :base_url, :token_endpoint, :authorization_endpoint,
|
||||||
o_auth2_mappings_attributes: [
|
:logout_endpoint, :profile_url, :client_id, :client_secret,
|
||||||
:id, :local_model, :local_field, :api_field, :api_endpoint, :api_data_type, :_destroy,
|
o_auth2_mappings_attributes: [:id, :local_model, :local_field,
|
||||||
transformation: [:type, :format, :true_value, :false_value, mapping: [:from, :to]]
|
:api_field, :api_endpoint,
|
||||||
]
|
:api_data_type, :_destroy,
|
||||||
])
|
transformation: [:type,
|
||||||
end
|
:format,
|
||||||
|
:true_value,
|
||||||
|
:false_value,
|
||||||
|
mapping: %i[from to]]]])
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user