the_role 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .rvmrc
data/.rvmrc.example ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.8.7-p357@the_role --create
data/Gemfile CHANGED
@@ -3,5 +3,3 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in the_role.gemspec
4
4
  gemspec
5
5
 
6
- gem 'haml', '~> 3.0'
7
- gem 'sass'
data/README.md CHANGED
@@ -1,121 +1,83 @@
1
- ## TheRole
1
+ # gem 'the_role'
2
2
 
3
- Gem for providing simple, but powerful and flexible role system for ROR3 applications.
4
- Based on Hashes.
3
+ ## Bye bye CanCan, I got The Role!
5
4
 
6
- * Based on MVC semantik (easy to understand what's happening)
7
- * Realtime dynamically management with simple interface
8
- * Customizable
5
+ Semantic, lightweight role system with an administrative interface
9
6
 
10
- ## Installation
7
+ ![TheSortableTree](https://github.com/the-teacher/the_role/raw/master/pic.png)
11
8
 
12
- Gemfile
9
+ ## What does it mean semantic?
13
10
 
14
- ``` ruby
15
- gem 'the_role'
16
- ```
11
+ Semantic - the science of meaning. Human should fast to understand what is happening in a role system.
12
+
13
+ Look at hash. If you can understand access rules - this role system is semantically.
17
14
 
18
15
  ``` ruby
19
- bundle install
16
+ role = {
17
+ :pages => {
18
+ :index => true,
19
+ :show => true,
20
+ :new => false,
21
+ :edit => false,
22
+ :update => false,
23
+ :destroy => false
24
+ },
25
+ :articles => {
26
+ :index => true,
27
+ :show => true
28
+ }
29
+ :twitter => {
30
+ :button => true,
31
+ :follow => false
32
+ }
33
+ }
20
34
  ```
21
35
 
22
- ``` ruby
23
- rake the_role_engine:install:migrations
24
- >> Copied migration 20111028145956_create_roles.rb from the_role_engine
36
+ ### How it works
25
37
 
26
- rails g model user role_id:integer
27
- rails g model role --migration=false
38
+ Role - is a two-level hash, consisting of the sections and rules.
28
39
 
29
- rake db:create && rake db:migrate
30
- ```
40
+ **Section** may be associated with the name of a **controller**.
31
41
 
32
- Creating roles for test
42
+ **Rule** may be associated with the name of **action** in the controller.
33
43
 
34
- ``` ruby
35
- rake db:roles:test
36
- >> Administrator, Moderator of pages, User, Demo
37
- ```
44
+ Section may contain a set of rules.
38
45
 
39
- Define aliases method for correctly work TheRole's controllers
46
+ **Rule in Section** can be set to **true** and **false**, this provide **ACL** (**Access Control List**)
40
47
 
41
- **login_required** or any other method from your auth system
48
+ Role hash **stored in the database as YAML** string.
49
+ Using of hashes, makes it extremely easy to configure access rules in the role.
42
50
 
43
- **access_denied** or any other method for processing access denied situation
51
+ ### Virtual sections and rules
44
52
 
45
- ``` ruby
46
- class ApplicationController < ActionController::Base
47
- # You Auth system
48
- include AuthenticatedSystem
49
-
50
- # define aliases for correctly work of TheRole gem
51
- alias_method :the_login_required, :login_required
52
- alias_method :the_role_access_denied, :access_denied
53
- end
54
- ```
53
+ Usually, we use real names of controllers as names of sections, and we use names of real actions in controllers as names of section's rules.
55
54
 
56
- ## Using with controllers
55
+ Like this:
57
56
 
58
57
  ``` ruby
59
- class ArticlesController < ApplicationController
60
- # Auth system
61
- before_filter :login_required, :except=>[:index, :show, :tag]
62
- # Role system
63
- before_filter :the_role_require, :except => [:index, :show, :tag]
64
- before_filter :the_role_object, :only => [:edit, :update, :rebuild, :destroy]
65
- before_filter :the_owner_require, :only => [:edit, :update, :rebuild, :destroy]
66
-
67
- # actions
68
-
69
- end
58
+ current_user.has_role?(:pages, :show)
70
59
  ```
71
60
 
72
- ## Manage roles
61
+ But you can also create virtual sections and rules:
62
+
73
63
 
74
64
  ``` ruby
75
- rails s
65
+ current_user.has_role?(:twitter, :button)
66
+ current_user.has_role?(:facebook, :like)
76
67
  ```
77
68
 
78
- **admin_roles_path** => **http://localhost:3000/admin/roles**
69
+ These sections and the rules are not associated with real controllers and actions.
70
+ And you can use them as well as other access rules.
71
+
72
+ ### Who is the administrator?
73
+
74
+ Administrator - a user who can access any section and the rules of your application.
75
+ The administrator is the owner of any objects in your application.
76
+ Administrator - a user in the role-hash of which there is a section **system** and rule **administrator**.
77
+
78
+
79
+
79
80
 
80
- ## How it works
81
81
 
82
- ``` ruby
83
- rails c
84
-
85
- user = User.first
86
- user.role = Role.where(:name => :demo).first
87
- user.save
88
-
89
- user.admin?
90
- => false
91
- user.moderator? :pages
92
- => false
93
- user.has_role? :pages, :index
94
- => true
95
-
96
-
97
- user.role = Role.where(:name => :moderator).first
98
- user.save
99
-
100
- user.admin?
101
- => false
102
- user.moderator? :pages
103
- => true
104
- user.has_role? :pages, :any_crazy_name
105
- => true
106
-
107
- user.role = Role.where(:name => :admin).first
108
- user.save
109
-
110
- user.admin?
111
- => true
112
- user.moderator? :pages
113
- => true
114
- user.moderator? :any_crazy_name
115
- => true
116
- user.has_role? :any_crazy_name, :any_crazy_name
117
- => true
118
82
 
119
- ```
120
83
 
121
- Copyright (c) 2011 [Ilya N. Zykin Github.com/the-teacher], released under the MIT license
@@ -1,55 +1,57 @@
1
- .form{
2
- background:#EEE;
3
- padding:5px;
4
- margin:0 0 15px 0;
5
- border:2px solid gray;
6
- -moz-border-radius:5px;
7
- }
8
- .form label{
9
- display:block;
10
- }
11
- .form .input{
12
- border:1px solid #000;
13
- padding:2px 0 2px 5px;
14
- font-size:13pt;
15
- color:DarkBlue;
16
- }
17
- .form .textarea{
18
- font-size:13pt;
19
- padding:2px;
20
- }
21
- .form .message_textarea{
22
- font-size:13pt;
23
- padding:2px;
24
- border:1px solid black;
25
- height: 200px;
26
- }
27
- .form .submit{
28
- font-size:16pt;
29
- }
30
- .article_buttons{
31
- margin:0 0 10px 0;
32
- padding:0 0 5px 0;
33
- border-bottom:1px dashed gray;
34
- }
35
- .article_buttons input{
36
- margin-right:10px;
37
- }
38
- .submit_button{
39
- margin-bottom:10px;
40
- }
41
- .moderation_buttons{
42
- background:silver;
43
- margin:3px 3px 10px 3px;
44
- padding:5px;
45
- border:2px solid blue;
46
- }
47
- .delete_button{
48
- background: none repeat scroll 0 0 lightGrey;
49
- border: 1px dashed gray;
50
- padding: 5px 0;
51
- text-align: right;
52
- }
53
- .delete_button input{
54
- color:Crimson;
55
- }
1
+ .the_role{
2
+ .the_form{
3
+ background:#EEE;
4
+ padding:5px;
5
+ margin:0 0 15px 0;
6
+ border:2px solid gray;
7
+ -moz-border-radius:5px;
8
+ }
9
+ .the_form label{
10
+ display:block;
11
+ }
12
+ .the_form .input{
13
+ border:1px solid #000;
14
+ padding:2px 0 2px 5px;
15
+ font-size:13pt;
16
+ color:DarkBlue;
17
+ }
18
+ .the_form .textarea{
19
+ font-size:13pt;
20
+ padding:2px;
21
+ }
22
+ .the_form .message_textarea{
23
+ font-size:13pt;
24
+ padding:2px;
25
+ border:1px solid black;
26
+ height: 200px;
27
+ }
28
+ .the_form .submit{
29
+ font-size:16pt;
30
+ }
31
+ .article_buttons{
32
+ margin:0 0 10px 0;
33
+ padding:0 0 5px 0;
34
+ border-bottom:1px dashed gray;
35
+ }
36
+ .article_buttons input{
37
+ margin-right:10px;
38
+ }
39
+ .submit_button{
40
+ margin-bottom:10px;
41
+ }
42
+ .moderation_buttons{
43
+ background:silver;
44
+ margin:3px 3px 10px 3px;
45
+ padding:5px;
46
+ border:2px solid blue;
47
+ }
48
+ .delete_button{
49
+ background: none repeat scroll 0 0 lightGrey;
50
+ border: 1px dashed gray;
51
+ padding: 5px 0;
52
+ text-align: right;
53
+ }
54
+ .delete_button input{
55
+ color:Crimson;
56
+ }
57
+ }
@@ -1,13 +1,15 @@
1
- h1,h2,h3,h4,h5,h6{
2
- font-family: Verdana, Arial;
3
- color:#333;
4
- font-weight:normal;
5
- line-height:100%;
6
- margin-bottom:15px;
1
+ .the_role{
2
+ h1,h2,h3,h4,h5,h6{
3
+ font-family: Verdana, Arial;
4
+ color:#333;
5
+ font-weight:normal;
6
+ line-height:100%;
7
+ margin-bottom:15px;
8
+ }
9
+ h1{font-size:3em;}
10
+ h2{font-size:2.8em;}
11
+ h3{font-size:2.6em;}
12
+ h4{font-size:2.4em;}
13
+ h5{font-size:2.2em;}
14
+ h6{font-size:2em;}
7
15
  }
8
- h1{font-size:3em;}
9
- h2{font-size:2.8em;}
10
- h3{font-size:2.6em;}
11
- h4{font-size:2.4em;}
12
- h5{font-size:2.2em;}
13
- h6{font-size:2em;}
@@ -1,76 +1,75 @@
1
- .body{
2
- width: 900px;
3
- margin:auto;
4
- font:Tahoma;
5
- font-family:Tahoma,Trebuchet MS,Times New Roman;
6
- }
7
- img, p, pre, blockquote, dd, dt, caption, legend, label{
8
- font-size: 2em;
9
- }
10
- ul.index{
11
- p{
12
- padding: 5px;
13
- &:hover{
14
- background: #DDD;
15
-
1
+ .the_role{
2
+ ul.index{
3
+ position: relative;
4
+ li{
5
+ position: relative;
6
+ p{
7
+ border-bottom: 1px solid Lavender;
8
+ font-size: 16px;
9
+ margin-bottom: 10px;
10
+ padding: 5px;
11
+ &:hover{ background: #EEE; }
12
+ a.delete{
13
+ position: absolute;
14
+ bottom: 5px; right: 0;
15
+ color: IndianRed;
16
+ }
17
+ }
16
18
  }
17
- a.delete{
18
- float: right;
19
+ }//ul.index
20
+
21
+ h4{
22
+ position: relative;
23
+ padding: 5px;
24
+ background: LightBlue;
25
+ .controls{
26
+ a{
27
+ color: blue;
28
+ }
19
29
  }
20
30
  }
21
- }//ul.index
22
31
 
23
- h4{
24
- position: relative;
25
- padding: 5px;
26
- background: LightBlue;
27
32
  .controls{
28
- a{
29
- color: blue;
30
- }
33
+ position:absolute;
34
+ right:10px;
35
+ top:10%;
36
+ zoom:1;
37
+ padding-bottom:6px;
38
+ }
39
+ .controls a{
40
+ margin:0 10px;
41
+ font-size:10pt;
42
+ color:#CCC;
43
+ border:1px solid transparent;
44
+ padding:3px;
45
+ text-decoration:none;
46
+ }
47
+ .controls a:hover{
48
+ color:#999;
49
+ border:1px solid #999;
50
+ }
51
+ ul.rights{
52
+ margin:0 0 20px;
53
+ }
54
+ ul.rights li{
55
+ margin:0 0 5px 20px;
56
+ position:relative;
57
+ zoom:1;
58
+ border-bottom:1px solid #EEE;
59
+ padding: 5px 0;
60
+ font-size:9pt;
61
+ }
62
+ ul.rights li .controls{
63
+ top:10%;
64
+ right:5px;
65
+ padding:5px;
66
+ }
67
+ form.new_action{
68
+ padding:15px;
69
+ background:#EEE;
70
+ margin:0 0 50px 0;
71
+ }
72
+ form{
73
+ margin:0 0 50px 0;
31
74
  }
32
75
  }
33
-
34
- .controls{
35
- position:absolute;
36
- right:10px;
37
- top:10%;
38
- zoom:1;
39
- padding-bottom:6px;
40
- }
41
- .controls a{
42
- margin:0 10px;
43
- font-size:10pt;
44
- color:#CCC;
45
- border:1px solid transparent;
46
- padding:3px;
47
- text-decoration:none;
48
- }
49
- .controls a:hover{
50
- color:#999;
51
- border:1px solid #999;
52
- }
53
- ul.rights{
54
- margin:0 0 20px;
55
- }
56
- ul.rights li{
57
- margin:0 0 5px 20px;
58
- position:relative;
59
- zoom:1;
60
- border-bottom:1px solid #EEE;
61
- padding: 5px 0;
62
- font-size:9pt;
63
- }
64
- ul.rights li .controls{
65
- top:10%;
66
- right:5px;
67
- padding:5px;
68
- }
69
- form.new_action{
70
- padding:15px;
71
- background:#EEE;
72
- margin:0 0 50px 0;
73
- }
74
- form{
75
- margin:0 0 50px 0;
76
- }