diff options
| author | Luc Donnet | 2017-09-11 17:27:10 +0200 |
|---|---|---|
| committer | Luc Donnet | 2017-09-11 17:27:10 +0200 |
| commit | 5ee3a180de710d23ceb7660b1bcc454701b42d87 (patch) | |
| tree | c5a6fa4d304306bb53dfcea93037f3ac10b46624 | |
| parent | 1b2976d7a63cc140304bd94b88b5ddc93e0aceb0 (diff) | |
| download | chouette-core-5ee3a180de710d23ceb7660b1bcc454701b42d87.tar.bz2 | |
Fix views and access for api keys generation Refs #4276 @8
| -rw-r--r-- | app/controllers/api_keys_controller.rb | 22 | ||||
| -rw-r--r-- | app/views/api_keys/_api_key.html.slim | 18 | ||||
| -rw-r--r-- | app/views/api_keys/_form.html.slim | 14 | ||||
| -rw-r--r-- | app/views/api_keys/edit.html.slim | 20 | ||||
| -rw-r--r-- | app/views/api_keys/index.html.slim | 27 | ||||
| -rw-r--r-- | app/views/api_keys/new.html.slim | 14 | ||||
| -rw-r--r-- | app/views/api_keys/show.html.slim | 17 | ||||
| -rw-r--r-- | app/views/workbenches/index.html.slim | 20 | ||||
| -rw-r--r-- | config/locales/actions.en.yml | 1 | ||||
| -rw-r--r-- | config/locales/actions.fr.yml | 1 | ||||
| -rw-r--r-- | config/locales/workbenches.fr.yml | 3 | ||||
| -rw-r--r-- | config/routes.rb | 3 | ||||
| -rw-r--r-- | lib/stif/permission_translator.rb | 1 |
13 files changed, 80 insertions, 81 deletions
diff --git a/app/controllers/api_keys_controller.rb b/app/controllers/api_keys_controller.rb index 7059cf52e..03e5ef237 100644 --- a/app/controllers/api_keys_controller.rb +++ b/app/controllers/api_keys_controller.rb @@ -3,19 +3,27 @@ class ApiKeysController < BreadcrumbController def create @api_key = Api::V1::ApiKey.new(api_key_params.merge(organisation: current_organisation)) - create! { organisation_api_keys_path } - end - - def index - @api_keys = decorate_api_keys(current_organisation.api_keys.paginate(page: params[:page])) + create! do |format| + format.html { + redirect_to workbenches_path + } + end end def update - update! { organisation_api_key_path(resource) } + update! do |format| + format.html { + redirect_to workbenches_path + } + end end def destroy - destroy! { organisation_api_keys_path } + destroy! do |format| + format.html { + redirect_to workbenches_path + } + end end private diff --git a/app/views/api_keys/_api_key.html.slim b/app/views/api_keys/_api_key.html.slim deleted file mode 100644 index 4cb07ef83..000000000 --- a/app/views/api_keys/_api_key.html.slim +++ /dev/null @@ -1,18 +0,0 @@ -#index_item.panel.panel-default.api_key - .panel-heading - .panel-title.clearfix - span.pull-right - = link_to edit_referential_api_key_path(@referential, api_key), class: "btn btn-default btn-sm" do - span.fa.fa-pencil - - = link_to referential_api_key_path(@referential, api_key), :method => :delete, :data => {:confirm => t('api_keys.actions.destroy_confirm')}, class: "btn btn-danger btn-sm" do - span.fa.fa-trash-o - - h5 - = link_to([@referential, api_key], class: "preview", :title => "#{Chouette::StopArea.model_name.human.capitalize} #{api_key.name}") do - span.name = truncate(api_key.name, :length => 20) - - .panel-body - p = "#{api_key.class.human_attribute_name('token')} #{truncate(api_key.token, :length => 20)}" - - p = "#{api_key.class.human_attribute_name('updated_at')} #{l(api_key.updated_at)}"
\ No newline at end of file diff --git a/app/views/api_keys/_form.html.slim b/app/views/api_keys/_form.html.slim index f3ebf3fe1..94a3ae57e 100644 --- a/app/views/api_keys/_form.html.slim +++ b/app/views/api_keys/_form.html.slim @@ -1,7 +1,9 @@ -= simple_form_for @api_key, url: action_url do |f| - = f.input :name - - unless @api_key.new_record? - = f.input :token, :input_html => { readonly: true } += simple_form_for @api_key, html: {class: 'form-horizontal', id: 'api_key_form'}, wrapper: :horizontal_form do |f| + .row + .col-lg-12 + = f.input :name + - unless @api_key.new_record? + = f.input :token, :input_html => { readonly: true } - = f.association :referential - = f.button :submit, 'submit', class: 'btn-primary' + / = f.association :referential + = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'api_key_form' diff --git a/app/views/api_keys/edit.html.slim b/app/views/api_keys/edit.html.slim index e47deddf7..b1bd1858d 100644 --- a/app/views/api_keys/edit.html.slim +++ b/app/views/api_keys/edit.html.slim @@ -1,2 +1,18 @@ -= title_tag t('api_keys.edit.title') -== render partial: 'form', locals: {action_url: organisation_api_key_path} +/ PageHeader += pageheader 'Clé d\'API', + t('api_keys.edit.title'), + 'Lorem ipsum dolor sit amet', + t('last_update', time: l(@api_key.updated_at, format: :short)), + '' + + / Below is secundary actions & optional contents (filters, ...) + .row.mb-sm + .col-lg-12.text-right + = ( policy(@api_key).destroy? ? link_to(t('actions.destroy'), api_key_path(@api_key), :method => :delete, class: 'btn btn-default') : '' ) + +/ PageContent +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + == render 'form' diff --git a/app/views/api_keys/index.html.slim b/app/views/api_keys/index.html.slim deleted file mode 100644 index 9757b8955..000000000 --- a/app/views/api_keys/index.html.slim +++ /dev/null @@ -1,27 +0,0 @@ -- header_params = ['map-marker', - t('.title'), - ''] -- header_params << link_to(t('actions.add'), new_organisation_api_key_path, class: 'btn btn-default') if policy(Api::V1::ApiKey).create? -= pageheader(*header_params) do - - -- if @api_keys.any? - .row - .col-lg-12 - = table_builder_2 @api_keys, - [ \ - TableBuilderHelper::Column.new( \ - key: :name, \ - attribute: 'name', \ - link_to: lambda do |api_key| \ - organisation_api_key_path(api_key) \ - end \ - ), \ - TableBuilderHelper::Column.new( \ - key: :token, \ - attribute: 'token' \ - ), \ - ], - cls: 'table has-search' - - = new_pagination @api_keys, 'pull-right' diff --git a/app/views/api_keys/new.html.slim b/app/views/api_keys/new.html.slim index 291c9f8a6..9acb08a94 100644 --- a/app/views/api_keys/new.html.slim +++ b/app/views/api_keys/new.html.slim @@ -1,2 +1,12 @@ -= title_tag t('api_keys.new.title') -== render partial: 'form', locals: {action_url: organisation_api_keys_path} +/ PageHeader += pageheader 'Clé d\'API', + t('api_keys.new.title'), + 'Lorem ipsum dolor sit amet', + '' + +/ PageContent +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + == render 'form' diff --git a/app/views/api_keys/show.html.slim b/app/views/api_keys/show.html.slim deleted file mode 100644 index de30ac125..000000000 --- a/app/views/api_keys/show.html.slim +++ /dev/null @@ -1,17 +0,0 @@ -= title_tag t('api_keys.show.title') - -.api_keys_show - .summary - p - label = "#{@api_key.class.human_attribute_name('name')} : " - = @api_key.name - - p - label = "#{@api_key.class.human_attribute_name('token')} : " - = @api_key.token - -- content_for :sidebar do - ul.actions - li = link_to t('api_keys.actions.edit'), edit_organisation_api_key_path(@api_key), class: "edit" - li = link_to t('api_keys.actions.destroy'), organisation_api_key_path(@api_key), :method => :delete, :data => {:confirm => t('api_keys.actions.destroy_confirm')}, class: "remove" - br diff --git a/app/views/workbenches/index.html.slim b/app/views/workbenches/index.html.slim index eece51bca..2ea1f0fe4 100644 --- a/app/views/workbenches/index.html.slim +++ b/app/views/workbenches/index.html.slim @@ -2,6 +2,13 @@ = pageheader 'tableau-de-bord', t('.title', organisation: current_organisation.name) + / Below is secundary actions & optional contents (filters, ...) + .row.mb-sm + .col-lg-12.text-right + - if policy(Api::V1::ApiKey).create? + = link_to t('actions.create_api_key'), new_api_key_path, class: 'btn btn-primary' + + / PageContent .page_content .container-fluid @@ -27,6 +34,19 @@ .panel-body em.small.text-muted = t('.offers.no_content') + .panel.panel-default + .panel-heading + h3.panel-title + = t('.offers.api_keys') + span.badge.ml-xs = current_organisation.api_keys.count if current_organisation.api_keys.any? + - if current_organisation.api_keys.any? + - current_organisation.api_keys.each do |api_key| + .list-group + = policy(api_key).edit? ? link_to( "#{api_key.name} : #{api_key.token}", edit_api_key_path(api_key), class: 'list-group-item') : "#{api_key.name} : #{api_key.token}" + - else + .panel-body + em.small.text-muted = t('.offers.no_content') + .col-lg-6.col-md-6.col-sm-6.col-xs-12 .panel.panel-default .panel-heading diff --git a/config/locales/actions.en.yml b/config/locales/actions.en.yml index 36b76d01c..8dea51ca3 100644 --- a/config/locales/actions.en.yml +++ b/config/locales/actions.en.yml @@ -19,6 +19,7 @@ en: import: 'Import' filter: 'Filter' erase: 'Erase' + create_api_key: "Create an API key" or: "or" cancel: "Cancel" search_hint: "Type in a search term" diff --git a/config/locales/actions.fr.yml b/config/locales/actions.fr.yml index f581142c7..01fc06326 100644 --- a/config/locales/actions.fr.yml +++ b/config/locales/actions.fr.yml @@ -19,6 +19,7 @@ fr: import: 'Importer' filter: 'Filtrer' erase: 'Effacer' + create_api_key: "Créer une clé d'API" or: "ou" cancel: "Annuler" search_hint: "Entrez un texte à rechercher" diff --git a/config/locales/workbenches.fr.yml b/config/locales/workbenches.fr.yml index 85c5259b8..559593492 100644 --- a/config/locales/workbenches.fr.yml +++ b/config/locales/workbenches.fr.yml @@ -6,6 +6,7 @@ fr: title: "Offres de transport" organisation: "Offres de mon organisation" idf: "Offres IDF" + api_keys: "Clés d'API" referentials: "Jeux de données" calendars: "Calendriers" see: "Voir la liste" @@ -13,4 +14,4 @@ fr: referential_count: zero: "Aucun jeu de données à l'heure actuelle" one: "1 jeu de données à l'heure actuelle" - other: "#{count} jeux de données à l'heure actuelle" + other: "#{count} jeux de données à l'heure actuelle" diff --git a/config/routes.rb b/config/routes.rb index fa892c908..4fcd649a7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -63,11 +63,12 @@ ChouetteIhm::Application.routes.draw do end resource :organisation, :only => [:show, :edit, :update] do - resources :api_keys resources :users resources :rule_parameter_sets end + resources :api_keys, :only => [:edit, :update, :new, :create, :destroy] + resources :stop_area_referentials, :only => [:show] do post :sync, on: :member resources :stop_areas diff --git a/lib/stif/permission_translator.rb b/lib/stif/permission_translator.rb index afe69756e..47ab2840f 100644 --- a/lib/stif/permission_translator.rb +++ b/lib/stif/permission_translator.rb @@ -23,6 +23,7 @@ module Stif referentials routes routing_constraint_zones time_tables vehicle_journeys + api_keys ] end |
