the_role 1.6.2 → 1.6.3

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
@@ -4,21 +4,40 @@
4
4
  |:------------- |:-------------|
5
5
  | ![Bye bye CanCan, I got The Role!](https://github.com/the-teacher/the_role/raw/master/Bye_bye_CanCan_I_got_the_Role.png) | TheRole is an authorization library for Ruby on Rails which restricts what resources a given user is allowed to access. All permissions are defined in with 2-level-hash, and store in database with JSON.<br><br>TheRole - Semantic, lightweight role system with an administrative interface.<br><br>Role is a two-level hash, consisting of the **sections** and nested **rules**.<br><br>**Section** may be associated with **controller** name.<br><br>**Rule** may be associated with **action** name.<br><br>Section can have many rules.<br><br>Rule can have **true** or **false** value<br><br>**Sections** and nested **Rules** provide **ACL** (**Access Control List**)<br><br>Role **stored in the database as JSON** string.<br><br>Using of hashes, makes role system extremely easy to configure and use.<br> |
6
6
 
7
- ### rubygems page
8
-
9
- http://rubygems.org/gems/the_role
10
-
11
7
  ### GUI
12
8
 
13
9
  | TheRole management web interface |
14
10
  |:-------------:|
15
11
  |![TheRole](https://github.com/the-teacher/the_role/raw/master/pic.png)|
16
12
 
13
+ ### rubygems page
14
+
15
+ http://rubygems.org/gems/the_role
16
+
17
+ ### TheRole and Devise 2
18
+
19
+ [Integration with Devise2](https://github.com/the-teacher/the_role/wiki/Integration-with-Devise2)
20
+
21
+ ### TheRole and Sorcery
22
+
23
+ [Integration with Sorcery](https://github.com/the-teacher/the_role/wiki/Integration-with-Sorcery)
24
+
25
+ ### Want to improve this gem?
26
+
27
+ * I need for your feedback and issues
28
+ * [How to start development process](https://github.com/the-teacher/the_role/wiki/Want-to-improve-this-gem%3F)
29
+
30
+ ### Rspec for TheRole
31
+
32
+ [Specs with Devise 2](https://github.com/the-teacher/devise2_on_the_role/tree/master/spec)
33
+
34
+ Read **How to start development process** manual for running specs
35
+
17
36
  ## What does it mean semantic?
18
37
 
19
38
  Semantic - the science of meaning. Human should fast to understand what is happening in a role system.
20
39
 
21
- Look at hash. If you can understand access rules - this role system is semantically.
40
+ Look at next Role hash. If you can understand access rules - this authorization system is semantically.
22
41
 
23
42
  ``` ruby
24
43
  role = {
@@ -68,38 +87,57 @@ And you can use them as well as other access rules.
68
87
  bundle
69
88
  ```
70
89
 
71
- ### Migrate
90
+ ### User Model migration
72
91
 
73
- Add **role_id:integer** to User Model Migration
92
+ Add **role_id:integer** field to your User Model
74
93
 
75
- ``` ruby
76
- rake the_role_engine:install:migrations
77
- >> Copied migration 20111028145956_create_roles.rb from the_role_engine
94
+ ```ruby
95
+ def self.up
96
+ create_table :users do |t|
97
+ t.string :login, :null => false
98
+ t.string :email, :default => nil
99
+ t.string :crypted_password, :default => nil
100
+ t.string :salt, :default => nil
101
+
102
+ t.integer :role_id, :default => nil
103
+
104
+ t.timestamps
105
+ end
106
+ end
78
107
  ```
79
108
 
109
+ #### Generate Role Model without migration
110
+
80
111
  ``` ruby
81
112
  rails g model role --migration=false
82
113
  ```
83
114
 
115
+ #### Generate Role migration
116
+
84
117
  ``` ruby
85
- rake db:create && rake db:migrate
118
+ rake the_role_engine:install:migrations
86
119
  ```
87
120
 
88
- ### Fake roles for test (not required)
121
+ #### Create database and migrate
122
+
123
+ ``` ruby
124
+ rake db:create && rake db:migrate
125
+ ```
89
126
 
90
- Creating roles for test
127
+ #### Create fake roles for test (not required)
91
128
 
92
129
  ``` ruby
93
130
  rake db:roles:test
94
- >> Administrator, Moderator of pages, User, Demo
95
131
  ```
96
132
 
97
- ### Change your ApplicationController
133
+ #### Change your ApplicationController
98
134
 
99
135
  **Example for Devise2**
100
136
 
101
137
  ``` ruby
102
138
  class ApplicationController < ActionController::Base
139
+ include TheRole::Requires
140
+
103
141
  protect_from_forgery
104
142
 
105
143
  def access_denied
@@ -108,7 +146,6 @@ class ApplicationController < ActionController::Base
108
146
 
109
147
  alias_method :login_required, :authenticate_user!
110
148
  alias_method :role_access_denied, :access_denied
111
-
112
149
  end
113
150
  ```
114
151
 
@@ -119,7 +156,7 @@ Define aliases method for correctly work TheRole's controllers
119
156
  **access_denied** or any other method for processing access denied situation
120
157
 
121
158
 
122
- ### Using with any controller
159
+ #### Using with any controller
123
160
 
124
161
  ``` ruby
125
162
  class PagesController < ApplicationController
@@ -139,8 +176,37 @@ class PagesController < ApplicationController
139
176
  end
140
177
  ```
141
178
 
179
+ ### Ownership checking
180
+
142
181
  **owner_required** method require **@ownership_checking_object** variable, with cheked object.
143
182
 
183
+ You should to define **@ownership_checking_object** before invoke of **owner_required** method.
184
+
185
+ ### Using with Views
186
+
187
+ ```ruby
188
+ <% if @user.has_role?(:twitter, :button) %>
189
+ Twitter Button is Here
190
+ <% else %>
191
+ Access Denied
192
+ <% end %>
193
+ ```
194
+
195
+ ### Way to set default role for new User
196
+
197
+ ```ruby
198
+ class User
199
+ after_create :set_default_role
200
+
201
+ private
202
+
203
+ def set_default_role
204
+ self.role = Role.where(:name => :user).first
205
+ self.save
206
+ end
207
+ end
208
+ ```
209
+
144
210
  ### Who is Administrator?
145
211
 
146
212
  Administrator it's a user who can access any section and the rules of your application.
@@ -1,3 +1,4 @@
1
1
  //= require jquery
2
2
  //= require jquery_ujs
3
+ //= require bootstrap-alert
3
4
  //= require bootstrap-dropdown
@@ -0,0 +1,90 @@
1
+ /* ==========================================================
2
+ * bootstrap-alert.js v2.0.4
3
+ * http://twitter.github.com/bootstrap/javascript.html#alerts
4
+ * ==========================================================
5
+ * Copyright 2012 Twitter, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ * ========================================================== */
19
+
20
+
21
+ !function ($) {
22
+
23
+ "use strict"; // jshint ;_;
24
+
25
+
26
+ /* ALERT CLASS DEFINITION
27
+ * ====================== */
28
+
29
+ var dismiss = '[data-dismiss="alert"]'
30
+ , Alert = function (el) {
31
+ $(el).on('click', dismiss, this.close)
32
+ }
33
+
34
+ Alert.prototype.close = function (e) {
35
+ var $this = $(this)
36
+ , selector = $this.attr('data-target')
37
+ , $parent
38
+
39
+ if (!selector) {
40
+ selector = $this.attr('href')
41
+ selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
42
+ }
43
+
44
+ $parent = $(selector)
45
+
46
+ e && e.preventDefault()
47
+
48
+ $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
49
+
50
+ $parent.trigger(e = $.Event('close'))
51
+
52
+ if (e.isDefaultPrevented()) return
53
+
54
+ $parent.removeClass('in')
55
+
56
+ function removeElement() {
57
+ $parent
58
+ .trigger('closed')
59
+ .remove()
60
+ }
61
+
62
+ $.support.transition && $parent.hasClass('fade') ?
63
+ $parent.on($.support.transition.end, removeElement) :
64
+ removeElement()
65
+ }
66
+
67
+
68
+ /* ALERT PLUGIN DEFINITION
69
+ * ======================= */
70
+
71
+ $.fn.alert = function (option) {
72
+ return this.each(function () {
73
+ var $this = $(this)
74
+ , data = $this.data('alert')
75
+ if (!data) $this.data('alert', (data = new Alert(this)))
76
+ if (typeof option == 'string') data[option].call($this)
77
+ })
78
+ }
79
+
80
+ $.fn.alert.Constructor = Alert
81
+
82
+
83
+ /* ALERT DATA-API
84
+ * ============== */
85
+
86
+ $(function () {
87
+ $('body').on('click.alert.data-api', dismiss, Alert.prototype.close)
88
+ })
89
+
90
+ }(window.jQuery);
@@ -0,0 +1,29 @@
1
+ // CLOSE ICONS
2
+ // -----------
3
+
4
+ .close {
5
+ float: right;
6
+ font-size: 20px;
7
+ font-weight: bold;
8
+ line-height: @baseLineHeight;
9
+ color: @black;
10
+ text-shadow: 0 1px 0 rgba(255,255,255,1);
11
+ .opacity(20);
12
+ &:hover {
13
+ color: @black;
14
+ text-decoration: none;
15
+ cursor: pointer;
16
+ .opacity(40);
17
+ }
18
+ }
19
+
20
+ // Additional properties for button version
21
+ // iOS requires the button element instead of an anchor tag.
22
+ // If you want the anchor version, it requires `href="#"`.
23
+ button.close {
24
+ padding: 0;
25
+ cursor: pointer;
26
+ background: transparent;
27
+ border: 0;
28
+ -webkit-appearance: none;
29
+ }
@@ -11,6 +11,8 @@
11
11
 
12
12
  @import "forms.less";
13
13
  @import "wells.less";
14
+ @import "alerts.less";
15
+ @import "close.less";
14
16
 
15
17
  .well{
16
18
  input{
@@ -11,19 +11,19 @@ class Admin::RoleSectionsController < ApplicationController
11
11
  def create
12
12
  if @role.create_section params[:section_name]
13
13
  flash[:notice] = t 'the_role.section_created'
14
- redirect_to edit_admin_role_path @role
15
14
  else
16
- render :action => :edit
15
+ flash[:error] = t 'the_role.section_not_created'
17
16
  end
17
+ redirect_to_edit
18
18
  end
19
19
 
20
20
  def create_rule
21
21
  if @role.create_rule params[:section_name], params[:rule_name]
22
- flash[:notice] = t 'the_role.section_created'
23
- redirect_to edit_admin_role_path @role
22
+ flash[:notice] = t 'the_role.section_rule_created'
24
23
  else
25
- render :action => :edit
24
+ flash[:error] = t 'the_role.section_rule_not_created'
26
25
  end
26
+ redirect_to_edit
27
27
  end
28
28
 
29
29
  def rule_on
@@ -31,10 +31,10 @@ class Admin::RoleSectionsController < ApplicationController
31
31
  rule_name = params[:name]
32
32
  if @role.rule_on section_name, rule_name
33
33
  flash[:notice] = t 'the_role.section_rule_on'
34
- redirect_to edit_admin_role_path @role
35
34
  else
36
- render :action => :edit
35
+ flash[:error] = t 'the_role.section_rule_state_not_changed'
37
36
  end
37
+ redirect_to_edit
38
38
  end
39
39
 
40
40
  def rule_off
@@ -42,20 +42,20 @@ class Admin::RoleSectionsController < ApplicationController
42
42
  rule_name = params[:name]
43
43
  if @role.rule_off section_name, rule_name
44
44
  flash[:notice] = t 'the_role.section_rule_off'
45
- redirect_to edit_admin_role_path @role
46
45
  else
47
- render :action => :edit
46
+ flash[:error] = t 'the_role.section_rule_state_not_changed'
48
47
  end
48
+ redirect_to_edit
49
49
  end
50
50
 
51
51
  def destroy
52
52
  section_name = params[:id]
53
53
  if @role.delete_section section_name
54
54
  flash[:notice] = t 'the_role.section_deleted'
55
- redirect_to edit_admin_role_path @role
56
55
  else
57
- render :action => :edit
58
- end
56
+ flash[:error] = t 'the_role.section_not_deleted'
57
+ end
58
+ redirect_to_edit
59
59
  end
60
60
 
61
61
  def destroy_rule
@@ -63,10 +63,10 @@ class Admin::RoleSectionsController < ApplicationController
63
63
  rule_name = params[:name]
64
64
  if @role.delete_rule section_name, rule_name
65
65
  flash[:notice] = t 'the_role.section_rule_deleted'
66
- redirect_to edit_admin_role_path @role
67
66
  else
68
- render :action => :edit
67
+ flash[:error] = t 'the_role.section_rule_not_deleted'
69
68
  end
69
+ redirect_to_edit
70
70
  end
71
71
 
72
72
  protected
@@ -75,4 +75,8 @@ class Admin::RoleSectionsController < ApplicationController
75
75
  @role = Role.find params[:role_id]
76
76
  @ownership_checking_object = @role
77
77
  end
78
+
79
+ def redirect_to_edit
80
+ redirect_to edit_admin_role_path @role
81
+ end
78
82
  end
@@ -16,9 +16,18 @@
16
16
  User: #{current_user.try(:name) || current_user.id}
17
17
  .crusty
18
18
  .container
19
+
20
+ - if flash[:notice]
21
+ .alert.alert-block
22
+ %a.close{:href => '#', 'data-dismiss' => :alert } &times;
23
+ = flash[:notice]
24
+
25
+ - if flash[:error]
26
+ .alert.alert-error
27
+ %a.close{:href => '#', 'data-dismiss' => :alert } &times;
28
+ = flash[:error]
19
29
  .row
20
30
  .span3
21
31
  .sidebar= yield :sidebar
22
32
  .span9
23
- .content= yield
24
-
33
+ .content= yield
@@ -5,6 +5,7 @@ en:
5
5
  name_presence: Set the role name
6
6
  title_presence: Set title of role
7
7
  section_created: Section is successfully created
8
+ section_not_created: Section is not created
8
9
  section_rule_created: In a given group is successfully created an access rule
9
10
  section_deleted: access rule is removed
10
11
  section_rule_deleted: access rule is removed
@@ -0,0 +1,41 @@
1
+ es:
2
+ the_role:
3
+ name_presence: Define el nombre del rol
4
+ title_presence: Definir el titulo del rol
5
+ section_created: "Sección creada exitosamente"
6
+ section_rule_created: En un grupo determinado se ha creado un rol de acceso exitosamente
7
+ section_deleted: regla de acceso eliminada
8
+ section_rule_deleted: regla de acceso eliminada
9
+ section_name_is_wrong: Nombre de rol erroneo
10
+ section_rule_wrong_name: Nombre de regla erroneo
11
+ section_name_is_blank: "El nombre del equipo de roles esta vacía"
12
+ section_exists: "La sección ya existe"
13
+ role_created: El Rol ha sido establecido exitosamente
14
+ role_updated: Rol actualizado exitosamente
15
+ delete_role: Esto puede ser un gran problema. ¿Eliminar este rol?
16
+ admin:
17
+ roles:
18
+ index:
19
+ list: lista de roles
20
+ delete: 'Borrar Rol'
21
+ new: Crear un nuevo rol
22
+ edit:
23
+ title: Editar rol
24
+ back: '← A la lista de roles'
25
+ name: 'Nombre del rol -'
26
+ create_section: "Crear una Sección"
27
+ create_access_rule: Crear una regla de acceso
28
+ create_rule: Nueva Regla
29
+ section_needs: "Crear al menos una sección"
30
+ update: Actualizar
31
+ form:
32
+ destroy_section_confirm: "¿Eliminar una sección de roles?"
33
+ empty: "No hay una sección de roles"
34
+ delete_rule_confirm: ¿Eliminar la regla de acceso?
35
+ delete: Eliminar
36
+ new:
37
+ back: '← A la lista de roles'
38
+ create: Crear un nuevo rol
39
+ name: Nombre del rol (Latin)
40
+ title: Titulo del rol
41
+ new: Crear
@@ -1,3 +1,3 @@
1
1
  module TheRole
2
- VERSION = "1.6.2"
2
+ VERSION = "1.6.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_role
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-19 00:00:00.000000000 Z
12
+ date: 2012-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml
16
- requirement: &15241260 !ruby/object:Gem::Requirement
16
+ requirement: &11730300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *15241260
24
+ version_requirements: *11730300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sass
27
- requirement: &15240720 !ruby/object:Gem::Requirement
27
+ requirement: &11729380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *15240720
35
+ version_requirements: *11729380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sass-rails
38
- requirement: &15239980 !ruby/object:Gem::Requirement
38
+ requirement: &11822780 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *15239980
46
+ version_requirements: *11822780
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: coffee-rails
49
- requirement: &15255560 !ruby/object:Gem::Requirement
49
+ requirement: &11821140 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *15255560
57
+ version_requirements: *11821140
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: therubyracer
60
- requirement: &15254860 !ruby/object:Gem::Requirement
60
+ requirement: &11819800 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *15254860
68
+ version_requirements: *11819800
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: less-rails
71
- requirement: &15254180 !ruby/object:Gem::Requirement
71
+ requirement: &11818680 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *15254180
79
+ version_requirements: *11818680
80
80
  description: Authorization lib for Rails 3 with Web Interface, aka CanCan killer
81
81
  email:
82
82
  - zykin-ilya@ya.ru
@@ -92,11 +92,13 @@ files:
92
92
  - README.md
93
93
  - Rakefile
94
94
  - app/assets/javascripts/admin_the_role.js
95
+ - app/assets/javascripts/bootstrap-alert.js
95
96
  - app/assets/javascripts/bootstrap-dropdown.js
96
97
  - app/assets/stylesheets/admin_the_role.css
97
98
  - app/assets/stylesheets/alerts.less
98
99
  - app/assets/stylesheets/button-groups.less
99
100
  - app/assets/stylesheets/buttons.less
101
+ - app/assets/stylesheets/close.less
100
102
  - app/assets/stylesheets/custom.scss
101
103
  - app/assets/stylesheets/dropdowns.less
102
104
  - app/assets/stylesheets/forms.less
@@ -120,6 +122,7 @@ files:
120
122
  - app/views/admin/roles/new.html.haml
121
123
  - app/views/layouts/the_role.html.haml
122
124
  - config/locales/en.yml
125
+ - config/locales/es.yml
123
126
  - config/locales/ru.yml
124
127
  - config/routes.rb
125
128
  - db/migrate/20111025025129_create_roles.rb