esp-auth 1.0.0

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.
Files changed (51) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +28 -0
  3. data/Rakefile +28 -0
  4. data/app/assets/images/esp_auth/gh_icons.png +0 -0
  5. data/app/assets/images/esp_auth/inline_error_arrow.png +0 -0
  6. data/app/assets/images/esp_auth/wood.jpg +0 -0
  7. data/app/assets/javascripts/esp_auth/application.js +4 -0
  8. data/app/assets/javascripts/esp_auth/jquery.noisy.min.js +3 -0
  9. data/app/assets/javascripts/esp_auth/permissions.js +62 -0
  10. data/app/assets/stylesheets/esp_auth/application.css +11 -0
  11. data/app/assets/stylesheets/esp_auth/buttons.sass +300 -0
  12. data/app/assets/stylesheets/esp_auth/jquery_ui.sass +1493 -0
  13. data/app/assets/stylesheets/esp_auth/pagination.sass +19 -0
  14. data/app/assets/stylesheets/esp_auth/permissions.sass +150 -0
  15. data/app/assets/stylesheets/esp_auth/shared.sass +84 -0
  16. data/app/controllers/esp_auth/application_controller.rb +11 -0
  17. data/app/controllers/esp_auth/omniauth_callbacks_controller.rb +11 -0
  18. data/app/controllers/esp_auth/permissions_controller.rb +13 -0
  19. data/app/controllers/esp_auth/sessions_controller.rb +16 -0
  20. data/app/controllers/esp_auth/users_controller.rb +24 -0
  21. data/app/models/user_search.rb +13 -0
  22. data/app/views/esp_auth/permissions/new.html.erb +23 -0
  23. data/app/views/esp_auth/shared/_footer.html.erb +12 -0
  24. data/app/views/esp_auth/shared/_header.html.erb +24 -0
  25. data/app/views/esp_auth/users/index.html.erb +53 -0
  26. data/app/views/layouts/esp_auth/application.html.erb +18 -0
  27. data/config/initializers/devise.rb +223 -0
  28. data/config/locales/ru.yml +35 -0
  29. data/config/routes.rb +25 -0
  30. data/lib/esp-auth.rb +19 -0
  31. data/lib/esp_auth/engine.rb +41 -0
  32. data/lib/esp_auth/spec_helper.rb +68 -0
  33. data/lib/esp_auth/version.rb +3 -0
  34. data/lib/generators/esp_auth/install/install_generator.rb +49 -0
  35. data/lib/generators/esp_auth/install/templates/app/controllers/manage/application_controller.rb +3 -0
  36. data/lib/generators/esp_auth/install/templates/app/models/ability.rb +41 -0
  37. data/lib/generators/esp_auth/install/templates/app/models/context.rb +27 -0
  38. data/lib/generators/esp_auth/install/templates/app/models/permission.rb +69 -0
  39. data/lib/generators/esp_auth/install/templates/app/models/subcontext.rb +21 -0
  40. data/lib/generators/esp_auth/install/templates/app/models/user.rb +67 -0
  41. data/lib/generators/esp_auth/install/templates/config/locales/permissions_enum.ru.yml +6 -0
  42. data/lib/generators/esp_auth/install/templates/config/schedule.rb +5 -0
  43. data/lib/generators/esp_auth/install/templates/db/migrate/esp_auth_create_contexts.rb +12 -0
  44. data/lib/generators/esp_auth/install/templates/db/migrate/esp_auth_create_permissions.rb +11 -0
  45. data/lib/generators/esp_auth/install/templates/db/migrate/esp_auth_create_subcontexts.rb +9 -0
  46. data/lib/generators/esp_auth/install/templates/db/migrate/esp_auth_create_users.rb +29 -0
  47. data/lib/generators/esp_auth/install/templates/db/seeds.rb +4 -0
  48. data/lib/generators/esp_auth/install/templates/spec/models/ability_spec.rb +83 -0
  49. data/lib/omniauth/strategies/identity.rb +15 -0
  50. data/lib/tasks/sync.rake +17 -0
  51. metadata +453 -0
@@ -0,0 +1,19 @@
1
+ @import "compass/utilities"
2
+ @import "compass/css3"
3
+
4
+ .pagination
5
+ span
6
+ +inline-block
7
+ border: 1px solid #ccc
8
+ +border-radius
9
+ margin: 0 2px
10
+ &.current,
11
+ &.gap,
12
+ a
13
+ +inline-block
14
+ padding: 5px 10px
15
+ &.current,
16
+ &.gap
17
+ cursor: default
18
+ &.current
19
+ background: #bbb
@@ -0,0 +1,150 @@
1
+ @import "compass/utilities"
2
+ @import "compass/reset"
3
+ @import "compass/css3"
4
+
5
+ body
6
+ background: #73351F image_url('esp_auth/wood.jpg') no-repeat center top fixed
7
+ color: #333
8
+ font-family: Helvetica, Verdana, sans-serif
9
+ font-size: 13px
10
+ line-height: 16px
11
+
12
+ a
13
+ color: #484B51
14
+ outline: none
15
+ text-decoration: none
16
+
17
+ &:active, &:hover
18
+ color: #484B51
19
+ text-decoration: underline
20
+
21
+ h1
22
+ +single-text-shadow(#555, 1px, 1px, 3px)
23
+ color: whitesmoke
24
+ font-size: 28px
25
+ text-align: center
26
+ padding: 15px 0
27
+ width: 100%
28
+
29
+ h3
30
+ font-size: 14px
31
+
32
+ span
33
+ font-weight: bold
34
+
35
+ .container
36
+ +border-radius(4px)
37
+ +single-box-shadow(#555, 0px, 0px, 20px)
38
+ background: #EEF1F8
39
+ margin: 5px auto 0
40
+ padding: 25px 30px
41
+ width: 960px
42
+
43
+ .new_permission
44
+ display: block
45
+ margin: 0 0 15px 0
46
+ text-align: right
47
+
48
+ .permission_list
49
+ display: none
50
+
51
+ .collection_list
52
+
53
+ li
54
+ +clearfix
55
+ border: 1px solid #A17345
56
+ margin: 0 0 15px 0
57
+ padding: 15px 20px
58
+
59
+ li.user
60
+ +border-radius(4px)
61
+
62
+ ul
63
+ +clearfix
64
+ width: 100%
65
+
66
+ li
67
+ border: none
68
+ margin: 5px 0
69
+ padding: 0
70
+
71
+ ul
72
+ margin: 0 0 0 15px
73
+
74
+ .name, .email, h4
75
+ float: left
76
+ font-size: 14px
77
+ line-height: 26px
78
+ margin: 0 10px 0 0
79
+
80
+ .name
81
+ font-weight: bold
82
+
83
+ .button-group
84
+ float: right
85
+
86
+ .remove
87
+ margin: 0 0 0 10px
88
+
89
+ .show_permissions
90
+ float: right
91
+ text-decoration: none
92
+
93
+ .links
94
+ +clearfix
95
+ line-height: 26px
96
+
97
+ .formtastic
98
+ .inline-errors
99
+ background: transparent image_url("esp_auth/inline_error_arrow.png") no-repeat left center
100
+ font-size: 12px
101
+ color: #933
102
+ padding: 0 0 0 18px
103
+
104
+ .inputs
105
+ li
106
+ margin: 15px 0
107
+
108
+ .label
109
+ display: block
110
+ margin: 0 0 5px 0
111
+
112
+ select
113
+ font-size: 14px
114
+ height: 26px
115
+ padding: 2px 3px
116
+ width: 954px
117
+
118
+ input
119
+ font-size: 14px
120
+ height: 20px
121
+ padding: 3px 4px
122
+ width: 868px
123
+
124
+ #permission_user_search
125
+ width: 942px
126
+
127
+
128
+ .button-group
129
+ margin: 15px 0
130
+
131
+ .user_search
132
+ +clearfix
133
+
134
+ .inputs
135
+ +clearfix
136
+ float: left
137
+ margin: 0 10px 15px 0
138
+
139
+ li
140
+ margin: 0
141
+
142
+ input
143
+ font-size: 14px
144
+ height: 20px
145
+ padding: 3px 4px
146
+ width: 868px
147
+
148
+ .buttons
149
+ +clearfix
150
+ margin: 2px 0 0 0
@@ -0,0 +1,84 @@
1
+ @import 'compass/utilities'
2
+ @import 'compass/css3'
3
+
4
+ $esp_auth_body_margin_top: 35px !default
5
+ $esp_auth_body_margin_bottom: 40px !default
6
+
7
+ $esp_auth_font_size: 11px !default
8
+ $esp_auth_font_family: Arial, Verdana, sans-serif !default
9
+
10
+ $esp_auth_text_color: #000 !default
11
+ $esp_auth_background_color: window !default
12
+ $esp_auth_link_color: #031074 !default
13
+ $esp_auth_underline_link: true !default
14
+ $esp_auth_hover_link_color: #000055 !default
15
+ $esp_auth_underline_hover_link: false !default
16
+
17
+ body
18
+ margin-top: $esp_auth_body_margin_top
19
+ margin-bottom: $esp_auth_body_margin_bottom
20
+
21
+ =fixed_block
22
+ +nested-reset
23
+ +single-box-shadow
24
+ font-size: $esp_auth_font_size
25
+ font-family: $esp_auth_font_family
26
+ background-color: $esp_auth_background_color
27
+ line-height: 1.5
28
+ color: $esp_auth_text_color
29
+ position: fixed
30
+ width: 100%
31
+ z-index: 99999
32
+ a
33
+ color: $esp_auth_link_color
34
+ @if $esp_auth_underline_link
35
+ text-decoration: underline
36
+ @else
37
+ text-decoration: none
38
+ &:hover
39
+ color: $esp_auth_hover_link_color
40
+ @if $esp_auth_underline_hover_link
41
+ text-decoration: underline
42
+ @else
43
+ text-decoration: none
44
+ &.selected
45
+ color: $esp_auth_text_color
46
+ @if $esp_auth_underline_link
47
+ text-decoration: none
48
+ @else
49
+ text-decoration: underline
50
+
51
+ .esp_auth_header_wrapper
52
+ +fixed_block
53
+ top: 0
54
+ left: 0
55
+ border-bottom: 1px solid #999
56
+
57
+ .esp_auth_header
58
+ +clearfix
59
+ margin: 5px 10px
60
+ .navigation
61
+ float: left
62
+ a
63
+ margin-right: 5px
64
+ .auth
65
+ float: right
66
+ .current_user
67
+ margin-right: 5px
68
+
69
+
70
+ .esp_auth_footer_wrapper
71
+ +fixed_block
72
+ bottom: 0
73
+ left: 0
74
+ border-top: 1px solid #999
75
+
76
+ .esp_auth_footer
77
+ +clearfix
78
+ margin: 5px 10px
79
+ .info
80
+ float: left
81
+ .developer
82
+ float: right
83
+ .range
84
+ margin-right: 5px
@@ -0,0 +1,11 @@
1
+ class EspAuth::ApplicationController < ApplicationController
2
+ esp_load_and_authorize_resource
3
+
4
+ before_filter :authorize_user_can_manage_permissions!
5
+
6
+ protected
7
+
8
+ def authorize_user_can_manage_permissions!
9
+ authorize! :manage, :permissions
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class EspAuth::OmniauthCallbacksController < Devise::OmniauthCallbacksController
2
+ def identity
3
+ user = User.find_or_initialize_by_uid(request.env['omniauth.auth']['uid']).tap do |user|
4
+ user.update_attributes request.env['omniauth.auth']['info']
5
+ end
6
+
7
+ flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Identity"
8
+ sign_in user, :event => :authentication
9
+ redirect_to stored_location_for(:user) || main_app.root_path
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class EspAuth::PermissionsController < EspAuth::ApplicationController
2
+ belongs_to :user, :optional => true
3
+ actions :new, :create, :destroy
4
+
5
+ def create
6
+ create!{ esp_auth.users_path }
7
+ end
8
+
9
+ def destroy
10
+ destroy!{ esp_auth.users_path }
11
+ end
12
+
13
+ end
@@ -0,0 +1,16 @@
1
+ class EspAuth::SessionsController < ApplicationController
2
+ def destroy
3
+ reset_session
4
+ redirect_to "#{Settings['sso.url']}/users/sign_out?redirect_uri=#{CGI.escape(redirect_uri)}"
5
+ end
6
+
7
+ protected
8
+
9
+ def redirect_uri
10
+ URI.parse(request.url).tap do | uri |
11
+ uri.path = main_app.root_path
12
+ uri.query = nil
13
+ end.to_s
14
+ end
15
+
16
+ end
@@ -0,0 +1,24 @@
1
+ class EspAuth::UsersController < EspAuth::ApplicationController
2
+ has_searcher
3
+
4
+ actions :index, :search
5
+
6
+ has_scope :page, :default => 1
7
+
8
+ def search
9
+ render :json => JSON.parse(Curl::Easy.http_get("#{Settings['sso.url']}/users.json?user_search[keywords]=#{URI.escape(params[:term])}").body_str) and return
10
+ end
11
+
12
+ protected
13
+ def collection
14
+ get_collection_ivar || set_collection_ivar(search_and_paginate_collection)
15
+ end
16
+
17
+ def search_and_paginate_collection
18
+ search_object = searcher_for(resource_instance_name)
19
+ search_object.permissions_count_gt = 1
20
+ search_object.pagination = {:page => params[:page], :per_page => 10}
21
+ search_object.order_by = 'uid' if search_object.term.blank?
22
+ search_object.results
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ class UserSearch < Search
2
+ column :order_by, :string
3
+ column :term, :text
4
+ column :permissions_count_gt, :integer
5
+ end
6
+
7
+ # == Schema Information
8
+ #
9
+ # Table name: searches
10
+ #
11
+ # keywords :text
12
+ #
13
+
@@ -0,0 +1,23 @@
1
+ <h3>
2
+ <%= "#{t('permissions.You are adding role to')} #{@user.try(:name)}" %>
3
+ </h3>
4
+
5
+ <%= semantic_form_for resource,
6
+ :url => (@user ? esp_auth.user_permissions_path(@user) : esp_auth.permissions_path) do |form| %>
7
+ <%= form.inputs do %>
8
+ <%= form.input :user_uid, :as => :hidden %>
9
+ <%= form.input :user_name, :as => :hidden %>
10
+ <%= form.input :user_email, :as => :hidden %>
11
+ <%= form.input :user_search, :as => :string unless @user %>
12
+ <%= form.input :polimorphic_context, :as => :select,
13
+ :collection => current_user.contexts_tree,
14
+ :member_value => ->(c) { [c.class.model_name.underscore, c.id].join('_') },
15
+ :member_label => ->(c) { ('&nbsp;' * 2 * c.depth + c.title).html_safe },
16
+ :include_blank => t('permissions.not_selected') %>
17
+ <%= form.input :role, :as => :select, :collection => Permission.human_enums[:role].invert, :include_blank => t('permissions.not_selected') %>
18
+ <% end %>
19
+ <%= form.buttons :class => 'button-group' do %>
20
+ <li><%= button_tag t('permissions.create'), :class => 'button icon approve' %></li>
21
+ <li><%= link_to t('permissions.cancel'), esp_auth.users_path, :class => 'button icon arrowleft' %></li>
22
+ <% end %>
23
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <div class='esp_auth_footer_wrapper'>
2
+ <div class='esp_auth_footer'>
3
+ <div class='info'>
4
+ <%= [request.remote_addr, request.remote_ip].join(', ').split(', ').uniq.join(', ') %>
5
+ <%= request.env['HTTP_USER_AGENT'] %>
6
+ </div>
7
+ <div class='developer'>
8
+ <span class='range'>2011&ndash;<%= Date.today.year %></span>
9
+ <a href='http://openteam.ru/' title='Сделано с любовью в OpenTeam'>OpenTeam</a>
10
+ </div>
11
+ </div>
12
+ </div>
@@ -0,0 +1,24 @@
1
+ <div class='esp_auth_header_wrapper'>
2
+ <div class='esp_auth_header'>
3
+ <% if current_user %>
4
+ <% current = controller_path.match(/^([a-z_]+)/)[0].inquiry %>
5
+ <div class='navigation'>
6
+ <% if can? :manage, :application %>
7
+ <%= link_to 'Публичный вид', '/', :class => current.manage? || current.esp_auth? ? nil : 'selected' %>
8
+ <%= link_to 'Система управления', '/manage', :class => current.manage? ? 'selected' : nil %>
9
+ <% end %>
10
+ <% if can? :manage, :permissions %>
11
+ <%= link_to 'Права доступа', esp_auth.root_path, :class => current.esp_auth? ? 'selected' : nil %>
12
+ <% end %>
13
+ </div>
14
+ <div class='auth'>
15
+ <span class='current_user'><%= current_user.name %></span>
16
+ <%= link_to('Выход', esp_auth.destroy_user_session_path) %>
17
+ </div>
18
+ <% else %>
19
+ <div class='auth'>
20
+ <%= link_to 'Вход в систему', user_omniauth_authorize_path(:identity) %>
21
+ </div>
22
+ <% end %>
23
+ </div>
24
+ </div>
@@ -0,0 +1,53 @@
1
+ <%= semantic_search_form_for :user, :url => esp_auth.users_path do |form| %>
2
+ <%= form.inputs do %>
3
+ <%= form.input :term, :as => :string, :label => false %>
4
+ <% end %>
5
+ <%= form.buttons do %>
6
+ <li><%= button_tag t('permissions.search'), :class => 'button icon search' %></li>
7
+ <% end %>
8
+ <% end %>
9
+
10
+ <%= link_to "&#43;#{t('permissions.create_permission')}".html_safe,
11
+ esp_auth.new_permission_path,
12
+ :class => 'new_permission' %>
13
+
14
+ <ul class='collection_list'>
15
+ <% collection.each do |user| %>
16
+ <li class='user'>
17
+ <div class="name">
18
+ <%= user.name %>
19
+ </div>
20
+ <div class="email">
21
+ &lt;<%= mail_to user.email, user.email %>&gt;
22
+ </div>
23
+
24
+ <div class="links">
25
+ <%= link_to "&darr;&nbsp;#{t('permissions.show_permissions')}".html_safe, '#', :class => 'show_permissions' %>
26
+ <%= link_to "&#43;#{t('permissions.new')}".html_safe, esp_auth.new_user_permission_path(user), :class => 'add' %>
27
+ </div>
28
+
29
+ <ul class='permission_list'>
30
+ <% user.permissions.group_by(&:role).each do |role, permissions| %>
31
+ <li>
32
+ <h4><%= permissions.first.human_role %></h4>
33
+ <ul>
34
+ <% permissions.each do |permission| %>
35
+ <li>
36
+ <%= permission.context %>
37
+ <%= link_to t('permissions.delete'),
38
+ esp_auth.permission_path(permission),
39
+ :method => :delete,
40
+ :confirm => t('permissions.Are you sure?'),
41
+ :class => 'buttton icon remove danger' if can?(:destroy, permission) %>
42
+ </li>
43
+ <% end %>
44
+ </ul>
45
+ </li>
46
+ <% end %>
47
+ </ul>
48
+
49
+ </li>
50
+ <% end %>
51
+ </ul>
52
+
53
+ <%= paginate collection %>
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE HTML>
2
+ <html lang="ru">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title><%= t('permissions.title') %></title>
6
+ <%= stylesheet_link_tag 'esp_auth/application' %>
7
+ <%= javascript_include_tag 'esp_auth/application' %>
8
+ <%= csrf_meta_tags %>
9
+ </head>
10
+ <body>
11
+ <%= render :partial => "esp_auth/shared/header" %>
12
+ <h1><%= t('permissions.title') %></h1>
13
+ <div class="container">
14
+ <%= yield %>
15
+ </div>
16
+ <%= render :partial => "esp_auth/shared/footer" %>
17
+ </body>
18
+ </html>