demarches-normaliennes/app/controllers/api_tokens_controller.rb

51 lines
1 KiB
Ruby
Raw Normal View History

class APITokensController < ApplicationController
before_action :authenticate_administrateur!
2024-01-17 11:02:26 +01:00
before_action :set_api_token, only: [:destroy]
2024-01-17 11:05:56 +01:00
def nom
@name = params[:name]
end
2024-01-17 11:07:48 +01:00
def autorisations
@name = params[:name]
@libelle_id_procedures = current_administrateur
.procedures
.order(:libelle)
.pluck(:libelle, :id)
.map { |libelle, id| ["#{id} - #{libelle}", id] }
end
2024-01-17 11:10:39 +01:00
def securite
end
def create
@api_token, @packed_token = APIToken.generate(current_administrateur)
2023-09-13 12:05:40 +02:00
render :index
end
def destroy
@api_token.destroy
redirect_to profil_path
end
private
def set_api_token
@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, :become_full_access, :disallow_procedure_id, allowed_procedure_ids: [])
end
end