the_role 2.5.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +178 -526
- data/gem_version.rb +3 -0
- data/lib/the_role/version.rb +1 -3
- data/lib/the_role.rb +3 -41
- data/the_role.gemspec +5 -5
- metadata +20 -231
- data/.ruby-gemset.example +0 -1
- data/.ruby-version.example +0 -1
- data/.rvmrc.example +0 -1
- data/.travis.yml +0 -5
- data/Bye_bye_CanCan_I_got_the_Role.png +0 -0
- data/app/controllers/admin/role_sections_controller.rb +0 -90
- data/app/controllers/admin/roles_controller.rb +0 -74
- data/app/controllers/concerns/controller.rb +0 -23
- data/app/models/_templates_/role.rb +0 -3
- data/app/models/concerns/base.rb +0 -37
- data/app/models/concerns/role.rb +0 -156
- data/app/models/concerns/user.rb +0 -57
- data/config/locales/en.yml +0 -44
- data/config/locales/es.yml +0 -42
- data/config/locales/nl.yml +0 -44
- data/config/locales/pl.yml +0 -43
- data/config/locales/pt_BR.yml +0 -43
- data/config/locales/ru.yml +0 -43
- data/config/locales/zh_CN.yml +0 -42
- data/config/routes.rb +0 -23
- data/db/migrate/20111025025129_create_roles.rb +0 -23
- data/docs/2.1.1.png +0 -0
- data/lib/generators/the_role/USAGE +0 -32
- data/lib/generators/the_role/templates/the_role.rb +0 -11
- data/lib/generators/the_role/the_role_generator.rb +0 -64
- data/lib/tasks/roles.rake +0 -137
- data/lib/the_role/activerecord.rb +0 -11
- data/lib/the_role/config.rb +0 -30
- data/lib/the_role/hash.rb +0 -58
- data/lib/the_role/the_class_exists.rb +0 -8
- data/pic.png +0 -0
- data/spec/dummy_app/.gitignore +0 -18
- data/spec/dummy_app/.rspec +0 -1
- data/spec/dummy_app/Gemfile +0 -43
- data/spec/dummy_app/README.md +0 -39
- data/spec/dummy_app/Rakefile +0 -6
- data/spec/dummy_app/app/assets/images/.keep +0 -0
- data/spec/dummy_app/app/assets/javascripts/application.js +0 -17
- data/spec/dummy_app/app/assets/stylesheets/app/style.css.scss +0 -23
- data/spec/dummy_app/app/assets/stylesheets/application.css +0 -3
- data/spec/dummy_app/app/controllers/application_controller.rb +0 -38
- data/spec/dummy_app/app/controllers/concerns/.keep +0 -0
- data/spec/dummy_app/app/controllers/pages_controller.rb +0 -75
- data/spec/dummy_app/app/controllers/users_controller.rb +0 -32
- data/spec/dummy_app/app/controllers/welcome_controller.rb +0 -13
- data/spec/dummy_app/app/helpers/application_helper.rb +0 -2
- data/spec/dummy_app/app/mailers/.keep +0 -0
- data/spec/dummy_app/app/models/.keep +0 -0
- data/spec/dummy_app/app/models/concerns/.keep +0 -0
- data/spec/dummy_app/app/models/page.rb +0 -24
- data/spec/dummy_app/app/models/role.rb +0 -4
- data/spec/dummy_app/app/models/user.rb +0 -21
- data/spec/dummy_app/app/views/layouts/_current_user_info.html.haml +0 -17
- data/spec/dummy_app/app/views/layouts/application.html.haml +0 -68
- data/spec/dummy_app/app/views/pages/_form.html.haml +0 -19
- data/spec/dummy_app/app/views/pages/edit.html.haml +0 -7
- data/spec/dummy_app/app/views/pages/index.html.haml +0 -27
- data/spec/dummy_app/app/views/pages/manage.html.haml +0 -23
- data/spec/dummy_app/app/views/pages/my.html.haml +0 -10
- data/spec/dummy_app/app/views/pages/new.html.haml +0 -5
- data/spec/dummy_app/app/views/pages/show.html.haml +0 -15
- data/spec/dummy_app/app/views/users/edit.html.haml +0 -34
- data/spec/dummy_app/app/views/welcome/index.html.haml +0 -38
- data/spec/dummy_app/app/views/welcome/profile.html.haml +0 -2
- data/spec/dummy_app/bin/bundle +0 -3
- data/spec/dummy_app/bin/rails +0 -4
- data/spec/dummy_app/bin/rake +0 -4
- data/spec/dummy_app/config/application.rb +0 -25
- data/spec/dummy_app/config/boot.rb +0 -4
- data/spec/dummy_app/config/database.yml +0 -17
- data/spec/dummy_app/config/environment.rb +0 -5
- data/spec/dummy_app/config/environments/development.rb +0 -29
- data/spec/dummy_app/config/environments/production.rb +0 -80
- data/spec/dummy_app/config/environments/test.rb +0 -36
- data/spec/dummy_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy_app/config/initializers/devise.rb +0 -227
- data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy_app/config/initializers/inflections.rb +0 -16
- data/spec/dummy_app/config/initializers/mime_types.rb +0 -5
- data/spec/dummy_app/config/initializers/secret_token.rb +0 -12
- data/spec/dummy_app/config/initializers/session_store.rb +0 -3
- data/spec/dummy_app/config/initializers/the_role.rb +0 -6
- data/spec/dummy_app/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy_app/config/locales/devise.en.yml +0 -57
- data/spec/dummy_app/config/locales/en.yml +0 -7
- data/spec/dummy_app/config/locales/ru.yml +0 -4
- data/spec/dummy_app/config/routes.rb +0 -26
- data/spec/dummy_app/config.ru +0 -4
- data/spec/dummy_app/db/migrate/20120212061952_devise_create_users.rb +0 -63
- data/spec/dummy_app/db/migrate/20120212063249_create_roles.rb +0 -18
- data/spec/dummy_app/db/migrate/20120314061307_create_pages.rb +0 -14
- data/spec/dummy_app/db/schema.rb +0 -59
- data/spec/dummy_app/db/seeds.rb +0 -85
- data/spec/dummy_app/lib/assets/.keep +0 -0
- data/spec/dummy_app/lib/tasks/.keep +0 -0
- data/spec/dummy_app/lib/tasks/assets.rake +0 -15
- data/spec/dummy_app/lib/tasks/db_bootstrap.rake +0 -16
- data/spec/dummy_app/log/.keep +0 -0
- data/spec/dummy_app/public/404.html +0 -58
- data/spec/dummy_app/public/422.html +0 -58
- data/spec/dummy_app/public/500.html +0 -57
- data/spec/dummy_app/public/favicon.ico +0 -0
- data/spec/dummy_app/public/robots.txt +0 -5
- data/spec/dummy_app/spec/controllers/admin_roles_controller_spec.rb +0 -52
- data/spec/dummy_app/spec/controllers/pages_controller_spec.rb +0 -141
- data/spec/dummy_app/spec/controllers/welcome_controller_spec.rb +0 -66
- data/spec/dummy_app/spec/factories/page.rb +0 -6
- data/spec/dummy_app/spec/factories/role.rb +0 -55
- data/spec/dummy_app/spec/factories/user.rb +0 -11
- data/spec/dummy_app/spec/models/hash_spec.rb +0 -272
- data/spec/dummy_app/spec/models/param_process_spec.rb +0 -39
- data/spec/dummy_app/spec/models/role_spec.rb +0 -218
- data/spec/dummy_app/spec/models/user_spec.rb +0 -164
- data/spec/dummy_app/spec/routing/admin_roles_routing_spec.rb +0 -41
- data/spec/dummy_app/spec/routing/pages_routing_spec.rb +0 -35
- data/spec/dummy_app/spec/spec_helper.rb +0 -68
- data/spec/dummy_app/vendor/assets/javascripts/.keep +0 -0
- data/spec/dummy_app/vendor/assets/stylesheets/.keep +0 -0
- data/the_role.yml.teamocil.example +0 -11
data/README.md
CHANGED
@@ -1,541 +1,193 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
<h2 align="center" class='center' style="text-align:center">
|
2
|
+
TheRole 3.0
|
3
|
+
</h2>
|
4
|
+
|
5
|
+
<p align="center" class='center' style="text-align:center">
|
6
|
+
<b>Authorization gem for Ruby on Rails</b><br>
|
7
|
+
<i>with <a href="https://github.com/TheRole/TheRoleManagementPanelBootstrap3">Management Panel</a></i>
|
8
|
+
</p>
|
9
|
+
|
10
|
+
<p align="center" class='center' style="text-align:center">
|
11
|
+
<img src="https://raw.githubusercontent.com/TheRole/docs/master/images/the_role.png" alt="TheRole. Authorization gem for Ruby on Rails with Administrative interface">
|
12
|
+
</p>
|
13
|
+
|
14
|
+
<p align="center" class='center' style="text-align:center">
|
15
|
+
<b>Semantic. Flexible. Lightweigh</b>
|
16
|
+
</p>
|
17
|
+
|
18
|
+
<div align="center" class='center' style="text-align:center">
|
19
|
+
|
20
|
+
<a href="http://badge.fury.io/rb/the_role"><img src="https://badge.fury.io/rb/the_role.svg" alt="Gem Version" height="18"></a>
|
21
|
+
|
22
|
+
<a href="https://travis-ci.org/TheRole/DummyApp"><img src="https://travis-ci.org/TheRole/DummyApp.svg?branch=master" alt="Build Status" height="18"></a>
|
23
|
+
|
24
|
+
<a href="https://codeclimate.com/github/TheRole/TheRoleApi"><img src="https://codeclimate.com/github/TheRole/TheRoleApi/badges/gpa.svg" /></a>
|
25
|
+
|
26
|
+
<a href="https://www.ruby-toolbox.com/categories/rails_authorization">ruby-toolbox</a>
|
27
|
+
|
28
|
+
<p>
|
29
|
+
Strongly recommended <a href='https://github.com/TheRole/docs/blob/master/MigrationsFromV2.md'>to upgrade from TheRole2 to TheRole3</a>. Please, do it ASAP.
|
30
|
+
</p>
|
31
|
+
</div>
|
6
32
|
|
7
33
|
### INTRO
|
8
34
|
|
9
|
-
|
10
|
-
<tr>
|
11
|
-
<th align="left">Bye bye CanCan, I got The Role!</th>
|
12
|
-
<th align="left">Description</th>
|
13
|
-
</tr>
|
14
|
-
<tr>
|
15
|
-
<td><img src="https://github.com/the-teacher/the_role/raw/master/Bye_bye_CanCan_I_got_the_Role.png" alt="Bye bye CanCan, I got The Role!"></td>
|
16
|
-
<td>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 stored in the database as a JSON string.<br><br>TheRole - Semantic, lightweight role system with an administrative interface.<br><br>Role is a two-level hash, consisting of the <b>sections</b> and nested <b>rules</b>.<br><br>A <b>Section</b> may be associated with a <b>controller</b> name.<br><br>A <b>Rule</b> may be associated with an <b>action</b> name.<br><br>A Section can have many rules.<br><br>A Rule can be <b>true</b> or <b>false</b>.<br><br><b>Sections</b> and nested <b>Rules</b> provide an <b>ACL</b> (<b>Access Control List</b>)<br><br><br>Using hashes, makes role system extremely easy to configure and use.<br></td>
|
17
|
-
</tr>
|
18
|
-
</table>
|
35
|
+
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 **stored in the database as a JSON string**.
|
19
36
|
|
20
|
-
|
37
|
+
<p align="center" class='center' style="text-align:center">
|
38
|
+
<img src="https://raw.githubusercontent.com/TheRole/docs/master/images/hash2string.png" alt="TheRole. Authorization gem for Ruby on Rails with Administrative interface">
|
39
|
+
</p>
|
21
40
|
|
22
|
-
|
41
|
+
Using hashes, makes role system extremely easy to configure and use
|
23
42
|
|
24
|
-
|
43
|
+
* Any Role is a two-level hash, consisting of the <b>sections</b> and nested <b>rules</b>
|
44
|
+
* A <b>Section</b> may be associated with a <b>controller</b> name
|
45
|
+
* A <b>Rule</b> may be associated with an <b>action</b> name
|
46
|
+
* A Section can have many rules
|
47
|
+
* A Rule can be <b>true</b> or <b>false</b>
|
48
|
+
* <b>Sections</b> and nested <b>Rules</b> provide an <b>ACL</b> (<b>Access Control List</b>)
|
25
49
|
|
26
|
-
|
50
|
+
#### Management Panel
|
27
51
|
|
28
52
|
<table>
|
29
53
|
<tr>
|
30
|
-
<td>
|
54
|
+
<td>
|
55
|
+
<b>http://localhost:3000/admin/roles</b>
|
56
|
+
</td>
|
31
57
|
</tr>
|
32
58
|
<tr>
|
33
|
-
<td
|
59
|
+
<td>
|
60
|
+
<img src="https://raw.githubusercontent.com/TheRole/docs/master/images/gui.png?2" alt="TheRole GUI">
|
61
|
+
</td>
|
34
62
|
</tr>
|
35
63
|
</table>
|
36
64
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
=
|
41
|
-
=
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
https://github.com/
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
```
|
168
|
-
bundle exec rails g the_role admin
|
169
|
-
```
|
170
|
-
|
171
|
-
Makes any user as Admin
|
172
|
-
|
173
|
-
```
|
174
|
-
User.first.update( role: Role.with_name(:admin) )
|
175
|
-
```
|
176
|
-
|
177
|
-
## Integration
|
178
|
-
|
179
|
-
#### Change your ApplicationController
|
180
|
-
|
181
|
-
**include TheRoleController** in your Application controller
|
182
|
-
|
183
|
-
```ruby
|
184
|
-
class ApplicationController < ActionController::Base
|
185
|
-
include TheRole::Controller
|
186
|
-
|
187
|
-
protect_from_forgery
|
188
|
-
|
189
|
-
def access_denied
|
190
|
-
flash[:error] = t('the_role.access_denied')
|
191
|
-
redirect_to(:back)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
```
|
195
|
-
|
196
|
-
#### Mount routes
|
197
|
-
|
198
|
-
config/routes.rb
|
199
|
-
|
200
|
-
```ruby
|
201
|
-
concern :the_role, TheRole::AdminRoutes.new
|
202
|
-
|
203
|
-
namespace :admin do
|
204
|
-
concerns :the_role
|
205
|
-
end
|
206
|
-
```
|
207
|
-
|
208
|
-
### Configuration
|
209
|
-
|
210
|
-
create the_role config:
|
211
|
-
|
212
|
-
```
|
213
|
-
bundle exec rails g the_role config
|
214
|
-
```
|
215
|
-
|
216
|
-
**config/initializers/the_role.rb**
|
217
|
-
|
218
|
-
```ruby
|
219
|
-
TheRole.configure do |config|
|
220
|
-
config.layout = :application
|
221
|
-
config.default_user_role = :user
|
222
|
-
config.access_denied_method = :access_denied # define it in ApplicationController
|
223
|
-
config.login_required_method = :authenticate_user! # devise auth method
|
224
|
-
|
225
|
-
# config.first_user_should_be_admin = false
|
226
|
-
# config.destroy_strategy = :restrict_with_exception # can be nil
|
227
|
-
end
|
228
|
-
```
|
229
|
-
|
230
|
-
#### Usage with any controller
|
231
|
-
|
232
|
-
```ruby
|
233
|
-
class PagesController < ApplicationController
|
234
|
-
before_action :login_required, except: [:index, :show]
|
235
|
-
before_action :role_required, except: [:index, :show]
|
236
|
-
|
237
|
-
before_action :set_page, only: [:edit, :update, :destroy]
|
238
|
-
before_action :owner_required, only: [:edit, :update, :destroy]
|
239
|
-
|
240
|
-
def edit
|
241
|
-
# ONLY OWNER CAN EDIT THIS PAGE
|
242
|
-
end
|
243
|
-
|
244
|
-
private
|
245
|
-
|
246
|
-
def set_page
|
247
|
-
@page = Page.find params[:id]
|
248
|
-
|
249
|
-
# TheRole: You should define OWNER CHECK OBJECT
|
250
|
-
# When editable object was found
|
251
|
-
# You should define @owner_check_object before invoking **owner_required** method
|
252
|
-
@owner_check_object = @page
|
253
|
-
end
|
254
|
-
end
|
255
|
-
```
|
256
|
-
|
257
|
-
**integration with Inhirited Resource**
|
258
|
-
|
259
|
-
```ruby
|
260
|
-
def owner_required
|
261
|
-
@owner_check_object = resource
|
262
|
-
super
|
263
|
-
end
|
264
|
-
```
|
265
|
-
|
266
|
-
## Understanding
|
267
|
-
|
268
|
-
#### TheRole instead of CanCan?
|
269
|
-
|
270
|
-
TheRole, in contrast to CanCan, has a simple and predefined way to find the access state of the current role. If you don't want to create your own role scheme with CanCan Abilities - TheRole can be a great solution for you.
|
271
|
-
|
272
|
-
You can manage roles with a simple UI. TheRole's ACL structure is inspired by Rails' controllers, that's why it's so great for Rails applications.
|
273
|
-
|
274
|
-
#### What does semantic mean?
|
275
|
-
|
276
|
-
Semantic - the science of meaning. Humans should be able to quickly understand what is happening in a role system.
|
277
|
-
|
278
|
-
Look at the next Role hash. If you can understand access rules - this authorization system is semantic.
|
279
|
-
|
280
|
-
```ruby
|
281
|
-
role = {
|
282
|
-
'pages' => {
|
283
|
-
'index' => true,
|
284
|
-
'show' => true,
|
285
|
-
'new' => false,
|
286
|
-
'edit' => false,
|
287
|
-
'update' => false,
|
288
|
-
'destroy' => false
|
289
|
-
},
|
290
|
-
'articles' => {
|
291
|
-
'index' => true,
|
292
|
-
'show' => true
|
293
|
-
},
|
294
|
-
'twitter' => {
|
295
|
-
'button' => true,
|
296
|
-
'follow' => false
|
297
|
-
}
|
298
|
-
}
|
299
|
-
```
|
300
|
-
|
301
|
-
#### Virtual sections and rules
|
302
|
-
|
303
|
-
Usually, we use real names of controllers and actions for names of sections and rules:
|
304
|
-
|
305
|
-
```ruby
|
306
|
-
@user.has_role?(:pages, :show)
|
307
|
-
```
|
308
|
-
|
309
|
-
But, also, you can use virtual names of sections, and virtual names of section's rules.
|
310
|
-
|
311
|
-
```ruby
|
312
|
-
@user.has_role?(:twitter, :button)
|
313
|
-
@user.has_role?(:facebook, :like)
|
314
|
-
```
|
315
|
-
|
316
|
-
And you can use them as well as other access rules.
|
317
|
-
|
318
|
-
#### Usage within Views
|
319
|
-
|
320
|
-
```ruby
|
321
|
-
<% if @user.has_role?(:twitter, :button) %>
|
322
|
-
Twitter Button is Here
|
323
|
-
<% else %>
|
324
|
-
Nothing here :(
|
325
|
-
<% end %>
|
326
|
-
```
|
327
|
-
|
328
|
-
#### Who is Administrator?
|
329
|
-
|
330
|
-
Administrator is the user who can access any section and rules of your application.
|
331
|
-
|
332
|
-
Administrator is the owner of any objects in your application.
|
333
|
-
|
334
|
-
Administrator is the user, who has a virtual section **system** and a rule **administrator** in the role-hash.
|
335
|
-
|
336
|
-
|
337
|
-
```ruby
|
338
|
-
admin_role_fragment = {
|
339
|
-
:system => {
|
340
|
-
:administrator => true
|
341
|
-
}
|
342
|
-
}
|
343
|
-
```
|
344
|
-
|
345
|
-
#### Who is Moderator?
|
346
|
-
|
347
|
-
Moderator is the user, who has access to any actions of some section(s).
|
348
|
-
|
349
|
-
Moderator is the owner of any objects of some class.
|
350
|
-
|
351
|
-
Moderator is the user, who has a virtual section **moderator**, with **section name** as rule name.
|
352
|
-
|
353
|
-
An example of a Moderator of Pages (controller) and Twitter (virtual section)
|
354
|
-
|
355
|
-
```ruby
|
356
|
-
moderator_role_fragment = {
|
357
|
-
:moderator => {
|
358
|
-
:pages => true,
|
359
|
-
:blogs => false,
|
360
|
-
:twitter => true
|
361
|
-
}
|
362
|
-
}
|
363
|
-
```
|
364
|
-
|
365
|
-
#### Who is Owner?
|
366
|
-
|
367
|
-
Administrator is owner of any object in system.
|
368
|
-
|
369
|
-
Moderator of pages is owner of any page.
|
370
|
-
|
371
|
-
User is owner of objects, when **Object#user_id == User#id**.
|
372
|
-
|
373
|
-
|
374
|
-
# API
|
375
|
-
|
376
|
-
## User
|
377
|
-
|
378
|
-
```ruby
|
379
|
-
# User's role
|
380
|
-
@user.role # => Role obj
|
381
|
-
```
|
382
|
-
|
383
|
-
Is a user Administrator?
|
384
|
-
|
385
|
-
```ruby
|
386
|
-
@user.admin? => true | false
|
387
|
-
```
|
388
|
-
|
389
|
-
Is a user Moderator?
|
390
|
-
|
391
|
-
```ruby
|
392
|
-
@user.moderator?(:pages) => true | false
|
393
|
-
@user.moderator?(:blogs) => true | false
|
394
|
-
@user.moderator?(:articles) => true | false
|
395
|
-
```
|
396
|
-
|
397
|
-
Has user got access to **rule** of **section** (action of controller)?
|
398
|
-
|
399
|
-
```ruby
|
400
|
-
@user.has_role?(:pages, :show) => true | false
|
401
|
-
@user.has_role?(:blogs, :new) => true | false
|
402
|
-
@user.has_role?(:articles, :edit) => true | false
|
403
|
-
|
404
|
-
# return true if one of roles is true
|
405
|
-
@user.any_role?(pages: :show, posts: :show) => true | false
|
406
|
-
```
|
407
|
-
|
408
|
-
Is user **Owner** of object?
|
409
|
-
|
410
|
-
```ruby
|
411
|
-
@user.owner?(@page) => true | false
|
412
|
-
@user.owner?(@blog) => true | false
|
413
|
-
@user.owner?(@article) => true | false
|
414
|
-
```
|
415
|
-
|
416
|
-
## Role
|
417
|
-
|
418
|
-
```ruby
|
419
|
-
# Find a Role by name
|
420
|
-
@role = Role.with_name(:user)
|
421
|
-
```
|
422
|
-
|
423
|
-
```ruby
|
424
|
-
@role.has?(:pages, :show) => true | false
|
425
|
-
@role.moderator?(:pages) => true | false
|
426
|
-
@role.admin? => true | false
|
427
|
-
|
428
|
-
# return true if one of roles is true
|
429
|
-
@role.any?(pages: :show, posts: :show) => true | false
|
430
|
-
```
|
431
|
-
|
432
|
-
#### CREATE
|
433
|
-
|
434
|
-
```ruby
|
435
|
-
# Create a section of rules
|
436
|
-
@role.create_section(:pages)
|
437
|
-
```
|
438
|
-
|
439
|
-
```ruby
|
440
|
-
# Create rule in section (false value by default)
|
441
|
-
@role.create_rule(:pages, :index)
|
442
|
-
```
|
443
|
-
|
444
|
-
#### READ
|
445
|
-
|
446
|
-
```ruby
|
447
|
-
@role.to_hash => Hash
|
448
|
-
|
449
|
-
# JSON string
|
450
|
-
@role.to_json => String
|
451
|
-
|
452
|
-
# check method
|
453
|
-
@role.has_section?(:pages) => true | false
|
454
|
-
```
|
455
|
-
|
456
|
-
#### UPDATE
|
457
|
-
|
458
|
-
```ruby
|
459
|
-
# set this rule on
|
460
|
-
@role.rule_on(:pages, :index)
|
461
|
-
```
|
462
|
-
|
463
|
-
```ruby
|
464
|
-
# set this rule off
|
465
|
-
@role.rule_off(:pages, :index)
|
466
|
-
```
|
467
|
-
|
468
|
-
```ruby
|
469
|
-
# Incoming hash is true-mask-hash
|
470
|
-
# All the rules of the Role will be reset to false
|
471
|
-
# Only rules from true-mask-hash will be set true
|
472
|
-
new_role_hash = {
|
473
|
-
:pages => {
|
474
|
-
:index => true,
|
475
|
-
:show => true
|
476
|
-
}
|
477
|
-
}
|
478
|
-
|
479
|
-
@role.update_role(new_role_hash)
|
480
|
-
```
|
481
|
-
|
482
|
-
#### DELETE
|
483
|
-
|
484
|
-
```ruby
|
485
|
-
# delete a section
|
486
|
-
@role.delete_section(:pages)
|
487
|
-
|
488
|
-
# delete a rule in section
|
489
|
-
@role.delete_rule(:pages, :show)
|
490
|
-
```
|
491
|
-
|
492
|
-
#### Changelog
|
493
|
-
|
494
|
-
* 2.3.0 - Refactoring
|
495
|
-
* 2.1.0 - User#any_role? & Role#any?
|
496
|
-
* 2.0.3 - create role fix, cleanup
|
497
|
-
* 2.0.2 - code cleanup, readme
|
498
|
-
* 2.0.1 - code cleanup
|
499
|
-
* 2.0.0 - Rails 4 ready, configurable, tests
|
500
|
-
* 1.7.0 - mass assignment for User#role_id, doc, locales, changes in test app
|
501
|
-
* 1.6.9 - assets precompile addon
|
502
|
-
* 1.6.8 - doc, re dependencies
|
503
|
-
* 1.6.7 - Es locale (beta 0.2)
|
504
|
-
* 1.6.6 - Ru locale, localization (beta 0.1)
|
505
|
-
* 1.6.5 - has_section?, fixes, tests (alpha 0.3)
|
506
|
-
* 1.6.4 - En locale (alpha 0.2)
|
507
|
-
* 1.6.3 - notifications
|
508
|
-
* 1.6.0 - stabile release (alpha 0.1)
|
509
|
-
|
510
|
-
### i18n
|
511
|
-
|
512
|
-
**Ru, En** (by me)
|
513
|
-
|
514
|
-
**Es** by @igmarin
|
515
|
-
|
516
|
-
**zh_CN** by @doabit & @linjunpop
|
517
|
-
|
518
|
-
**PL** by @egb3
|
519
|
-
|
520
|
-
### MIT-LICENSE
|
521
|
-
|
522
|
-
##### Copyright (c) 2012-2014 [Ilya N.Zykin]
|
523
|
-
|
524
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
525
|
-
a copy of this software and associated documentation files (the
|
526
|
-
"Software"), to deal in the Software without restriction, including
|
527
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
528
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
529
|
-
permit persons to whom the Software is furnished to do so, subject to
|
530
|
-
the following conditions:
|
531
|
-
|
532
|
-
The above copyright notice and this permission notice shall be
|
533
|
-
included in all copies or substantial portions of the Software.
|
534
|
-
|
535
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
536
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
537
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
538
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
539
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
540
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
541
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
65
|
+
**Import/Export operations provided via TheRole Management Panel.** If you have 2 Rails apps, based on TheRole - you can move roles between them via export/import abilities of TheRole Management Panel.
|
66
|
+
It can be usefull for Rails apps based on one engine.
|
67
|
+
|
68
|
+
<div align="center" class='center' style="text-align:center">
|
69
|
+
<img src="https://raw.githubusercontent.com/TheRole/docs/master/images/import_export.png" alt="TheRole. Authorization gem for Ruby on Rails with Administrative interface">
|
70
|
+
</div>
|
71
|
+
|
72
|
+
#### Limitations by Design
|
73
|
+
|
74
|
+
TheRole uses few conventions over configuration.
|
75
|
+
It gives simplicity of code, but also some limitations.
|
76
|
+
You have to know about them before using of TheRole:
|
77
|
+
<a href="https://github.com/TheRole/docs/blob/master/Limitations.md">Limitations list</a>
|
78
|
+
|
79
|
+
<hr>
|
80
|
+
|
81
|
+
<div align="center" class='center' style="text-align:center">
|
82
|
+
<a href="https://github.com/TheRole/docs/blob/master/TheRoleInstallation.md">
|
83
|
+
<img src="https://raw.githubusercontent.com/TheRole/docs/master/images/install.png?2" alt="TheRole. Installation">
|
84
|
+
</a>
|
85
|
+
</div>
|
86
|
+
|
87
|
+
<div align="center" class='center' style="text-align:center">
|
88
|
+
<a href="https://github.com/TheRole/docs/blob/master/TheRoleAPI.md">
|
89
|
+
<img src="https://raw.githubusercontent.com/TheRole/docs/master/images/api.png" alt="TheRole API">
|
90
|
+
</a>
|
91
|
+
</div>
|
92
|
+
|
93
|
+
<div align="center" class='center' style="text-align:center">
|
94
|
+
<a href="https://github.com/TheRole/docs/blob/master/IntegrationWithRailsControllers.md">
|
95
|
+
<img src="https://raw.githubusercontent.com/TheRole/docs/master/images/int_ctrl.png" alt="Integration with Rails controllers">
|
96
|
+
</a>
|
97
|
+
</div>
|
98
|
+
|
99
|
+
<div align="center" class='center' style="text-align:center">
|
100
|
+
<a href="https://github.com/TheRole/docs/blob/master/IntegrationWithRailsViews.md">
|
101
|
+
<img src="https://raw.githubusercontent.com/TheRole/docs/master/images/int_views.png" alt="Integration with Rails views">
|
102
|
+
</a>
|
103
|
+
</div>
|
104
|
+
|
105
|
+
<div align="center" class='center' style="text-align:center">
|
106
|
+
<a href="https://github.com/TheRole/docs/blob/master/UsingWithStrongParameters.md">
|
107
|
+
<img src="https://raw.githubusercontent.com/TheRole/docs/master/images/int_params.png" alt="Using with Strong Parameters">
|
108
|
+
</a>
|
109
|
+
</div>
|
110
|
+
|
111
|
+
<div align="center" class='center' style="text-align:center">
|
112
|
+
<a href="https://github.com/TheRole/docs/blob/master/TheRoleGuiInstallation.md">
|
113
|
+
<img src="https://raw.githubusercontent.com/TheRole/docs/master/images/install_gui.png" alt="TheRole GUI. Installation">
|
114
|
+
</a>
|
115
|
+
</div>
|
116
|
+
|
117
|
+
<hr>
|
118
|
+
|
119
|
+
<div align="center" class='center' style="text-align:center">
|
120
|
+
<table>
|
121
|
+
<tbody>
|
122
|
+
<tr>
|
123
|
+
<td colspan="2">
|
124
|
+
<b>FAQ</b>
|
125
|
+
</td>
|
126
|
+
</tr>
|
127
|
+
|
128
|
+
<tr>
|
129
|
+
<td width="350px" valign="top" style='vertical-align:top'>
|
130
|
+
<p align="left" class="left" style="text-align:left"><a href='https://github.com/TheRole/docs/blob/master/FAQ.md#why-therole-was-created'>Why TheRole was created?</a></p>
|
131
|
+
<p align="left" class="left" style="text-align:left"><a href='https://github.com/TheRole/docs/blob/master/FAQ.md#who-is-administrator'>Who is Administrator?</a></p>
|
132
|
+
<p align="left" class="left" style="text-align:left"><a href='https://github.com/TheRole/docs/blob/master/FAQ.md#who-is-moderator'>Who is Moderator?</a></p>
|
133
|
+
<p align="left" class="left" style="text-align:left"><a href='https://github.com/TheRole/docs/blob/master/FAQ.md#who-is-owner'>Who is Owner?</a></p>
|
134
|
+
<p align="left" class="left" style="text-align:left"><a href='https://github.com/TheRole/docs/blob/master/Ownership.md'>Few words about Ownership</a></p>
|
135
|
+
<p align="left" class="left" style="text-align:left"><a href='https://github.com/TheRole/docs/blob/master/Customization.md'>Customization, Rake tasks, code generators</a></p>
|
136
|
+
</td>
|
137
|
+
|
138
|
+
<td width="350px" valign="top" style='vertical-align:top'>
|
139
|
+
<p align="left" class="left" style="text-align:left"><a href='https://github.com/TheRole/docs/blob/master/FAQ.md##what-does-it-mean-semantic'>What does it mean semantic?</a></p>
|
140
|
+
<p align="left" class="left" style="text-align:left"><a href='https://github.com/TheRole/docs/blob/master/FAQ.md#virtual-sections-and-rules'>Virtual sections and rules</a></p>
|
141
|
+
<p align="left" class="left" style="text-align:left"><a href='https://github.com/TheRole/docs/blob/master/Limitations.md'>Limitations</a></p>
|
142
|
+
<p align="left" class="left" style="text-align:left"><a href='https://github.com/TheRole/docs/blob/master/Contributing.md'>Contributing</a></p>
|
143
|
+
<p align="left" class="left" style="text-align:left"><a href='https://github.com/TheRole/docs/blob/master/MigrationsFromV2.md'>Migration form TheRole 2 to TheRole 3</a></p>
|
144
|
+
</td>
|
145
|
+
</tr>
|
146
|
+
</tbody>
|
147
|
+
</table>
|
148
|
+
</div>
|
149
|
+
|
150
|
+
<hr>
|
151
|
+
|
152
|
+
### We need your feedback!
|
153
|
+
|
154
|
+
If you have to say something about TheRole, or if you need help, there are few ways to contact us:
|
155
|
+
|
156
|
+
0. SKYPE: **ilya.killich**
|
157
|
+
0. Email: zykin-ilya@ya.ru
|
158
|
+
0. TWITTER: [@iam_teacher](https://twitter.com/iam_teacher)
|
159
|
+
0. Hash tag: [#the_role](https://twitter.com/hashtag/the_role)
|
160
|
+
0. Google group: [about the_role](https://groups.google.com/forum/#!forum/the_role)
|
161
|
+
|
162
|
+
<hr>
|
163
|
+
|
164
|
+
#### Test matrix
|
165
|
+
|
166
|
+
* **RAILS:** 3.2.21, 4.0, 4.1, 4.2
|
167
|
+
* **RUBY:** 1.9.3, 2.0, 2.1, 2.2
|
168
|
+
* **DB**: sqlite, mysql, postgresql
|
169
|
+
|
170
|
+
totally: 48 environments
|
171
|
+
|
172
|
+
<hr>
|
173
|
+
|
174
|
+
**Supported locales:**
|
175
|
+
[the_role_api](https://github.com/TheRole/the_role_api/tree/master/config/locales) |
|
176
|
+
[the_role_management_panel](https://github.com/TheRole/the_role_management_panel/tree/master/config/locales)
|
177
|
+
(please, help us with them)
|
178
|
+
<hr>
|
179
|
+
|
180
|
+
### MIT License
|
181
|
+
|
182
|
+
[MIT License](https://github.com/TheRole/docs/blob/master/LICENSE.md)
|
183
|
+
Copyright (c) 2012-2015 [Ilya N.Zykin](https://github.com/the-teacher)
|
184
|
+
|
185
|
+
#### Maintainers
|
186
|
+
|
187
|
+
[@the-teacher](https://github.com/the-teacher),
|
188
|
+
[@sedx](https://github.com/sedx),
|
189
|
+
[@seuros](https://github.com/seuros)
|
190
|
+
|
191
|
+
#### Contributors
|
192
|
+
|
193
|
+
@igmarin, @doabit, @linjunpop, @egb3
|