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 +2 -2
- data/Rakefile +4 -5
- data/{vendor/assets/javascripts/iam.js.coffee → app/assets/javascripts/iam.coffee} +1 -1
- data/app/assets/javascripts/iam.js +2 -0
- data/{vendor → app}/assets/javascripts/jquery.cookie.js +0 -0
- data/{vendor → app}/assets/stylesheets/iam.css +0 -0
- data/{vendor → app}/assets/stylesheets/iam.css.sass +0 -0
- data/app/controllers/iam_controller.rb +9 -16
- data/app/helpers/iam_helper.rb +25 -0
- data/app/views/iam/_account.html.erb +2 -2
- data/app/views/iam/_account_attribute.html.erb +2 -4
- data/app/views/iam/_account_group.html.erb +2 -2
- data/app/views/iam/_settings.html.erb +2 -2
- data/app/views/iam/menu.html.erb +1 -1
- data/config/routes.rb +1 -1
- data/lib/generators/iam/initializer_generator.rb +2 -4
- data/lib/generators/templates/iam.yml +16 -0
- data/lib/iam.rb +5 -2
- data/lib/iam/authorization_provider/devise.rb +13 -0
- data/lib/iam/authorization_provider/factory.rb +17 -0
- data/lib/iam/configuration.rb +6 -17
- data/lib/iam/engine.rb +8 -1
- data/lib/iam/version.rb +1 -1
- data/lib/rack/assets_middleware.rb +0 -3
- data/spec/rails_app/config/iam.yml +16 -0
- metadata +12 -10
- data/lib/generators/templates/iam.rb +0 -18
- data/lib/rack/railtie.rb +0 -7
- data/vendor/assets/javascripts/iam.js.js +0 -1
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
|
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
|
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
|
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('
|
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('
|
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('
|
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"
|
@@ -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);
|
File without changes
|
File without changes
|
File without changes
|
@@ -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
|
9
|
+
def log_in
|
9
10
|
return if Rails.env == 'production'
|
10
11
|
|
11
|
-
account
|
12
|
-
sign_in Iam::Configuration.account_class.downcase, account
|
12
|
+
log_in_account account
|
13
13
|
|
14
|
-
|
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
|
20
|
-
|
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
|
2
|
-
<%= render partial: 'iam/account_attribute', collection:
|
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,8 +1,8 @@
|
|
1
1
|
<% role, accounts = account_group %>
|
2
2
|
|
3
3
|
<tr>
|
4
|
-
<td class='role-name' colspan=<%= Iam::Configuration.
|
5
|
-
<%= role
|
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.
|
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.
|
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>
|
data/app/views/iam/menu.html.erb
CHANGED
data/config/routes.rb
CHANGED
@@ -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
|
6
|
+
desc 'Creates a sample Iam configuration.'
|
8
7
|
def copy_initializer
|
9
|
-
copy_file 'iam.
|
8
|
+
copy_file 'iam.yml', 'config/iam.yml'
|
10
9
|
end
|
11
|
-
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
data/lib/iam.rb
CHANGED
@@ -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
|
data/lib/iam/configuration.rb
CHANGED
@@ -1,22 +1,11 @@
|
|
1
1
|
module Iam
|
2
2
|
module Configuration
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
14
|
-
|
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
|
data/lib/iam/engine.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
module Iam
|
2
|
-
class 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
|
data/lib/iam/version.rb
CHANGED
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
|
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-
|
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.
|
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
|
data/lib/rack/railtie.rb
DELETED
@@ -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);
|