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 %> +