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
|
||||
= t('.allowed_procedures_html', count: @api_token.allowed_procedures.size)
|
||||
|
||||
- if @api_token.allowed_procedures.empty?
|
||||
= button_to t('.action_all'), @api_token, method: :patch, params: { api_token: { disallow_procedure_id: '0' } }, class: "fr-btn fr-btn--secondary"
|
||||
- if @api_token.procedures.empty?
|
||||
= button_to t('.action_all'), @api_token, method: :patch, params: { api_token: { become_full_access: '1' } }, class: "fr-btn fr-btn--secondary"
|
||||
- else
|
||||
%ul
|
||||
- @api_token.allowed_procedures.each do |procedure|
|
||||
|
|
|
@ -12,7 +12,9 @@ class APITokensController < ApplicationController
|
|||
end
|
||||
|
||||
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)
|
||||
else
|
||||
@api_token.update!(api_token_params)
|
||||
|
@ -39,11 +41,15 @@ class APITokensController < ApplicationController
|
|||
@api_token = current_administrateur.api_tokens.find(params[:id])
|
||||
end
|
||||
|
||||
def become_full_access?
|
||||
api_token_params[:become_full_access].present?
|
||||
end
|
||||
|
||||
def disallow_procedure_id
|
||||
api_token_params[:disallow_procedure_id]
|
||||
end
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue