role_based_security 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2011 Artem Rufanov
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2011 Artem Rufanov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README CHANGED
@@ -1,47 +1,52 @@
1
- RoleBasedSecurity
2
- ===================
3
-
4
- RoleBasedSecurity is a gem that implements role based security for authlogic.
5
-
6
- * The gem supports ruby 1.9.x & rails 3.x
7
- * The gem allows to create role based security for authlogic
8
- * The gem allows ...
9
-
10
- This gem assumes that
11
-
12
- * You are using authlogic and application has current_user method
13
- * The name of the user model is User
14
- *
15
-
16
- Quick Start
17
- =======
18
- In your Gemfile:
19
-
20
- gem "role_based_security", ">= 0.5.0"
21
-
22
- In your controller:
23
-
24
- require_role "admin"
25
-
26
- In your user model:
27
-
28
- has_many :user_roles, :dependent => :destroy
29
-
30
- If you wish:
31
-
32
- -Use config/initiaizers to configure options for this gem
33
- -Run ruby script/rails generate role_based_security to gen migration, models and etc.
34
-
35
-
36
- Installation
37
- =======
38
-
39
- * Type 'gem install --local role_based_security' with root account if you have installed RubyGems.
40
-
41
-
42
- Example
43
- =======
44
-
45
- Example goes here.
46
-
47
- Copyright (c) 2011 arufanov, released under the MIT license.
1
+ RoleBasedSecurity
2
+ ===================
3
+
4
+ RoleBasedSecurity is a gem that implements role based security for authlogic.
5
+
6
+ * The gem supports ruby 1.9.x & rails 3.x
7
+ * The gem allows to create role based security for authlogic
8
+ * The gem allows ...
9
+
10
+ This gem assumes that
11
+
12
+ * You are using authlogic and application has current_user method
13
+ * The name of the user model is User
14
+ *
15
+
16
+ Important
17
+ =======
18
+ Project doesn't supported more. Use https://github.com/be9/acl9 for example
19
+
20
+
21
+ Quick Start
22
+ =======
23
+ In your Gemfile:
24
+
25
+ gem "role_based_security", ">= 0.5.1"
26
+
27
+ In your controller:
28
+
29
+ require_role "admin"
30
+
31
+ In your user model:
32
+
33
+ has_many :user_roles, :dependent => :destroy
34
+
35
+ If you wish:
36
+
37
+ -Use config/initiaizers to configure options for this gem
38
+ -Run ruby script/rails generate role_based_security to gen migration, models and etc.
39
+
40
+
41
+ Installation
42
+ =======
43
+
44
+ * Type 'gem install --local role_based_security' with root account if you have installed RubyGems.
45
+
46
+
47
+ Example
48
+ =======
49
+
50
+ Example goes here.
51
+
52
+ Copyright (c) 2011 arufanov, released under the MIT license.
data/Rakefile CHANGED
@@ -1,23 +1,23 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- desc 'Default: run unit tests.'
6
- task :default => :test
7
-
8
- desc 'Test the role_based_security plugin.'
9
- Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
11
- t.libs << 'test'
12
- t.pattern = 'test/**/*_test.rb'
13
- t.verbose = true
14
- end
15
-
16
- desc 'Generate documentation for the role_based_security plugin.'
17
- Rake::RDocTask.new(:rdoc) do |rdoc|
18
- rdoc.rdoc_dir = 'rdoc'
19
- rdoc.title = 'RoleBasedSecurity'
20
- rdoc.options << '--line-numbers' << '--inline-source'
21
- rdoc.rdoc_files.include('README')
22
- rdoc.rdoc_files.include('lib/**/*.rb')
23
- end
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the role_based_security plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the role_based_security plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'RoleBasedSecurity'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
data/changelog CHANGED
@@ -1,18 +1,18 @@
1
- Introduction:
2
- To see the latest list of the change log please visit the Change Log page at www.majoron.com.
3
-
4
- Legend:
5
- Follow notation is used at change log, roadmap and known bugs. Each bug begins with a version,
6
- then follow category of the bug inside {}. It can be bug report, feature request and etc.
7
- Then follow component inside []. After follow bug number at bug tracking system between // signs.
8
- And then follow a short description of the bug.
9
-
10
- Example:
11
- For example bug: "1.0 { Feature Request } [ AntHill ] / 380 / STLport support required" means
12
- that bug was created for 1.0 version of the AntHill component, bug is feature request with
13
- 380 number at bug tracking system. And bug requires STLPort support implementation.
14
-
15
- Version 0.5
16
- -----------
17
- 0.5 { Bug Report } [ RoleBasedSecurity ] / X / Changelog, roadmap, knownbugs have been created
18
- 0.5 { Bug Report } [ RoleBasedSecurity ] / X / Use include, extend instead of class_eval
1
+ Introduction:
2
+ To see the latest list of the change log please visit the Change Log page at www.majoron.com.
3
+
4
+ Legend:
5
+ Follow notation is used at change log, roadmap and known bugs. Each bug begins with a version,
6
+ then follow category of the bug inside {}. It can be bug report, feature request and etc.
7
+ Then follow component inside []. After follow bug number at bug tracking system between // signs.
8
+ And then follow a short description of the bug.
9
+
10
+ Example:
11
+ For example bug: "1.0 { Feature Request } [ AntHill ] / 380 / STLport support required" means
12
+ that bug was created for 1.0 version of the AntHill component, bug is feature request with
13
+ 380 number at bug tracking system. And bug requires STLPort support implementation.
14
+
15
+ Version 0.5
16
+ -----------
17
+ 0.5 { Bug Report } [ RoleBasedSecurity ] / X / Changelog, roadmap, knownbugs have been created
18
+ 0.5 { Bug Report } [ RoleBasedSecurity ] / X / Use include, extend instead of class_eval
data/init.rb CHANGED
@@ -1,2 +1,2 @@
1
- # Include hook code here
2
- require 'role_based_security'
1
+ # Include hook code here
2
+ require 'role_based_security'
data/install.rb CHANGED
@@ -1 +1 @@
1
- # Install hook code here
1
+ # Install hook code here
data/knownbugs CHANGED
@@ -1,17 +1,17 @@
1
- Introduction:
2
- To see the latest list of the known bugs please visit the Known bugs page at www.majoron.com.
3
-
4
- Legend:
5
- Follow notation is used at change log, roadmap and known bugs. Each bug begins with a version,
6
- then follow category of the bug inside {}. It can be bug report, feature request and etc.
7
- Then follow component inside []. After follow bug number at bug tracking system between // signs.
8
- And then follow a short description of the bug.
9
-
10
- Example:
11
- For example bug: "1.0 { Feature Request } [ AntHill ] / 380 / STLport support required" means
12
- that bug was created for 1.0 version of the AntHill component, bug is feature request with
13
- 380 number at bug tracking system. And bug requires STLPort support implementation.
14
-
15
- Version 0.5
16
- -----------
17
- 0.5 { Bug Report } [ AuxiliaryAddons ] / X / There isn't known bugs
1
+ Introduction:
2
+ To see the latest list of the known bugs please visit the Known bugs page at www.majoron.com.
3
+
4
+ Legend:
5
+ Follow notation is used at change log, roadmap and known bugs. Each bug begins with a version,
6
+ then follow category of the bug inside {}. It can be bug report, feature request and etc.
7
+ Then follow component inside []. After follow bug number at bug tracking system between // signs.
8
+ And then follow a short description of the bug.
9
+
10
+ Example:
11
+ For example bug: "1.0 { Feature Request } [ AntHill ] / 380 / STLport support required" means
12
+ that bug was created for 1.0 version of the AntHill component, bug is feature request with
13
+ 380 number at bug tracking system. And bug requires STLPort support implementation.
14
+
15
+ Version 0.5
16
+ -----------
17
+ 0.5 { Bug Report } [ AuxiliaryAddons ] / X / There isn't known bugs
@@ -1,4 +1,4 @@
1
- Description:
2
- The role_based_security generator creates an role and user role models
3
- at app/models and roles and user roles migrations and db/migrate.
4
-
1
+ Description:
2
+ The role_based_security generator creates an role and user role models
3
+ at app/models and roles and user roles migrations and db/migrate.
4
+
@@ -1,15 +1,15 @@
1
- module RoleBasedSecurity
2
- module Generators
3
- class RoleBasedSecurityGenerator < Rails::Generators::Base
4
- source_root File.expand_path('../templates', __FILE__)
5
-
6
- def generate_role_based_security
7
- copy_file "role.rb", "app/models/role.rb"
8
- copy_file "user_role.rb", "app/models/user_role.rb"
9
- copy_file "20110510155623_create_roles.rb", "db/migrate/20110510155623_create_roles.rb"
10
- copy_file "20110510155626_create_user_roles.rb", "db/migrate/20110510155626_create_user_roles.rb"
11
- end
12
- end
13
- end
14
- end
15
-
1
+ module RoleBasedSecurity
2
+ module Generators
3
+ class RoleBasedSecurityGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def generate_role_based_security
7
+ copy_file "role.rb", "app/models/role.rb"
8
+ copy_file "user_role.rb", "app/models/user_role.rb"
9
+ copy_file "20110510155623_create_roles.rb", "db/migrate/20110510155623_create_roles.rb"
10
+ copy_file "20110510155626_create_user_roles.rb", "db/migrate/20110510155626_create_user_roles.rb"
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -1,18 +1,18 @@
1
- class CreateRoles < ActiveRecord::Migration
2
- def self.up
3
- create_table :roles do |t|
4
- t.column :name, :string, :limit => 128, :null => false
5
- t.column :code, :string, :limit => 128, :null => false
6
- t.column :about, :string, :limit => 128, :null => false
7
- t.timestamps
8
- end
9
-
10
- # Create constraints
11
- add_index :roles, :name, :unique
12
- add_index :roles, :code, :unique
13
- end
14
-
15
- def self.down
16
- drop_table :roles
17
- end
18
- end
1
+ class CreateRoles < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :roles do |t|
4
+ t.column :name, :string, :limit => 128, :null => false
5
+ t.column :code, :string, :limit => 128, :null => false
6
+ t.column :about, :string, :limit => 128, :null => false
7
+ t.timestamps
8
+ end
9
+
10
+ # Create constraints
11
+ add_index :roles, :name, :unique
12
+ add_index :roles, :code, :unique
13
+ end
14
+
15
+ def self.down
16
+ drop_table :roles
17
+ end
18
+ end
@@ -1,20 +1,20 @@
1
- class CreateUserRoles < ActiveRecord::Migration
2
- def self.up
3
- create_table :user_roles do |t|
4
- t.column :user_id, :integer, :null => false
5
- t.column :role_id, :integer, :null => false
6
- t.timestamps
7
- end
8
-
9
- # Add foreign keys
10
- add_foreign_key :user_roles, :users, :column => "user_id"
11
- add_foreign_key :user_roles, :roles, :column => "role_id"
12
-
13
- # Create indexes
14
- add_index :user_roles, [:user_id, :role_id], :unique
15
- end
16
-
17
- def self.down
18
- drop_table :user_roles
19
- end
20
- end
1
+ class CreateUserRoles < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :user_roles do |t|
4
+ t.column :user_id, :integer, :null => false
5
+ t.column :role_id, :integer, :null => false
6
+ t.timestamps
7
+ end
8
+
9
+ # Add foreign keys
10
+ add_foreign_key :user_roles, :users, :column => "user_id"
11
+ add_foreign_key :user_roles, :roles, :column => "role_id"
12
+
13
+ # Create indexes
14
+ add_index :user_roles, [:user_id, :role_id], :unique
15
+ end
16
+
17
+ def self.down
18
+ drop_table :user_roles
19
+ end
20
+ end
@@ -1,14 +1,14 @@
1
- class Role < ActiveRecord::Base
2
- has_many :user_roles, :dependent => :destroy
3
-
4
- validates_presence_of :name
5
- validates_presence_of :code
6
- validates_presence_of :about
7
-
8
- validates_length_of :name, :within => 1..128
9
- validates_length_of :code, :within => 1..128
10
- validates_length_of :about, :within => 1..128
11
-
12
- validates_uniqueness_of :name
13
- validates_uniqueness_of :code
14
- end
1
+ class Role < ActiveRecord::Base
2
+ has_many :user_roles, :dependent => :destroy
3
+
4
+ validates_presence_of :name
5
+ validates_presence_of :code
6
+ validates_presence_of :about
7
+
8
+ validates_length_of :name, :within => 1..128
9
+ validates_length_of :code, :within => 1..128
10
+ validates_length_of :about, :within => 1..128
11
+
12
+ validates_uniqueness_of :name
13
+ validates_uniqueness_of :code
14
+ end
@@ -1,10 +1,10 @@
1
- class UserRole < ActiveRecord::Base
2
- belongs_to :user
3
- belongs_to :role
4
-
5
- validates_presence_of :user_id
6
- validates_presence_of :role_id
7
-
8
- #validates_uniqueness_of [:muscle_user_id, :role_id]
9
-
10
- end
1
+ class UserRole < ActiveRecord::Base
2
+ belongs_to :user
3
+ belongs_to :role
4
+
5
+ validates_presence_of :user_id
6
+ validates_presence_of :role_id
7
+
8
+ #validates_uniqueness_of [:muscle_user_id, :role_id]
9
+
10
+ end
@@ -1,37 +1,37 @@
1
- # Include
2
- require 'rubygems'
3
- require 'active_support'
4
- require 'role_based_security/model_additions'
5
- require 'role_based_security/controller_additions'
6
- require 'role_based_security/view_additions'
7
-
8
- # = RoleBasedSecurity
9
- #
10
- module RoleBasedSecurity
11
- # ::Rails.logger.error("...")
12
-
13
- # default options that can be overridden on the global level
14
- @@options = {
15
- :home_path => '/welcome', #
16
- :locale_message_key => 'labels.invalid_rights', #
17
- :invalid_rights_message => 'Sorry, but you don\'t have access rights to visit this URL', #
18
- }
19
- mattr_reader :options
20
-
21
-
22
- def self.enable_activerecord
23
- ActiveRecord::Base.send :include, RoleBasedSecurity::ModelAdditions
24
- end
25
-
26
- def self.enable_actionpack
27
- ActionController::Base.send :include, RoleBasedSecurity::ControllerAdditions
28
- ActionController::Base.send :extend, RoleBasedSecurity::ControllerAdditions::ClassMethods
29
-
30
- ActionView::Base.send :include, RoleBasedSecurity::ViewAdditions
31
- end
32
- end
33
-
34
- if defined? Rails
35
- RoleBasedSecurity.enable_activerecord if defined? ActiveRecord
36
- RoleBasedSecurity.enable_actionpack if defined? ActionController
37
- end
1
+ # Include
2
+ require 'rubygems'
3
+ require 'active_support'
4
+ require 'role_based_security/model_additions'
5
+ require 'role_based_security/controller_additions'
6
+ require 'role_based_security/view_additions'
7
+
8
+ # = RoleBasedSecurity
9
+ #
10
+ module RoleBasedSecurity
11
+ # ::Rails.logger.error("...")
12
+
13
+ # default options that can be overridden on the global level
14
+ @@options = {
15
+ :home_path => '/welcome', #
16
+ :locale_message_key => 'labels.invalid_rights', #
17
+ :invalid_rights_message => 'Sorry, but you don\'t have access rights to visit this URL', #
18
+ }
19
+ mattr_reader :options
20
+
21
+
22
+ def self.enable_activerecord
23
+ ActiveRecord::Base.send :include, RoleBasedSecurity::ModelAdditions
24
+ end
25
+
26
+ def self.enable_actionpack
27
+ ActionController::Base.send :include, RoleBasedSecurity::ControllerAdditions
28
+ ActionController::Base.send :extend, RoleBasedSecurity::ControllerAdditions::ClassMethods
29
+
30
+ ActionView::Base.send :include, RoleBasedSecurity::ViewAdditions
31
+ end
32
+ end
33
+
34
+ if defined? Rails
35
+ RoleBasedSecurity.enable_activerecord if defined? ActiveRecord
36
+ RoleBasedSecurity.enable_actionpack if defined? ActionController
37
+ end
@@ -1,80 +1,80 @@
1
- #
2
- module RoleBasedSecurity
3
- module ControllerAdditions
4
- # ::Rails.logger.error("...")
5
-
6
- # Hook to extend
7
- def self.included(klass)
8
- klass.send :class_inheritable_array, :role_requirements
9
- klass.send :role_requirements=, []
10
- end
11
-
12
- module ClassMethods
13
- # Add this to the top of your controller to require a role in order to access it.
14
- # Example Usage:
15
- #
16
- # require_role "contractor"
17
- # require_role "admin", :only => :destroy # don't allow contractors to destroy
18
- # require_role "admin", :only => :update, :unless => "current_<%= users_name %>.authorized_for_listing?(params[:id]) "
19
- #
20
- # Valid options
21
- #
22
- # * :only - Only require the role for the given actions
23
- # * :except - Require the role for everything but
24
- # * :if - a Proc or a string to evaluate. If it evaluates to true, the role is required.
25
- # * :unless - The inverse of :if
26
- #
27
- def require_role(roles, options = {})
28
- options.assert_valid_keys(:if, :unless,
29
- :for, :only,
30
- :for_all_except, :except
31
- )
32
-
33
- # only declare that before filter once
34
- unless (@before_filter_declared||=false)
35
- @before_filter_declared=true
36
- before_filter :check_roles
37
- end
38
-
39
- # convert to an array if it isn't already
40
- roles = [roles] unless Array===roles
41
-
42
- options[:only] ||= options[:for] if options[:for]
43
- options[:except] ||= options[:for_all_except] if options[:for_all_except]
44
-
45
- # convert any actions into symbols
46
- for key in [:only, :except]
47
- if options.has_key?(key)
48
- options[key] = [options[key]] unless Array === options[key]
49
- options[key] = options[key].compact.collect{|v| v.to_sym}
50
- end
51
- end
52
-
53
- self.role_requirements||=[]
54
- self.role_requirements << {:roles => roles, :options => options }
55
- end
56
- end
57
-
58
- # Before filter to check roles
59
- # current_user come from authlogic
60
- # self.role_requirements = [{:roles=>["admin"], :options=>{}}]
61
- def check_roles
62
- return true if self.role_requirements.size() == 0
63
- if !current_user.nil?
64
- self.role_requirements.each do |role_requirement|
65
- role_requirement[:roles].each do |role|
66
- return true if current_user.has_role?(role)
67
- end
68
- end
69
- end
70
-
71
- #
72
- # Set flash and redurn to main page
73
- flash[:warning] = I18n.t ::RoleBasedSecurity.options[:locale_message_key],
74
- :default => ::RoleBasedSecurity.options[:invalid_rights_message]
75
- redirect_to(::RoleBasedSecurity.options[:home_path])
76
- false
77
- end
78
-
79
- end
1
+ #
2
+ module RoleBasedSecurity
3
+ module ControllerAdditions
4
+ # ::Rails.logger.error("...")
5
+
6
+ # Hook to extend
7
+ def self.included(klass)
8
+ klass.send :class_inheritable_array, :role_requirements
9
+ klass.send :role_requirements=, []
10
+ end
11
+
12
+ module ClassMethods
13
+ # Add this to the top of your controller to require a role in order to access it.
14
+ # Example Usage:
15
+ #
16
+ # require_role "contractor"
17
+ # require_role "admin", :only => :destroy # don't allow contractors to destroy
18
+ # require_role "admin", :only => :update, :unless => "current_<%= users_name %>.authorized_for_listing?(params[:id]) "
19
+ #
20
+ # Valid options
21
+ #
22
+ # * :only - Only require the role for the given actions
23
+ # * :except - Require the role for everything but
24
+ # * :if - a Proc or a string to evaluate. If it evaluates to true, the role is required.
25
+ # * :unless - The inverse of :if
26
+ #
27
+ def require_role(roles, options = {})
28
+ options.assert_valid_keys(:if, :unless,
29
+ :for, :only,
30
+ :for_all_except, :except
31
+ )
32
+
33
+ # only declare that before filter once
34
+ unless (@before_filter_declared||=false)
35
+ @before_filter_declared=true
36
+ before_filter :check_roles
37
+ end
38
+
39
+ # convert to an array if it isn't already
40
+ roles = [roles] unless Array===roles
41
+
42
+ options[:only] ||= options[:for] if options[:for]
43
+ options[:except] ||= options[:for_all_except] if options[:for_all_except]
44
+
45
+ # convert any actions into symbols
46
+ for key in [:only, :except]
47
+ if options.has_key?(key)
48
+ options[key] = [options[key]] unless Array === options[key]
49
+ options[key] = options[key].compact.collect{|v| v.to_sym}
50
+ end
51
+ end
52
+
53
+ self.role_requirements||=[]
54
+ self.role_requirements << {:roles => roles, :options => options }
55
+ end
56
+ end
57
+
58
+ # Before filter to check roles
59
+ # current_user come from authlogic
60
+ # self.role_requirements = [{:roles=>["admin"], :options=>{}}]
61
+ def check_roles
62
+ return true if self.role_requirements.size() == 0
63
+ if !current_user.nil?
64
+ self.role_requirements.each do |role_requirement|
65
+ role_requirement[:roles].each do |role|
66
+ return true if current_user.has_role?(role)
67
+ end
68
+ end
69
+ end
70
+
71
+ #
72
+ # Set flash and redurn to main page
73
+ flash[:warning] = I18n.t ::RoleBasedSecurity.options[:locale_message_key],
74
+ :default => ::RoleBasedSecurity.options[:invalid_rights_message]
75
+ redirect_to(::RoleBasedSecurity.options[:home_path])
76
+ false
77
+ end
78
+
79
+ end
80
80
  end
@@ -1,21 +1,21 @@
1
- #
2
- module RoleBasedSecurity
3
- module ModelAdditions
4
- # ::Rails.logger.error("...")
5
-
6
- #
7
- # Parameter role is a string rather than object, for example moderator or admin
8
- def has_role?(role)
9
- user_roles = UserRole.find :all, :conditions => ["user_id = ? ", self.id]
10
- return false if user_roles.nil? || (user_roles.size() == 0)
11
- user_roles.each do |user_role|
12
- next if user_role.role.code != role
13
- return true
14
- end
15
- false
16
- end
17
-
18
-
19
-
20
- end
1
+ #
2
+ module RoleBasedSecurity
3
+ module ModelAdditions
4
+ # ::Rails.logger.error("...")
5
+
6
+ #
7
+ # Parameter role is a string rather than object, for example moderator or admin
8
+ def has_role?(role)
9
+ user_roles = UserRole.find :all, :conditions => ["user_id = ? ", self.id]
10
+ return false if user_roles.nil? || (user_roles.size() == 0)
11
+ user_roles.each do |user_role|
12
+ next if user_role.role.code != role
13
+ return true
14
+ end
15
+ false
16
+ end
17
+
18
+
19
+
20
+ end
21
21
  end
@@ -1,8 +1,8 @@
1
- #
2
- module RoleBasedSecurity
3
- module ViewAdditions
4
- # ::Rails.logger.error("...")
5
-
6
-
7
- end
1
+ #
2
+ module RoleBasedSecurity
3
+ module ViewAdditions
4
+ # ::Rails.logger.error("...")
5
+
6
+
7
+ end
8
8
  end
data/roadmap CHANGED
@@ -1,19 +1,19 @@
1
- Introduction:
2
- To see the latest list of the roadmap please visit the Roadmap page at www.majoron.com.
3
-
4
- Legend:
5
- Follow notation is used at change log, roadmap and known bugs. Each bug begins with a version,
6
- then follow category of the bug inside {}. It can be bug report, feature request and etc.
7
- Then follow component inside []. After follow bug number at bug tracking system between // signs.
8
- And then follow a short description of the bug.
9
-
10
- Example:
11
- For example bug: "1.0 { Feature Request } [ AntHill ] / 380 / STLport support required" means
12
- that bug was created for 1.0 version of the AntHill component, bug is feature request with
13
- 380 number at bug tracking system. And bug requires STLPort support implementation.
14
-
15
- Version 0.5
16
- -----------
17
- 0.5 { Feature Request } [ RoleBasedSecurity ] / X / Add tests
18
- 0.5 { Feature Request } [ RoleBasedSecurity ] / X / Add RailsTie
19
-
1
+ Introduction:
2
+ To see the latest list of the roadmap please visit the Roadmap page at www.majoron.com.
3
+
4
+ Legend:
5
+ Follow notation is used at change log, roadmap and known bugs. Each bug begins with a version,
6
+ then follow category of the bug inside {}. It can be bug report, feature request and etc.
7
+ Then follow component inside []. After follow bug number at bug tracking system between // signs.
8
+ And then follow a short description of the bug.
9
+
10
+ Example:
11
+ For example bug: "1.0 { Feature Request } [ AntHill ] / 380 / STLport support required" means
12
+ that bug was created for 1.0 version of the AntHill component, bug is feature request with
13
+ 380 number at bug tracking system. And bug requires STLPort support implementation.
14
+
15
+ Version 0.5
16
+ -----------
17
+ 0.5 { Feature Request } [ RoleBasedSecurity ] / X / Add tests
18
+ 0.5 { Feature Request } [ RoleBasedSecurity ] / X / Add RailsTie
19
+
@@ -1,17 +1,17 @@
1
- require 'date'
2
- Gem::Specification.new do |s|
3
- s.name = %q{role_based_security}
4
- s.version = "0.5.0"
5
- s.date = Date.today.to_s
6
- s.summary = %q{RoleBasedSecurity is a gem that implements role based security for authlogic.}
7
- s.description = %q{RoleBasedSecurity is a gem that implements role based security for authlogic.}
8
- s.author = %q{Artem Rufanov}
9
- s.email = %q{developers@majoron.com}
10
- s.homepage = %q{http://www.majoron.com/project/rbundle/role_based_security}
11
- s.files = Dir.glob('**/*') - Dir.glob('distrib/**/*') - Dir.glob('lib/api/**/*') - Dir.glob('doc/*.xpr')
12
- s.bindir = 'bin'
13
- s.executables = Dir.glob('bin/*').collect {|f| File.basename(f)}
14
- s.require_paths << 'doc' << 'examples' << 'lib' << 'test'
15
- s.has_rdoc = true
16
- s.required_ruby_version = '>= 1.8.7'
17
- end
1
+ require 'date'
2
+ Gem::Specification.new do |s|
3
+ s.name = %q{role_based_security}
4
+ s.version = "0.5.1"
5
+ s.date = Date.today.to_s
6
+ s.summary = %q{RoleBasedSecurity is a gem that implements role based security for authlogic.}
7
+ s.description = %q{RoleBasedSecurity is a gem that implements role based security for authlogic.}
8
+ s.author = %q{Artem Rufanov}
9
+ s.email = %q{developers@majoron.com}
10
+ s.homepage = %q{http://www.majoron.com/project/rbundle/role_based_security}
11
+ s.files = Dir.glob('**/*') - Dir.glob('distrib/**/*') - Dir.glob('lib/api/**/*') - Dir.glob('doc/*.xpr')
12
+ s.bindir = 'bin'
13
+ s.executables = Dir.glob('bin/*').collect {|f| File.basename(f)}
14
+ s.require_paths << 'doc' << 'examples' << 'lib' << 'test'
15
+ s.has_rdoc = true
16
+ s.required_ruby_version = '>= 1.8.7'
17
+ end
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
2
-
3
- describe RoleBasedSecurity::ControllerAdditions do
4
- it "should define controller additions" do
5
- ::RoleBasedSecurity::ControllerAdditions.should be
6
- end
7
- end
1
+ require 'spec_helper'
2
+
3
+ describe RoleBasedSecurity::ControllerAdditions do
4
+ it "should define controller additions" do
5
+ ::RoleBasedSecurity::ControllerAdditions.should be
6
+ end
7
+ end
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
2
-
3
- describe RoleBasedSecurity::ModelAdditions do
4
- it "should define model additions" do
5
- ::RoleBasedSecurity::ModelAdditions.should be
6
- end
7
- end
1
+ require 'spec_helper'
2
+
3
+ describe RoleBasedSecurity::ModelAdditions do
4
+ it "should define model additions" do
5
+ ::RoleBasedSecurity::ModelAdditions.should be
6
+ end
7
+ end
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
2
-
3
- describe RoleBasedSecurity::ViewAdditions do
4
- it "should define view additions" do
5
- ::RoleBasedSecurity::ViewAdditions.should be
6
- end
7
- end
1
+ require 'spec_helper'
2
+
3
+ describe RoleBasedSecurity::ViewAdditions do
4
+ it "should define view additions" do
5
+ ::RoleBasedSecurity::ViewAdditions.should be
6
+ end
7
+ end
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
2
-
3
- describe RoleBasedSecurity do
4
- it "should define rails" do
5
- ::Rails::VERSION::MAJOR.should be
6
- end
7
- end
1
+ require 'spec_helper'
2
+
3
+ describe RoleBasedSecurity do
4
+ it "should define rails" do
5
+ ::Rails::VERSION::MAJOR.should be
6
+ end
7
+ end
data/spec/spec.opts CHANGED
@@ -1,2 +1,2 @@
1
- --color
2
- --backtrace
1
+ --color
2
+ --backtrace
data/spec/spec_helper.rb CHANGED
@@ -1,23 +1,23 @@
1
- $:.unshift File.dirname(__FILE__)
2
- $:.unshift File.join(File.dirname(__FILE__), '../lib')
3
-
4
- ENV["RAILS_ENV"] = "test"
5
- require 'rubygems'
6
- require 'rspec'
7
- require 'action_controller'
8
- require 'role_based_security'
9
-
10
- module Rails
11
- module VERSION
12
- MAJOR = 3
13
- end
14
- end unless defined? Rails
15
-
16
- # RoleBasedSecurity.root = './'
17
- RAILS_ROOT = './' unless defined?(RAILS_ROOT)
18
- RAILS_ENV = 'test' unless defined?(RAILS_ENV)
19
-
20
- RSpec.configure do |config|
21
- config.mock_with :rspec
22
- end
23
-
1
+ $:.unshift File.dirname(__FILE__)
2
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
3
+
4
+ ENV["RAILS_ENV"] = "test"
5
+ require 'rubygems'
6
+ require 'rspec'
7
+ require 'action_controller'
8
+ require 'role_based_security'
9
+
10
+ module Rails
11
+ module VERSION
12
+ MAJOR = 3
13
+ end
14
+ end unless defined? Rails
15
+
16
+ # RoleBasedSecurity.root = './'
17
+ RAILS_ROOT = './' unless defined?(RAILS_ROOT)
18
+ RAILS_ENV = 'test' unless defined?(RAILS_ENV)
19
+
20
+ RSpec.configure do |config|
21
+ config.mock_with :rspec
22
+ end
23
+
@@ -1,4 +1,4 @@
1
- # desc "Explaining what the task does"
2
- # task :captcha_validateable do
3
- # # Task goes here
4
- # end
1
+ # desc "Explaining what the task does"
2
+ # task :captcha_validateable do
3
+ # # Task goes here
4
+ # end
data/uninstall.rb CHANGED
@@ -1 +1 @@
1
- # Uninstall hook code here
1
+ # Uninstall hook code here
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: role_based_security
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-16 00:00:00.000000000Z
12
+ date: 2014-02-21 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: RoleBasedSecurity is a gem that implements role based security for authlogic.
15
15
  email: developers@majoron.com
@@ -17,33 +17,33 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - uninstall.rb
20
21
  - changelog
21
- - init.rb
22
- - install.rb
22
+ - tasks/role_based_security_tasks.rake
23
23
  - knownbugs
24
- - lib/generators/role_based_security/role_based_security_generator.rb
25
- - lib/generators/role_based_security/templates/20110510155623_create_roles.rb
26
- - lib/generators/role_based_security/templates/20110510155626_create_user_roles.rb
24
+ - init.rb
25
+ - role_based_security.gemspec
26
+ - Rakefile
27
+ - roadmap
28
+ - lib/role_based_security.rb
29
+ - lib/role_based_security/model_additions.rb
30
+ - lib/role_based_security/controller_additions.rb
31
+ - lib/role_based_security/view_additions.rb
27
32
  - lib/generators/role_based_security/templates/role.rb
33
+ - lib/generators/role_based_security/templates/20110510155626_create_user_roles.rb
28
34
  - lib/generators/role_based_security/templates/user_role.rb
35
+ - lib/generators/role_based_security/templates/20110510155623_create_roles.rb
36
+ - lib/generators/role_based_security/role_based_security_generator.rb
29
37
  - lib/generators/role_based_security/USAGE
30
- - lib/role_based_security/controller_additions.rb
31
- - lib/role_based_security/model_additions.rb
32
- - lib/role_based_security/view_additions.rb
33
- - lib/role_based_security.rb
34
38
  - MIT-LICENSE
35
- - Rakefile
36
39
  - README
37
- - roadmap
38
- - role_based_security.gemspec
39
- - spec/lib/role_based_security/controller_additions_spec.rb
40
+ - install.rb
41
+ - spec/spec_helper.rb
42
+ - spec/lib/role_based_security_spec.rb
40
43
  - spec/lib/role_based_security/model_additions_spec.rb
41
44
  - spec/lib/role_based_security/view_additions_spec.rb
42
- - spec/lib/role_based_security_spec.rb
45
+ - spec/lib/role_based_security/controller_additions_spec.rb
43
46
  - spec/spec.opts
44
- - spec/spec_helper.rb
45
- - tasks/role_based_security_tasks.rake
46
- - uninstall.rb
47
47
  homepage: http://www.majoron.com/project/rbundle/role_based_security
48
48
  licenses: []
49
49
  post_install_message:
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  requirements: []
70
70
  rubyforge_project:
71
- rubygems_version: 1.8.10
71
+ rubygems_version: 1.8.23
72
72
  signing_key:
73
73
  specification_version: 3
74
74
  summary: RoleBasedSecurity is a gem that implements role based security for authlogic.