aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/assets/stylesheets/api_keys.css.scss34
-rw-r--r--app/controllers/api_keys_controller.rb17
-rw-r--r--app/models/api/v1/api_key.rb4
-rw-r--r--app/views/api_keys/_api_key.html.erb12
-rw-r--r--app/views/api_keys/_form.html.erb14
-rw-r--r--app/views/api_keys/edit.html.erb4
-rw-r--r--app/views/api_keys/new.html.erb4
-rw-r--r--app/views/referentials/show.html.erb7
-rw-r--r--config/initializers/apartment.rb2
-rw-r--r--config/locales/api_keys.yml32
-rw-r--r--config/routes.rb1
11 files changed, 129 insertions, 2 deletions
diff --git a/app/assets/stylesheets/api_keys.css.scss b/app/assets/stylesheets/api_keys.css.scss
new file mode 100644
index 000000000..cca96321e
--- /dev/null
+++ b/app/assets/stylesheets/api_keys.css.scss
@@ -0,0 +1,34 @@
+// Place all the styles related to the routes controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+@import "common";
+
+#workspace.referentials.show
+{
+ .api_key:after {
+ @include after_div_for_object;
+ }
+
+ .api_keys {
+ margin-top: 20px;
+ }
+
+ .api_keys:after {
+ @include content_to_clear;
+ }
+
+ .api_key {
+ @include div_for_object;
+
+ /* to create multi-column index */
+ width: 350px;
+ padding-right: 10px;
+
+ .name {
+ line-height: 16px;
+ float: left;
+ }
+
+ }
+}
+
diff --git a/app/controllers/api_keys_controller.rb b/app/controllers/api_keys_controller.rb
new file mode 100644
index 000000000..fea8f66b3
--- /dev/null
+++ b/app/controllers/api_keys_controller.rb
@@ -0,0 +1,17 @@
+class ApiKeysController < ChouetteController
+ defaults :resource_class => Api::V1::ApiKey
+
+ belongs_to :referential
+
+ def create
+ create! { referential_path(@referential) }
+ end
+ def update
+ update! { referential_path(@referential) }
+ end
+ def destroy
+ destroy! { referential_path(@referential) }
+ end
+
+end
+
diff --git a/app/models/api/v1/api_key.rb b/app/models/api/v1/api_key.rb
index 40719127a..2c1b9ba5f 100644
--- a/app/models/api/v1/api_key.rb
+++ b/app/models/api/v1/api_key.rb
@@ -4,6 +4,10 @@ module Api
before_create :generate_access_token
belongs_to :referential, :class_name => '::Referential'
+ def self.model_name
+ ActiveModel::Name.new self, Api::V1, self.name.demodulize
+ end
+
def eql?(other)
other.token == self.token
end
diff --git a/app/views/api_keys/_api_key.html.erb b/app/views/api_keys/_api_key.html.erb
new file mode 100644
index 000000000..6492af3b0
--- /dev/null
+++ b/app/views/api_keys/_api_key.html.erb
@@ -0,0 +1,12 @@
+<%= div_for(api_key) do %>
+ <%= api_key.token %>
+ <div class="info">
+ <%= api_key.class.human_attribute_name('name') %> <%= api_key.name %> -
+ <%= api_key.class.human_attribute_name('updated_at') %> <%= l(api_key.updated_at) %>
+ <div class="actions">
+ <%= link_to t("actions.edit"), edit_referential_api_key_path(@referential, api_key), :class => "edit" %> |
+ <%= link_to t("actions.destroy"), referential_api_key_path(@referential, api_key), :method => :delete, :data => {:confirm => t('api_keys.actions.destroy_confirm')}, :class => "remove" %>
+ </div>
+ </div>
+<% end %>
+
diff --git a/app/views/api_keys/_form.html.erb b/app/views/api_keys/_form.html.erb
new file mode 100644
index 000000000..de3f9ad7e
--- /dev/null
+++ b/app/views/api_keys/_form.html.erb
@@ -0,0 +1,14 @@
+<%= semantic_form_for [@referential, @api_key] do |form| %>
+ <%= form.inputs do %>
+ <%= form.input :name %>
+ <% unless @api_key.new_record? %>
+ <%= form.input :token, :input_html => { :disabled => true } %>
+ <% end %>
+ <% end %>
+
+ <%= form.actions do %>
+ <%= form.action :submit, :as => :button %>
+ <%= form.action :cancel, :as => :link %>
+ <% end %>
+<% end %>
+
diff --git a/app/views/api_keys/edit.html.erb b/app/views/api_keys/edit.html.erb
new file mode 100644
index 000000000..7d367421e
--- /dev/null
+++ b/app/views/api_keys/edit.html.erb
@@ -0,0 +1,4 @@
+<%= title_tag t('api_keys.edit.title') %>
+
+<%= render "form" %>
+
diff --git a/app/views/api_keys/new.html.erb b/app/views/api_keys/new.html.erb
new file mode 100644
index 000000000..40dd1a4fe
--- /dev/null
+++ b/app/views/api_keys/new.html.erb
@@ -0,0 +1,4 @@
+<%= title_tag t('api_keys.new.title') %>
+
+<%= render "form" %>
+
diff --git a/app/views/referentials/show.html.erb b/app/views/referentials/show.html.erb
index 64df439a0..d8e5dd8df 100644
--- a/app/views/referentials/show.html.erb
+++ b/app/views/referentials/show.html.erb
@@ -39,12 +39,19 @@
</td>
</tr>
</table>
+
+<h3 class="api_keys"><%= t('.api_keys') %></h3>
+
+<div class="api_keys">
+ <%= render :partial => "api_keys/api_key", :collection => @referential.api_keys %>
+</div>
</div>
<% content_for :sidebar do %>
<ul class="actions">
<li><%= link_to t('referentials.actions.edit'), edit_referential_path(@referential), :class => "edit" %></li>
<li><%= link_to t('referentials.actions.destroy'), referential_path(@referential), :method => :delete, :data => {:confirm => t('referentials.actions.destroy_confirm')}, :class => "remove" %></li>
+ <li><%= link_to t('api_keys.actions.new'), new_referential_api_key_path(@referential), :class => "add" %></li>
<br>
</ul>
diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb
index bff88d5fc..4bc95f829 100644
--- a/config/initializers/apartment.rb
+++ b/config/initializers/apartment.rb
@@ -1,6 +1,6 @@
Apartment.configure do |config|
# set your options (described below) here
- config.excluded_models = ["Referential", "Organisation", "User", "Import", "ImportLogMessage", "Export", "ExportLogMessage", "Delayed::Backend::ActiveRecord::Job"] # these models will not be multi-tenanted, but remain in the global (public) namespace
+ config.excluded_models = ["Referential", "Organisation", "User", "Import", "ImportLogMessage", "Export", "ExportLogMessage", "Delayed::Backend::ActiveRecord::Job", "Api::V1::ApiKey"] # these models will not be multi-tenanted, but remain in the global (public) namespace
# Dynamically get database names to migrate
config.database_names = lambda{ Referential.pluck(:slug) }
diff --git a/config/locales/api_keys.yml b/config/locales/api_keys.yml
new file mode 100644
index 000000000..1cbb90867
--- /dev/null
+++ b/config/locales/api_keys.yml
@@ -0,0 +1,32 @@
+en:
+ api_keys:
+ actions:
+ new: Add a new api key
+ edit: Edit this api key
+ destroy: Remove this api key
+ destroy_confirm: Are you sure you want destroy this api key?
+ new:
+ title: Add a new api key
+ edit:
+ title: Update api key
+ activerecord:
+ models:
+ api_key: Api Key
+fr:
+ api_keys:
+ actions:
+ new: "Ajouter une clé d'accès API"
+ edit: "Modifier la clé d'accès API"
+ destroy: "Supprimer la clé d'accès API"
+ destroy_confirm: "Etes vous sûr de vouloir détruire la clé d'accès API ?"
+ new:
+ title: "Ajouter une clé d'accès API"
+ edit:
+ title: "Modifier la clé d'accès API"
+ activerecord:
+ models:
+ api_key: "Clé d'accès API"
+ attributes:
+ api_key:
+ name: Nom
+
diff --git a/config/routes.rb b/config/routes.rb
index a512a68dc..d2eabf7c5 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -36,7 +36,6 @@ ChouetteIhm::Application.routes.draw do
resources :file_validations
resources :referentials do
- resources :keys
resources :api_keys
resources :stop_point_areas
match 'lines' => 'lines#destroy_all', :via => :delete