From 1d7b6a6a543eb8220b68c2e03e7f330f7ea12e47 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 17 Jan 2024 11:05:56 +0100 Subject: [PATCH] feature(api): setup name --- app/controllers/api_tokens_controller.rb | 4 ++++ app/views/api_tokens/nom.html.haml | 22 ++++++++++++++++++++++ config/locales/views/api_tokens.fr.yml | 9 +++++++++ config/routes.rb | 6 +++++- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/views/api_tokens/nom.html.haml create mode 100644 config/locales/views/api_tokens.fr.yml diff --git a/app/controllers/api_tokens_controller.rb b/app/controllers/api_tokens_controller.rb index 6746347eb..1da383109 100644 --- a/app/controllers/api_tokens_controller.rb +++ b/app/controllers/api_tokens_controller.rb @@ -2,6 +2,10 @@ class APITokensController < ApplicationController before_action :authenticate_administrateur! before_action :set_api_token, only: [:destroy] + def nom + @name = params[:name] + end + def create @api_token, @packed_token = APIToken.generate(current_administrateur) diff --git a/app/views/api_tokens/nom.html.haml b/app/views/api_tokens/nom.html.haml new file mode 100644 index 000000000..cea1b6428 --- /dev/null +++ b/app/views/api_tokens/nom.html.haml @@ -0,0 +1,22 @@ +- content_for :title, 'Nouveau jeton dʼAPI' + += render partial: 'administrateurs/breadcrumbs', + locals: { steps: [['Tableau de bord', tableau_de_bord_helper_path], + [t('users.profil.show.profile'), profil_path], + [t('api_tokens.nom.new_token')]] } + +.fr-container.fr-mt-2w + %h1= t('.new_token') + = form_with url: autorisations_api_tokens_path, method: :get, html: { class: 'fr-mt-2w' } do |f| + .fr-input-group + = f.label :name, class: 'fr-label' do + = t('.name') + %span.fr-hint-text= t('.name-hint') + = f.text_field :name, class: 'fr-input width-33', autocomplete: 'off', autocapitalize: 'off', autocorrect: 'off', spellcheck: false, required: true, value: @name, autofocus: true + + %ul.fr-btns-group.fr-btns-group--inline + %li + = f.button type: :submit, class: "fr-btn fr-btn--primary" do + = t('.continue') + %li + = link_to t('.cancel'), profil_path, class: "fr-btn fr-btn--secondary" diff --git a/config/locales/views/api_tokens.fr.yml b/config/locales/views/api_tokens.fr.yml new file mode 100644 index 000000000..90323a835 --- /dev/null +++ b/config/locales/views/api_tokens.fr.yml @@ -0,0 +1,9 @@ +--- +fr: + api_tokens: + nom: + new_token: Création d'un nouveau jeton + name: Nom du jeton + name-hint: 'exemples: prod orus, test presta' + continue: continuer + cancel: retour diff --git a/config/routes.rb b/config/routes.rb index cfc2b6515..e1a4f520a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -208,7 +208,11 @@ Rails.application.routes.draw do resources :attachments, only: [:show, :destroy] resources :recherche, only: [:index] - resources :api_tokens, only: [:create, :destroy] + resources :api_tokens, only: [:create, :destroy] do + collection do + get :nom + end + end get "patron" => "root#patron" if Rails.env.development? || Rails.env.test? get "suivi" => "root#suivi"