iam 0.0.4 → 0.0.5

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/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.swp
2
+ **/*.swp
3
+ *.gem
4
+ Gemfile.lock
5
+ .bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,9 @@
1
+ class IamController < ApplicationController
2
+ def log_in_as
3
+ account = Iam::Configuration.account_class.constantize.find(params[:id])
4
+ sign_in Iam::Configuration.account_class.downcase, account
5
+
6
+ account_attributes = account.attributes.slice(*Iam::Configuration.account_attributes).values.join(' ')
7
+ render json: { notice: "Successfully logged in as:\n#{account_attributes}" }
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module IamHelper
2
+ ROLE_CLASS = Iam::Configuration.role_class.constantize
3
+ ACCOUNT_CLASS = Iam::Configuration.account_class.constantize
4
+
5
+ def iam
6
+ @account_samples = account_samples
7
+ render 'iam/menu'
8
+ end
9
+
10
+ private
11
+ def account_samples
12
+ ROLE_CLASS.all.inject({}) do |account_groups, role|
13
+ account_group = ACCOUNT_CLASS.where(ROLE_CLASS.to_s.foreign_key => role.id).limit(Iam::Configuration.accounts_for_each_role)
14
+ account_groups.merge role => account_group
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ <tr href='<%= log_in_as_path(account) %>'>
2
+ <%= render partial: 'iam/account_attribute', collection: account.attributes.slice(*Iam::Configuration.account_attributes).to_a %>
3
+ </tr>
@@ -0,0 +1,5 @@
1
+ <% key, value = account_attribute %>
2
+
3
+ <td class="attribute <%= key %>-attribute">
4
+ <%= value %>
5
+ </td>
@@ -0,0 +1,8 @@
1
+ <% role, accounts = account_group %>
2
+
3
+ <tr>
4
+ <td class='role-name' colspan=<%= Iam::Configuration.account_attributes.count %>>
5
+ <%= role.send Iam::Configuration.role_name_attribute %>
6
+ </td>
7
+ </tr>
8
+ <%= render partial: 'iam/account', collection: accounts %>
@@ -0,0 +1,3 @@
1
+ <table id='iam-menu' href='<%= log_in_as_path(id: 'ID') %>'>
2
+ <%= render partial: 'iam/account_group', collection: @account_samples.to_a %>
3
+ </table>
data/iam.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/iam/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'iam'
6
+ s.version = Iam::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.license = 'MIT'
9
+ s.author = 'Yury Kaliada'
10
+ s.email = 'fut.wrk@gmail.com'
11
+ s.description = 'Simple account switcher for Rails that automatically retrieves a few user accounts for each role and provides single-click login feature.'
12
+ s.homepage = 'http://github.com/FUT/iam'
13
+ s.summary = 'Simple account switcher for Rails.'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.require_path = 'lib'
17
+
18
+ s.add_dependency 'activesupport', '~> 3.1'
19
+ s.add_dependency 'coffee-rails', '~> 3.2.1'
20
+ s.add_dependency 'sass'
21
+ s.add_dependency 'devise'
22
+
23
+ s.add_development_dependency 'rails', '~> 3.1'
24
+ s.add_development_dependency 'rspec-rails', '~> 2.10'
25
+
26
+ s.rubyforge_project = s.name
27
+ end
data/lib/iam/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Iam
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -0,0 +1,15 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /log/*.log
15
+ /tmp
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,38 @@
1
+ $ ->
2
+ $menu = $('#iam-menu')
3
+ linkTemplate = $menu.attr 'href'
4
+ inputMode = false
5
+ input = ''
6
+
7
+ iamNotice = (notice) ->
8
+ $notice = $("<div class='iam-notice'>#{notice}</div>")
9
+ $('body').append $notice
10
+ $notice.fadeIn(200).delay(1000).fadeOut 600
11
+
12
+ log_in_by_link = (link) ->
13
+ $.post link, (data) ->
14
+ $menu.hide()
15
+ iamNotice data.notice
16
+
17
+ log_in_by_input = ->
18
+ if inputMode
19
+ if input.match(/^\d+$/)
20
+ link = linkTemplate.replace(/ID/, input)
21
+ log_in_by_link link
22
+ else
23
+ iamNotice "#{input} is invalid id."
24
+ input = ''
25
+
26
+ $menu.on 'click', 'td', ->
27
+ $tr = $(@).parents 'tr'
28
+ link = $tr.attr 'href'
29
+ log_in_by_link link if link
30
+
31
+ $(document).on 'keypress', (e) ->
32
+ if e.keyCode == 96 || e.keyCode == 1105 # '`' || 'ё'
33
+ log_in_by_input()
34
+
35
+ inputMode = !inputMode
36
+ $menu.toggle()
37
+ else
38
+ input += String.fromCharCode e.keyCode
@@ -0,0 +1,28 @@
1
+ #iam-menu
2
+ text-align: center
3
+ background: #d9ead3
4
+ border-spacing: 0
5
+ position: fixed
6
+ top: 0
7
+ left: 0
8
+ display: none
9
+ cursor: pointer
10
+
11
+ td
12
+ border: 1px solid #c9dac3
13
+ margin: 0
14
+ padding: 2px
15
+
16
+ .role-name
17
+ cursor: default
18
+ padding: 5px
19
+ font-size: 120%
20
+ font-weight: bold
21
+
22
+ .iam-notice
23
+ position: fixed
24
+ left: 200px
25
+ top: 0
26
+ background: #d9ead3
27
+ padding: 5px
28
+ display: none
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.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -114,58 +114,76 @@ executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
- - lib/iam/version.rb
118
- - lib/iam/configuration.rb
119
- - lib/iam/engine.rb
120
- - lib/iam.rb
117
+ - .gitignore
118
+ - .rspec
119
+ - Gemfile
120
+ - README.md
121
+ - Rakefile
122
+ - app/controllers/iam_controller.rb
123
+ - app/helpers/iam_helper.rb
124
+ - app/views/iam/_account.html.erb
125
+ - app/views/iam/_account_attribute.html.erb
126
+ - app/views/iam/_account_group.html.erb
127
+ - app/views/iam/_menu.html.erb
128
+ - config/routes.rb
129
+ - iam.gemspec
121
130
  - lib/generators/iam/initializer_generator.rb
122
131
  - lib/generators/templates/iam.rb
123
- - config/routes.rb
124
- - spec/rails_app/db/seeds.rb
125
- - spec/rails_app/db/schema.rb
126
- - spec/rails_app/db/migrate/20121202072527_create_user.rb
127
- - spec/rails_app/db/migrate/20121202131821_add_devise_to_users.rb
128
- - spec/rails_app/db/migrate/20121202072519_create_role.rb
129
- - spec/rails_app/config/initializers/inflections.rb
130
- - spec/rails_app/config/initializers/mime_types.rb
131
- - spec/rails_app/config/initializers/session_store.rb
132
- - spec/rails_app/config/initializers/wrap_parameters.rb
133
- - spec/rails_app/config/initializers/backtrace_silencers.rb
134
- - spec/rails_app/config/initializers/secret_token.rb
135
- - spec/rails_app/config/initializers/devise.rb
136
- - spec/rails_app/config/environments/development.rb
137
- - spec/rails_app/config/environments/production.rb
138
- - spec/rails_app/config/environments/test.rb
139
- - spec/rails_app/config/application.rb
140
- - spec/rails_app/config/environment.rb
141
- - spec/rails_app/config/locales/en.yml
142
- - spec/rails_app/config/locales/devise.en.yml
143
- - spec/rails_app/config/database.yml
144
- - spec/rails_app/config/routes.rb
145
- - spec/rails_app/config/boot.rb
132
+ - lib/iam.rb
133
+ - lib/iam/configuration.rb
134
+ - lib/iam/engine.rb
135
+ - lib/iam/version.rb
136
+ - spec/rails_app/.gitignore
137
+ - spec/rails_app/.sass-cache/465c165ef21fa54af136b469241496dfb6e2a334/iam.css.sassc
138
+ - spec/rails_app/.sass-cache/465c165ef21fa54af136b469241496dfb6e2a334/menu.css.sassc
139
+ - spec/rails_app/Rakefile
146
140
  - spec/rails_app/app/assets/images/rails.png
147
141
  - spec/rails_app/app/assets/javascripts/application.js
148
142
  - spec/rails_app/app/assets/stylesheets/application.css
149
- - spec/rails_app/app/views/layouts/application.html.erb
150
- - spec/rails_app/app/views/pages/index.html.erb
151
- - spec/rails_app/app/models/user.rb
152
- - spec/rails_app/app/models/role.rb
153
- - spec/rails_app/app/controllers/pages_controller.rb
154
143
  - spec/rails_app/app/controllers/application_controller.rb
144
+ - spec/rails_app/app/controllers/pages_controller.rb
155
145
  - spec/rails_app/app/helpers/application_helper.rb
156
- - spec/rails_app/Rakefile
146
+ - spec/rails_app/app/mailers/.gitkeep
147
+ - spec/rails_app/app/models/.gitkeep
148
+ - spec/rails_app/app/models/role.rb
149
+ - spec/rails_app/app/models/user.rb
150
+ - spec/rails_app/app/views/layouts/application.html.erb
151
+ - spec/rails_app/app/views/pages/index.html.erb
157
152
  - spec/rails_app/config.ru
158
- - spec/rails_app/script/rails
159
- - spec/rails_app/public/robots.txt
160
- - spec/rails_app/public/422.html
153
+ - spec/rails_app/config/application.rb
154
+ - spec/rails_app/config/boot.rb
155
+ - spec/rails_app/config/database.yml
156
+ - spec/rails_app/config/environment.rb
157
+ - spec/rails_app/config/environments/development.rb
158
+ - spec/rails_app/config/environments/production.rb
159
+ - spec/rails_app/config/environments/test.rb
160
+ - spec/rails_app/config/initializers/backtrace_silencers.rb
161
+ - spec/rails_app/config/initializers/devise.rb
162
+ - spec/rails_app/config/initializers/inflections.rb
163
+ - spec/rails_app/config/initializers/mime_types.rb
164
+ - spec/rails_app/config/initializers/secret_token.rb
165
+ - spec/rails_app/config/initializers/session_store.rb
166
+ - spec/rails_app/config/initializers/wrap_parameters.rb
167
+ - spec/rails_app/config/locales/devise.en.yml
168
+ - spec/rails_app/config/locales/en.yml
169
+ - spec/rails_app/config/routes.rb
170
+ - spec/rails_app/db/migrate/20121202072519_create_role.rb
171
+ - spec/rails_app/db/migrate/20121202072527_create_user.rb
172
+ - spec/rails_app/db/migrate/20121202131821_add_devise_to_users.rb
173
+ - spec/rails_app/db/schema.rb
174
+ - spec/rails_app/db/seeds.rb
175
+ - spec/rails_app/lib/assets/.gitkeep
176
+ - spec/rails_app/lib/tasks/.gitkeep
161
177
  - spec/rails_app/public/404.html
162
- - spec/rails_app/public/favicon.ico
178
+ - spec/rails_app/public/422.html
163
179
  - spec/rails_app/public/500.html
180
+ - spec/rails_app/public/favicon.ico
181
+ - spec/rails_app/public/robots.txt
182
+ - spec/rails_app/script/rails
164
183
  - spec/spec_helper.rb
165
184
  - spec/support/database_cleaner.rb
166
- - README.md
167
- - Gemfile
168
- - Rakefile
185
+ - vendor/assets/javascripts/iam.js.coffee
186
+ - vendor/assets/stylesheets/iam.css.sass
169
187
  homepage: http://github.com/FUT/iam
170
188
  licenses:
171
189
  - MIT