iam 0.1.12 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -31,7 +31,7 @@ Also you may log in using user_id (e.g. 42):
31
31
  Add gem to your gemfile:
32
32
 
33
33
  ```ruby
34
- gem 'iam', '~> 0.1.12'
34
+ gem 'iam', '~> 0.2.1'
35
35
  ```
36
36
  ##Configuration
37
37
 
@@ -41,7 +41,7 @@ Generate configuration file:
41
41
  rails g iam:initializer
42
42
  ```
43
43
 
44
- All major configuration params available are described there.
44
+ All configuration params available are self descriptive enough.
45
45
 
46
46
  Also each developer can configure control keys (alt ctrl shift) to make up iam-menu show/hide combination.
47
47
  These configurations are saved into cookies and you may forget these settings after first customization.
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'bundler/gem_tasks'
3
2
  require 'rake/testtask'
4
3
 
@@ -12,7 +11,7 @@ Rake::TestTask.new(:test) do |t|
12
11
  t.verbose = true
13
12
  end
14
13
 
15
- desc 'Precompile vendor assets'
14
+ desc 'Precompile assets'
16
15
  task :precompile do |t|
17
16
  precompile_sass
18
17
  precompile_coffee
@@ -20,14 +19,14 @@ task :precompile do |t|
20
19
  end
21
20
 
22
21
  def precompile_sass
23
- Dir[File.join('vendor', 'assets', 'stylesheets', '*.sass')].each do |file|
22
+ Dir[File.join('app', 'assets', 'stylesheets', '*.sass')].each do |file|
24
23
  system "sass #{file} > #{file.gsub('.sass', '')}"
25
24
  p "File #{file} precompiled"
26
25
  end
27
26
  end
28
27
 
29
28
  def precompile_coffee
30
- Dir[File.join('vendor', 'assets', 'javascripts', '*.coffee')].each do |file|
29
+ Dir[File.join('app', 'assets', 'javascripts', '*.coffee')].each do |file|
31
30
  system "coffee -c #{file}"
32
31
  p "File #{file} precompiled"
33
32
  end
@@ -36,7 +35,7 @@ end
36
35
  def uglify_js
37
36
  require 'uglifier'
38
37
 
39
- Dir[File.join('vendor', 'assets', 'javascripts', '*.js')].each do |file|
38
+ Dir[File.join('app', 'assets', 'javascripts', '*.js')].each do |file|
40
39
  javascript = File.read(file)
41
40
  File.open(file, 'w') { |f| f << Uglifier.compile(javascript) }
42
41
  p "File #{file} uglified"
@@ -1,5 +1,5 @@
1
1
  $ ->
2
- templateLink = '/iam/log_in_as/:id'
2
+ templateLink = '/iam/log_in/:id'
3
3
  menuLink = '/iam/menu'
4
4
  inputMode = false # account id is anticipated to be typed
5
5
  input = '' # typed string
@@ -0,0 +1,2 @@
1
+ // Generated by CoffeeScript 1.3.3
2
+ (function(){$(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h;return h="/iam/log_in/:id",l="/iam/menu",s=!1,i="",e=["alt","ctrl","shift"],r=function(){return $(".iam-settings-header").on("click",function(){return $(".iam-settings").toggle()}),$("#iam-menu").on("click","td",function(){var e,t;e=$(this).parents("tr"),t=e.attr("href");if(t)return f(t)}),$.each(e,function(){var e,t;return e=$(".iam-"+this+"-settings input"),t="iam-"+this+"-checked",e[0].checked=$.cookie(t)==="true",e.on("click",function(){return $.cookie(t,this.checked)})})},n=function(e){var t;return t=$("<div class='iam-notice'>"+e+"</div>"),$("body").append(t),t.fadeIn(200).delay(1e3).fadeOut(600)},f=function(e){return $.post(e,function(e){return window.location.reload(),n(e.notice)})},u=function(e){return String.fromCharCode(e)==="À"},t=function(t){var n,r,i,s;for(i=0,s=e.length;i<s;i++){n=e[i],r=$.cookie("iam-"+n+"-checked")==="true";if(r!==t[""+n+"Key"])return!1}return!0},o=function(){return $(document.getSelection().focusNode).find("input, textarea").length>0},c=function(e){var t;if(e.match(/^\d+$/))return t=h.replace(/:id/,e),f(t);if(e)return n(""+e+" is invalid id.")},a=function(){return s?c(i):$.get(l,function(e){return $("body").append(e),r()}),i=""},$(document).on("keydown",function(e){var n;if(!o()&&u(e.keyCode)&&t(e))return a(),s=!s,$("#iam-menu").remove();if(48<=(n=e.keyCode)&&n<=57)return i+=String.fromCharCode(e.keyCode)})})}).call(this);
@@ -1,28 +1,21 @@
1
1
  class IamController < ApplicationController
2
+ include IamHelper
3
+ include Iam::AuthorizationProvider::Factory.current_provider
4
+
2
5
  layout false
3
6
 
4
- def menu
5
- @account_samples = account_samples
6
- end
7
+ def menu; end
7
8
 
8
- def log_in_as
9
+ def log_in
9
10
  return if Rails.env == 'production'
10
11
 
11
- account = Iam::Configuration.account_class.constantize.find(params[:id])
12
- sign_in Iam::Configuration.account_class.downcase, account
12
+ log_in_account account
13
13
 
14
- name = Iam::Configuration.account_attributes.map{ |key| account.public_send(key)}.join(' ')
15
- render json: { notice: I18n.t('iam.success', name: name) }
14
+ render json: { notice: I18n.t('iam.success', name: account_name(account)) }
16
15
  end
17
16
 
18
17
  private
19
- def account_samples
20
- role_class = Iam::Configuration.role_class.constantize
21
- account_class = Iam::Configuration.account_class.constantize
22
-
23
- role_class.all.inject({}) do |account_groups, role|
24
- account_group = account_class.where(role_class.to_s.foreign_key => role.id).order(:id).limit(Iam::Configuration.accounts_for_each_role)
25
- account_groups.merge role => account_group
26
- end
18
+ def account
19
+ Iam::Configuration[:account][:class].constantize.find(params[:id])
27
20
  end
28
21
  end
@@ -0,0 +1,25 @@
1
+ module IamHelper
2
+ include Iam::AuthorizationProvider::Factory.current_provider
3
+
4
+ [:account, :role].each do |type|
5
+ define_method "#{type}_name" do |instance|
6
+ extract_attributes(instance, type).join ' '
7
+ end
8
+ end
9
+
10
+ def extract_attributes(instance, type)
11
+ Iam::Configuration[type][:attributes].map do |attribute|
12
+ instance.public_send attribute
13
+ end
14
+ end
15
+
16
+ def account_samples
17
+ role_class = Iam::Configuration[:role][:class].constantize
18
+ account_class = Iam::Configuration[:account][:class].constantize
19
+
20
+ role_class.all.inject({}) do |account_groups, role|
21
+ account_group = account_class.where(role_class.to_s.foreign_key => role.id).order(:id).limit(Iam::Configuration[:accounts_for_each_role])
22
+ account_groups.merge role => account_group
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
- <tr id='<%='iam-current-account' if account == current_user%>' href='<%= log_in_as_path(account) %>'>
2
- <%= render partial: 'iam/account_attribute', collection: Iam::Configuration.account_attributes.map { |key| [key, account.public_send(key)] } %>
1
+ <tr id='<%= 'iam-current-account' if current_account?(account) %>' href='<%= log_in_path(account) %>'>
2
+ <%= render partial: 'iam/account_attribute', collection: extract_attributes(account, :account) %>
3
3
  </tr>
@@ -1,5 +1,3 @@
1
- <% key, value = account_attribute %>
2
-
3
- <td class="attribute <%= key %>-attribute">
4
- <%= value %>
1
+ <td class="attribute">
2
+ <%= account_attribute %>
5
3
  </td>
@@ -1,8 +1,8 @@
1
1
  <% role, accounts = account_group %>
2
2
 
3
3
  <tr>
4
- <td class='role-name' colspan=<%= Iam::Configuration.account_attributes.count %>>
5
- <%= role.public_send Iam::Configuration.role_name_attribute %>
4
+ <td class='role-name' colspan=<%= Iam::Configuration[:account][:attributes].count %>>
5
+ <%= role_name role %>
6
6
  </td>
7
7
  </tr>
8
8
 
@@ -1,11 +1,11 @@
1
1
  <tr>
2
- <td class='iam-settings-header' colspan=<%= Iam::Configuration.account_attributes.count %>>
2
+ <td class='iam-settings-header' colspan=<%= Iam::Configuration[:account][:attributes].count %>>
3
3
  <%= t 'iam.settings' %>
4
4
  </td>
5
5
  </tr>
6
6
 
7
7
  <tr>
8
- <td class='iam-settings' colspan=<%= Iam::Configuration.account_attributes.count %>>
8
+ <td class='iam-settings' colspan=<%= Iam::Configuration[:account][:attributes].count %>>
9
9
  <%= render partial: 'iam/key_setting', collection: %w{alt ctrl shift} %>
10
10
  </td>
11
11
  </tr>
@@ -1,4 +1,4 @@
1
1
  <table id='iam-menu'>
2
- <%= render partial: 'iam/account_group', collection: @account_samples.to_a %>
2
+ <%= render partial: 'iam/account_group', collection: account_samples.to_a %>
3
3
  <%= render partial: 'iam/settings' %>
4
4
  </table>
@@ -1,4 +1,4 @@
1
1
  Rails.application.routes.draw do
2
- post 'iam/log_in_as/:id' => 'iam#log_in_as', as: :log_in_as
2
+ post 'iam/log_in/:id' => 'iam#log_in', as: :log_in
3
3
  get 'iam/menu' => 'iam#menu', as: :iam_menu
4
4
  end
@@ -1,14 +1,12 @@
1
1
  module Iam
2
2
  module Generators
3
3
  class InitializerGenerator < ::Rails::Generators::Base
4
-
5
4
  source_root File.expand_path("../../templates", __FILE__)
6
5
 
7
- desc 'Creates a sample Iam initializer.'
6
+ desc 'Creates a sample Iam configuration.'
8
7
  def copy_initializer
9
- copy_file 'iam.rb', 'config/initializers/iam.rb'
8
+ copy_file 'iam.yml', 'config/iam.yml'
10
9
  end
11
-
12
10
  end
13
11
  end
14
12
  end
@@ -0,0 +1,16 @@
1
+ :accounts_for_each_role: 3
2
+ :authorization_provider: devise
3
+
4
+ :exclude_environments:
5
+ - production
6
+
7
+ :account:
8
+ :class: User
9
+ :attributes:
10
+ - id
11
+ - full_name
12
+
13
+ :role:
14
+ :class: Role
15
+ :attributes:
16
+ - name
data/lib/iam.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'rack'
2
2
 
3
- require 'iam/configuration'
4
- require 'iam/engine'
5
3
  require 'iam/version'
4
+ require 'iam/configuration'
5
+ require 'iam/engine' if defined?(Rails::Engine)
6
+
7
+ require 'iam/authorization_provider/factory'
8
+
6
9
  require 'rack/assets_middleware'
@@ -0,0 +1,13 @@
1
+ module Iam
2
+ module AuthorizationProvider
3
+ module Devise
4
+ def log_in_account(account)
5
+ sign_in Iam::Configuration[:account][:class].downcase, account
6
+ end
7
+
8
+ def current_account?(account)
9
+ current_user == account
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require 'iam/authorization_provider/devise'
2
+
3
+ module Iam
4
+ module AuthorizationProvider
5
+ module Factory
6
+ class << self
7
+ def current_provider
8
+ provider Iam::Configuration[:authorization_provider]
9
+ end
10
+
11
+ def provider(provider_name)
12
+ "Iam::AuthorizationProvider::#{provider_name.camelize}".constantize
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,22 +1,11 @@
1
1
  module Iam
2
2
  module Configuration
3
- def self.configure
4
- yield self
5
- end
6
-
7
- mattr_accessor :account_class
8
- @@account_class = 'User'
9
-
10
- mattr_accessor :account_attributes
11
- @@account_attributes = ['id', 'full_name']
3
+ class << self
4
+ def config
5
+ @configuration ||= YAML.load(File.read 'config/iam.yml')
6
+ end
12
7
 
13
- mattr_accessor :role_class
14
- @@role_class = 'Role'
15
-
16
- mattr_accessor :role_name_attribute
17
- @@role_name_attribute = 'name'
18
-
19
- mattr_accessor :accounts_for_each_role
20
- @@accounts_for_each_role = 3
8
+ delegate :[], to: :config
9
+ end
21
10
  end
22
11
  end
@@ -1,4 +1,11 @@
1
1
  module Iam
2
- class Engine < ::Rails::Engine
2
+ class Engine < Rails::Engine
3
+ initializer 'iam.assets.precompile' do |app|
4
+ app.config.assets.precompile += %w(jquery.cookie.js iam.js iam.css)
5
+ end
6
+
7
+ initializer 'iam.assets.add_middleware' do |app|
8
+ app.middleware.use Rack::Assets unless Rails.env.production?
9
+ end
3
10
  end
4
11
  end
@@ -1,3 +1,3 @@
1
1
  module Iam
2
- VERSION = '0.1.12'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -1,5 +1,2 @@
1
- # encoding: utf-8
2
1
  require 'rack/asset_helpers'
3
2
  require 'rack/assets'
4
-
5
- require 'rack/railtie' if defined?(Rails::Railtie)
@@ -0,0 +1,16 @@
1
+ :accounts_for_each_role: 3
2
+ :authorization_provider: devise
3
+
4
+ :exclude_environments:
5
+ - production
6
+
7
+ :account:
8
+ :class: User
9
+ :attributes:
10
+ - id
11
+ - full_name
12
+
13
+ :role:
14
+ :class: Role
15
+ :attributes:
16
+ - name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-13 00:00:00.000000000 Z
12
+ date: 2012-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -198,7 +198,13 @@ files:
198
198
  - Gemfile
199
199
  - README.md
200
200
  - Rakefile
201
+ - app/assets/javascripts/iam.coffee
202
+ - app/assets/javascripts/iam.js
203
+ - app/assets/javascripts/jquery.cookie.js
204
+ - app/assets/stylesheets/iam.css
205
+ - app/assets/stylesheets/iam.css.sass
201
206
  - app/controllers/iam_controller.rb
207
+ - app/helpers/iam_helper.rb
202
208
  - app/views/iam/_account.html.erb
203
209
  - app/views/iam/_account_attribute.html.erb
204
210
  - app/views/iam/_account_group.html.erb
@@ -209,15 +215,16 @@ files:
209
215
  - config/routes.rb
210
216
  - iam.gemspec
211
217
  - lib/generators/iam/initializer_generator.rb
212
- - lib/generators/templates/iam.rb
218
+ - lib/generators/templates/iam.yml
213
219
  - lib/iam.rb
220
+ - lib/iam/authorization_provider/devise.rb
221
+ - lib/iam/authorization_provider/factory.rb
214
222
  - lib/iam/configuration.rb
215
223
  - lib/iam/engine.rb
216
224
  - lib/iam/version.rb
217
225
  - lib/rack/asset_helpers.rb
218
226
  - lib/rack/assets.rb
219
227
  - lib/rack/assets_middleware.rb
220
- - lib/rack/railtie.rb
221
228
  - spec/rails_app/.gitignore
222
229
  - spec/rails_app/Rakefile
223
230
  - spec/rails_app/app/assets/images/rails.png
@@ -240,6 +247,7 @@ files:
240
247
  - spec/rails_app/config/environments/development.rb
241
248
  - spec/rails_app/config/environments/production.rb
242
249
  - spec/rails_app/config/environments/test.rb
250
+ - spec/rails_app/config/iam.yml
243
251
  - spec/rails_app/config/initializers/backtrace_silencers.rb
244
252
  - spec/rails_app/config/initializers/devise.rb
245
253
  - spec/rails_app/config/initializers/inflections.rb
@@ -265,12 +273,6 @@ files:
265
273
  - spec/rails_app/script/rails
266
274
  - spec/spec_helper.rb
267
275
  - spec/support/database_cleaner.rb
268
- - vendor/assets/javascripts/iam.js.coffee
269
- - vendor/assets/javascripts/iam.js.js
270
- - vendor/assets/javascripts/jquery.cookie.js
271
- - vendor/assets/stylesheets/.sass-cache/99c7326b15538dc9b4651af91a5f076fe779d5ec/iam.css.sassc
272
- - vendor/assets/stylesheets/iam.css
273
- - vendor/assets/stylesheets/iam.css.sass
274
276
  homepage: http://github.com/FUT/iam
275
277
  licenses:
276
278
  - MIT
@@ -1,18 +0,0 @@
1
- # encoding : utf-8
2
-
3
- Iam::Configuration.configure do |config|
4
- # Account class name
5
- # config.account_class = 'User'
6
-
7
- # Account attributes to display in the table
8
- # account_attributes = ['id', 'full_name']
9
-
10
- # Role class name
11
- # role_class = 'Role'
12
-
13
- # Role attribute to display as a group name
14
- # role_name_attribute = 'name'
15
-
16
- # Accounts to display for each role
17
- # accounts_for_each_role = 3
18
- end
@@ -1,7 +0,0 @@
1
- module Rack
2
- class Railtie < ::Rails::Railtie
3
- initializer 'iam-assets.add_middleware' do |app|
4
- app.middleware.use Rack::Assets unless Rails.env.production?
5
- end
6
- end
7
- end
@@ -1 +0,0 @@
1
- (function(){$(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h;return h="/iam/log_in_as/:id",l="/iam/menu",s=!1,i="",e=["alt","ctrl","shift"],r=function(){return $(".iam-settings-header").on("click",function(){return $(".iam-settings").toggle()}),$("#iam-menu").on("click","td",function(){var e,t;e=$(this).parents("tr"),t=e.attr("href");if(t)return f(t)}),$.each(e,function(){var e,t;return e=$(".iam-"+this+"-settings input"),t="iam-"+this+"-checked",e[0].checked=$.cookie(t)==="true",e.on("click",function(){return $.cookie(t,this.checked)})})},n=function(e){var t;return t=$("<div class='iam-notice'>"+e+"</div>"),$("body").append(t),t.fadeIn(200).delay(1e3).fadeOut(600)},f=function(e){return $.post(e,function(e){return window.location.reload(),n(e.notice)})},u=function(e){return String.fromCharCode(e)==="À"},t=function(t){var n,r,i,s;for(i=0,s=e.length;i<s;i++){n=e[i],r=$.cookie("iam-"+n+"-checked")==="true";if(r!==t[""+n+"Key"])return!1}return!0},o=function(){return $(document.getSelection().focusNode).find("input, textarea").length>0},c=function(e){var t;if(e.match(/^\d+$/))return t=h.replace(/:id/,e),f(t);if(e)return n(""+e+" is invalid id.")},a=function(){return s?c(i):$.get(l,function(e){return $("body").append(e),r()}),i=""},$(document).on("keydown",function(e){var n;if(!o()&&u(e.keyCode)&&t(e))return a(),s=!s,$("#iam-menu").remove();if(48<=(n=e.keyCode)&&n<=57)return i+=String.fromCharCode(e.keyCode)})})}).call(this);