aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/api_keys_controller.rb32
-rw-r--r--app/decorators/api_key_decorator.rb30
-rw-r--r--app/views/api_keys/edit.html.slim3
-rw-r--r--app/views/api_keys/index.html.slim24
-rw-r--r--app/views/api_keys/new.html.slim3
-rw-r--r--app/views/api_keys/show.html.slim7
-rw-r--r--config/locales/api_keys.en.yml6
-rw-r--r--config/locales/api_keys.fr.yml2
-rw-r--r--config/routes.rb2
9 files changed, 87 insertions, 22 deletions
diff --git a/app/controllers/api_keys_controller.rb b/app/controllers/api_keys_controller.rb
index 35a84da87..bd225818b 100644
--- a/app/controllers/api_keys_controller.rb
+++ b/app/controllers/api_keys_controller.rb
@@ -1,22 +1,32 @@
-class ApiKeysController < ChouetteController
- defaults :resource_class => Api::V1::ApiKey
-
- belongs_to :referential
+class ApiKeysController < BreadcrumbController
+ defaults resource_class: Api::V1::ApiKey
def create
- create! { referential_path(@referential) }
+ @api_key = Api::V1::ApiKey.new(api_key_params.merge(organisation: current_organisation))
+ create! { organisation_api_key_path(resource) }
+ end
+
+ def index
+ @api_keys = decorate_api_keys(current_organisation.api_keys.paginate(page: params[:page]))
end
+
def update
- update! { referential_path(@referential) }
+ update! { organisation_api_key_path(resource) }
end
+
def destroy
- destroy! { referential_path(@referential) }
+ destroy! { organisation_api_keys_path }
end
private
def api_key_params
- params.require(:api_key).permit( :name )
- end
-
-end
+ params.require(:api_key).permit(:name, :referential_id)
+ end
+ def decorate_api_keys(api_keys)
+ ModelDecorator.decorate(
+ api_keys,
+ with: ApiKeyDecorator,
+ )
+ end
+end
diff --git a/app/decorators/api_key_decorator.rb b/app/decorators/api_key_decorator.rb
new file mode 100644
index 000000000..def3a6a01
--- /dev/null
+++ b/app/decorators/api_key_decorator.rb
@@ -0,0 +1,30 @@
+class ApiKeyDecorator < Draper::Decorator
+ decorates Api::V1::ApiKey
+ delegate_all
+
+
+ def action_links
+ links = []
+
+ links << Link.new(
+ content: h.t('api_keys.actions.show'),
+ href: h.organisation_api_key_path(object),
+ )
+
+ links << Link.new(
+ content: h.t('api_keys.actions.edit'),
+ href: h.edit_organisation_api_key_path(object),
+ )
+
+ if h.policy(object).destroy?
+ links << Link.new(
+ content: h.destroy_link_content,
+ href: h.organisation_api_key_path(object),
+ method: :delete,
+ data: { confirm: h.t('api_keys.actions.destroy_confirm') }
+ )
+ end
+
+ links
+ end
+end
diff --git a/app/views/api_keys/edit.html.slim b/app/views/api_keys/edit.html.slim
index 110f0775d..e47deddf7 100644
--- a/app/views/api_keys/edit.html.slim
+++ b/app/views/api_keys/edit.html.slim
@@ -1,3 +1,2 @@
= title_tag t('api_keys.edit.title')
-
-== render 'form' \ No newline at end of file
+== render partial: 'form', locals: {action_url: organisation_api_key_path}
diff --git a/app/views/api_keys/index.html.slim b/app/views/api_keys/index.html.slim
new file mode 100644
index 000000000..fc8d95c7a
--- /dev/null
+++ b/app/views/api_keys/index.html.slim
@@ -0,0 +1,24 @@
+- 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' \
+ ), \
+ 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 f7b1dd99b..291c9f8a6 100644
--- a/app/views/api_keys/new.html.slim
+++ b/app/views/api_keys/new.html.slim
@@ -1,3 +1,2 @@
= title_tag t('api_keys.new.title')
-
-== render "form" \ No newline at end of file
+== render partial: 'form', locals: {action_url: organisation_api_keys_path}
diff --git a/app/views/api_keys/show.html.slim b/app/views/api_keys/show.html.slim
index b65717408..de30ac125 100644
--- a/app/views/api_keys/show.html.slim
+++ b/app/views/api_keys/show.html.slim
@@ -12,7 +12,6 @@
- content_for :sidebar do
ul.actions
- li = link_to t('api_keys.actions.new'), new_referential_api_key_path(@referential), class: "add"
- li = link_to t('api_keys.actions.edit'), edit_referential_api_key_path(@referential, @api_key), class: "edit"
- li = link_to t('api_keys.actions.destroy'), referential_api_key_path(@referential, @api_key), :method => :delete, :data => {:confirm => t('api_keys.actions.destroy_confirm')}, class: "remove"
- br \ No newline at end of file
+ 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/config/locales/api_keys.en.yml b/config/locales/api_keys.en.yml
index 221fa6eef..1480c8e55 100644
--- a/config/locales/api_keys.en.yml
+++ b/config/locales/api_keys.en.yml
@@ -7,12 +7,14 @@ en:
destroy_confirm: "Are you sure you want destroy this api key?"
show:
title: "Api key"
+ index:
+ title: Api key
new:
title: "Add a new api key"
edit:
title: "Update api key"
- activerecord:
- models:
+ activerecord:
+ models:
api_key: "Api Key"
attributes:
api_key:
diff --git a/config/locales/api_keys.fr.yml b/config/locales/api_keys.fr.yml
index 445367c72..20af91a49 100644
--- a/config/locales/api_keys.fr.yml
+++ b/config/locales/api_keys.fr.yml
@@ -7,6 +7,8 @@ fr:
destroy_confirm: "Etes vous sûr de vouloir détruire la clé d'accès API ?"
show:
title: "Clé d'accès API"
+ index:
+ title: Clé d'accès API
new:
title: "Ajouter une clé d'accès API"
edit:
diff --git a/config/routes.rb b/config/routes.rb
index 0ed401cf5..ea0eefd06 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -56,6 +56,7 @@ ChouetteIhm::Application.routes.draw do
end
resource :organisation, :only => [:show, :edit, :update] do
+ resources :api_keys
resources :users
resources :rule_parameter_sets
end
@@ -78,7 +79,6 @@ ChouetteIhm::Application.routes.draw do
end
resources :referentials, except: :index do
- resources :api_keys
resources :autocomplete_stop_areas, only: [:show, :index] do
get 'around', on: :member
end