api_tokens_controller: extract become full_access
This commit is contained in:
parent
9b440b6c44
commit
9047c2a7de
2 changed files with 10 additions and 4 deletions
|
@ -29,8 +29,8 @@
|
||||||
%p.fr-text--lg
|
%p.fr-text--lg
|
||||||
= t('.allowed_procedures_html', count: @api_token.allowed_procedures.size)
|
= t('.allowed_procedures_html', count: @api_token.allowed_procedures.size)
|
||||||
|
|
||||||
- if @api_token.allowed_procedures.empty?
|
- if @api_token.procedures.empty?
|
||||||
= button_to t('.action_all'), @api_token, method: :patch, params: { api_token: { disallow_procedure_id: '0' } }, class: "fr-btn fr-btn--secondary"
|
= button_to t('.action_all'), @api_token, method: :patch, params: { api_token: { become_full_access: '1' } }, class: "fr-btn fr-btn--secondary"
|
||||||
- else
|
- else
|
||||||
%ul
|
%ul
|
||||||
- @api_token.allowed_procedures.each do |procedure|
|
- @api_token.allowed_procedures.each do |procedure|
|
||||||
|
|
|
@ -12,7 +12,9 @@ class APITokensController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if disallow_procedure_id.present?
|
if become_full_access?
|
||||||
|
@api_token.become_full_access!
|
||||||
|
elsif disallow_procedure_id.present?
|
||||||
@api_token.untarget_procedure(disallow_procedure_id.to_i)
|
@api_token.untarget_procedure(disallow_procedure_id.to_i)
|
||||||
else
|
else
|
||||||
@api_token.update!(api_token_params)
|
@api_token.update!(api_token_params)
|
||||||
|
@ -39,11 +41,15 @@ class APITokensController < ApplicationController
|
||||||
@api_token = current_administrateur.api_tokens.find(params[:id])
|
@api_token = current_administrateur.api_tokens.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def become_full_access?
|
||||||
|
api_token_params[:become_full_access].present?
|
||||||
|
end
|
||||||
|
|
||||||
def disallow_procedure_id
|
def disallow_procedure_id
|
||||||
api_token_params[:disallow_procedure_id]
|
api_token_params[:disallow_procedure_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
def api_token_params
|
def api_token_params
|
||||||
params.require(:api_token).permit(:name, :write_access, :disallow_procedure_id, allowed_procedure_ids: [])
|
params.require(:api_token).permit(:name, :write_access, :become_full_access, :disallow_procedure_id, allowed_procedure_ids: [])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue