the_role 0.9.93 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,21 +7,24 @@ Based on Hashes.
7
7
  * Realtime dynamically management with simple interface
8
8
  * Customizable
9
9
 
10
- ## Installing
10
+ ## Installation
11
11
 
12
12
  Gemfile
13
13
 
14
14
  ``` ruby
15
15
  gem 'the_role'
16
+ gem 'haml'
16
17
  ```
17
18
 
18
19
  ``` ruby
19
- bundle
20
+ bundle install
20
21
  ```
21
22
 
22
23
  ``` ruby
23
24
  rake the_role_engine:install:migrations
24
25
  >> Copied migration 20111028145956_create_roles.rb from the_role_engine
26
+
27
+ rake db:migrate
25
28
  ```
26
29
 
27
30
  ``` ruby
@@ -29,76 +32,43 @@ rake db:roles:create
29
32
  >> Administrator, Moderator of pages, User, Demo
30
33
  ```
31
34
 
32
- When gem initialize, **User**, **Role**, **ApplicationController** classes are extending with next methods:
33
-
34
- ## User
35
-
36
- ``` ruby
37
- # will be include into User.rb automaticaly
38
- belongs_to :role
39
- attr_accessible :role
40
- after_save { |user| user.instance_variable_set(:@the_role, nil) }
41
-
42
- # methods
43
- the_role
44
- admin?
45
- moderator?(section)
46
- has_role?(section, policy)
47
- owner?(obj)
48
-
49
- # instance variables
50
- @the_role
51
- ```
52
-
53
- ## Role
54
-
55
- ``` ruby
56
- # will be include into Role.rb automaticaly
57
- has_many :users
58
- validates :name, :presence => {:message => I18n.translate('the_role.name_presence')}
59
- validates :title, :presence => {:message => I18n.translate('the_role.title_presence')}
60
- ```
61
-
62
- ## ApplicationController
63
-
64
35
  ``` ruby
65
- # private methods (should be define as before filters)
66
- the_role_access_denied
67
- the_role_object
68
- the_role_require
69
- the_owner_require
70
- ```
71
- ## Routes
72
-
73
- method **the_role_access_denied** needs **root_path** for redirect
74
-
75
- ### Now try to use into console
36
+ user = User.first
37
+ user.role = Role.where(:name => :demo).first
38
+ user.save
39
+
40
+ user.admin?
41
+ => false
42
+ user.moderator? :pages
43
+ => false
44
+ user.has_role? :pages, :index
45
+ => true
46
+
47
+
48
+ user.role = Role.where(:name => :moderator).first
49
+ user.save
50
+
51
+ user.admin?
52
+ => false
53
+ user.moderator? :pages
54
+ => true
55
+ user.has_role? :pages, :any_crazy_name
56
+ => true
57
+
58
+ user.role = Role.where(:name => :admin).first
59
+ user.save
60
+
61
+ user.admin?
62
+ => true
63
+ user.moderator? :pages
64
+ => true
65
+ user.moderator? :any_crazy_name
66
+ => true
67
+ user.has_role? :any_crazy_name, :any_crazy_name
68
+ => true
76
69
 
77
- ``` ruby
78
- rails g scaffold article title:string content:text user_id:integer
79
- rails g scaffold page title:string content:text user_id:integer
80
- rails c
81
- >> User.new(:login => 'cosmo', :username => 'John Black').save
82
- >> u = User.first
83
- >> u.role = Role.first # admin
84
- >> u.save
85
- >> u.has_role? :x, :y
86
- => true
87
- >> u.role = Role.last # demo
88
- >> u.save
89
- >> u.has_role? :pages, :show
90
- => true
91
- >> u.has_role? :pages, :delete
92
- => flase
93
70
  ```
94
71
 
95
- ## Example
96
-
97
- ``` ruby
98
- - if curent_user.has_role? :pages, :show
99
- Page content
100
- - else
101
- Access denied
102
- ```
72
+ Manage your roles you can with **admin_roles_path** => **http://localhost:3000/admin/roles**
103
73
 
104
74
  Copyright (c) 2011 [Ilya N. Zykin Github.com/the-teacher], released under the MIT license
@@ -1,3 +1,3 @@
1
1
  module TheRole
2
- VERSION = "0.9.93"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/the_role.rb CHANGED
@@ -36,6 +36,7 @@ module TheRole
36
36
  end
37
37
 
38
38
  def moderator? section
39
+ return true if self.admin?
39
40
  role = self.the_role[:moderator] ? self.the_role[:moderator][section.to_sym] : false
40
41
  role && role.is_a?(TrueClass)
41
42
  end
@@ -103,7 +104,7 @@ module TheRole
103
104
  @the_role_object = self.instance_variable_get("@#{variable_name}")
104
105
  end
105
106
 
106
- # before_filter :owner_and_role_require
107
+ # before_filter :the_owner_require
107
108
  def the_owner_require
108
109
  the_role_access_denied unless current_user.owner?(@the_role_object)
109
110
  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: 0.9.93
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml
16
- requirement: &78949540 !ruby/object:Gem::Requirement
16
+ requirement: &80904720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *78949540
24
+ version_requirements: *80904720
25
25
  description: TheRole - simple, but powerful role system for ROR applications
26
26
  email:
27
27
  - zykin-ilya@ya.ru