From a2f22fcaa3415b90d01ee04574818ec9595275a0 Mon Sep 17 00:00:00 2001 From: Marc Florisson Date: Fri, 14 Dec 2012 11:47:11 +0100 Subject: add api_key management --- app/assets/stylesheets/api_keys.css.scss | 34 ++++++++++++++++++++++++++++++++ app/controllers/api_keys_controller.rb | 17 ++++++++++++++++ app/models/api/v1/api_key.rb | 4 ++++ app/views/api_keys/_api_key.html.erb | 12 +++++++++++ app/views/api_keys/_form.html.erb | 14 +++++++++++++ app/views/api_keys/edit.html.erb | 4 ++++ app/views/api_keys/new.html.erb | 4 ++++ app/views/referentials/show.html.erb | 7 +++++++ 8 files changed, 96 insertions(+) create mode 100644 app/assets/stylesheets/api_keys.css.scss create mode 100644 app/controllers/api_keys_controller.rb create mode 100644 app/views/api_keys/_api_key.html.erb create mode 100644 app/views/api_keys/_form.html.erb create mode 100644 app/views/api_keys/edit.html.erb create mode 100644 app/views/api_keys/new.html.erb (limited to 'app') 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 %> +
+ <%= api_key.class.human_attribute_name('name') %> <%= api_key.name %> - + <%= api_key.class.human_attribute_name('updated_at') %> <%= l(api_key.updated_at) %> +
+ <%= 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" %> +
+
+<% 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 @@ + +

<%= t('.api_keys') %>

+ +
+ <%= render :partial => "api_keys/api_key", :collection => @referential.api_keys %> +
<% content_for :sidebar do %> -- cgit v1.2.3