Adman65-AccessControl 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{AccessControl}
5
- s.version = "0.2.1"
5
+ s.version = "0.2.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Adam Hawkins"]
@@ -47,13 +47,13 @@ Gem::Specification.new do |s|
47
47
  s.rubygems_version = %q{1.3.4}
48
48
  s.summary = %q{Simple role based authorization for rails}
49
49
  s.test_files = [
50
- "spec/access_controlled_user_spec.rb",
51
- "spec/models/permission_spec.rb",
52
- "spec/models/role_spec.rb",
53
- "spec/spec_helper.rb",
50
+ "spec/spec_helper.rb",
54
51
  "spec/support/access_control_user.rb",
55
52
  "spec/support/authorizable.rb",
56
- "spec/support/schema.rb"
53
+ "spec/support/schema.rb",
54
+ "spec/models/permission_spec.rb",
55
+ "spec/models/role_spec.rb",
56
+ "spec/access_controlled_user_spec.rb"
57
57
  ]
58
58
 
59
59
  if s.respond_to? :specification_version then
data/README.markdown CHANGED
@@ -1,6 +1,5 @@
1
1
  AccessControl
2
2
  =============
3
- **Warning: this is a beta plugin!**
4
3
 
5
4
  AccessControl is a user authorization plugin. It gives you a role based permission system without having to do any work. There are users and roles, each have permission.
6
5
  A user can play any role and inherit permissions through that role. A user may also have individual permissions. For example, you can create a role to update
@@ -14,18 +13,19 @@ Features
14
13
  * God permission
15
14
  * Easy to use
16
15
 
17
-
18
16
  Up and Running
19
17
  ================
20
18
 
21
19
  Install
22
20
  -------
23
21
 
24
- First, prepare your application. AccessControl does not create user logins, it soley is a permission system. I'm assuming you have model named user. AccessControl
22
+ First, prepare your application. AccessControl does not create user logins, it soley is a permission system. Your user model must be named User. AccessControl
25
23
  also uses two other models: Permission & Role. Once your users can login and log out, you are ready to use AccessControl.
26
24
 
27
25
  1. Install
28
- ./script/plugin install git://github.com/Adman65/AccessControl.git
26
+ (plugin) ./script/plugin install git://github.com/Adman65/AccessControl.git
27
+ (gem) sudo gem install Adman65-AccessControl
28
+ (gem) config.gem 'Adman65-AccessControl', :lib => 'access_control'
29
29
 
30
30
  2. Prepare the database
31
31
  ./script/generate access_control models
@@ -64,7 +64,7 @@ Voilla, Adam can now post_news. But that's no good by itself. So now check agani
64
64
  end
65
65
 
66
66
  Your controllers are protected from people who can't post news. Now lets expand our permissions by adding a role:
67
- editors = Role.create :name => "Editors", :description => "Manage content around the site."
67
+ editors = Role.create :name => "Editors", :description => "Manage content around the site." # Description is optional
68
68
  # assuming we have these permissions in the system
69
69
  editors.grant :manage_news
70
70
  editors.grant :manage_categories
@@ -83,29 +83,24 @@ Man, Adam sure got a lot of responsibilities, hopefully you trust him :)
83
83
  Using the language
84
84
  ==============
85
85
 
86
- Its nice to be able to express concepts in code that when you read the code, you understand what is going on. AccessControl gives you expressive method names
87
- express authorization inside your code. The methods below can be user on a User or Role.
88
- @user.can_manage_news?
89
- @user.can? :manage_news
90
- @user.can? "manage_news"
91
- @user.has_permission :manage_news
92
- @user.cannot? :manage_news
93
- @user.grant :permission
94
- @user.authorize :permission
95
- @user.deauthorize :permission
96
- @user.permissions (returns an array of all the permissions a user/role has)
97
-
98
- These methods only work on users
99
- @user.plays :role_name
100
- @user.plays? :role_name
101
- @user.is_a_editor?
102
-
103
-
104
- Utilties
105
- ===========
106
- Sometimes you want to see all the permissions in your application:
107
- rake access_control:permissions
108
-
86
+ Here are the methods available on User & Role objects:
87
+ Authorizable#authorize(permission)
88
+ Authorizable#grant(permission)
89
+ Authorizable#deauthorize(permission)
90
+ Authorizable#cannot?(permission)
91
+ Authorizable#god?
92
+ Authorizable#can_permission_name?
93
+ Authorizable#can_not_permission_name?
94
+ Authorizable#permissions
95
+ Authorizable#has_permission?(permission)
96
+ Authorizable#can?(permission)
97
+
98
+ User Methods:
99
+ User#plays?(role)
100
+ User#plays(role)
101
+ User#does_not_play?(role)
102
+ User#does_not_play(role)
103
+ User.roles (and all other has_and_belongs_to_many methods)
109
104
 
110
105
 
111
106
  Copyright (c) 2009 Adam Hawkins, released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.3
@@ -29,7 +29,7 @@ class AccessControlGenerator < Rails::Generator::NamedBase
29
29
 
30
30
  m.migration_template File.join("migrate","create_access_control_models.rb"), File.join("db","migrate"), :migration_file_name => "GenerateAccessControlModels".underscore
31
31
  when :permission
32
- file_name = "create_multiple_permissions" if args.size > 2
32
+ file_name = "create_multiple_permissions_#{@permission_names.join('_').underscore}" if args.size > 2
33
33
  file_name = "create_permission_#{@permission_name}" if args.size.eql? 2
34
34
  m.migration_template "migration:migration.rb", File.join("db","migrate"), :assigns => migration_options, :migration_file_name => file_name
35
35
  end
@@ -40,7 +40,8 @@ class AccessControlGenerator < Rails::Generator::NamedBase
40
40
  def migration_options
41
41
  assigns = {}
42
42
  assigns[:migration_action] = "add"
43
- assigns[:class_name] = "create_permission_#{@permission_name}"
43
+ assigns[:class_name] = "create_multiple_permissions_#{@permission_names.join('_').underscore}".camelize if @permission_names
44
+ assigns[:class_name] = "create_multiple_permissions" if @permission_name
44
45
  assigns[:table_name] = "permissions"
45
46
  assigns[:attributes] = @permission_names.map {|name| Rails::Generator::GeneratedAttribute.new(name, "boolean")}
46
47
  assigns
@@ -5,6 +5,7 @@ class GenerateAccessControlModels < ActiveRecord::Migration
5
5
  t.string "authorizable_type"
6
6
  t.datetime "created_at"
7
7
  t.datetime "updated_at"
8
+ t.boolean "god", :default => false
8
9
  end
9
10
 
10
11
  create_table "roles" do |t|
@@ -36,11 +36,6 @@ module AccessControl
36
36
  return true if self.permission.god
37
37
  self.permission.send(perm)
38
38
  end
39
-
40
- private
41
- def create_new_permission
42
- self.permission = Permission.create
43
- end
44
-
39
+
45
40
  end
46
41
  end
@@ -6,7 +6,7 @@ module AccessControl
6
6
  include AccessControl::CommonMethods
7
7
  include AccessControl::Language
8
8
 
9
- has_and_belongs_to_many :users, :join_table => :user_roles#, :foreign_key => :access_control_user_id
9
+ has_and_belongs_to_many :users, :join_table => :user_roles
10
10
  has_one :permission, :as => :authorizable, :dependent => :destroy
11
11
 
12
12
  alias :has_permission? :has_local_permission?
@@ -17,10 +17,7 @@ module AccessControl
17
17
  end
18
18
 
19
19
  def permissions
20
- set = self.permission.set_permissions
21
- return nil if set.nil?
22
- return set.first if set.size.eql? 0
23
- set
20
+ self.permission.set_permissions
24
21
  end
25
22
 
26
23
  end
@@ -32,6 +32,13 @@ module AccessControl
32
32
  def does_not_play? role
33
33
  !plays? role
34
34
  end
35
+
36
+ def does_not_play role
37
+ role = role.to_s if role.is_a? Symbol
38
+ actual_role = Role.find_by_name(role.downcase)
39
+ raise "#{role} does not exist" if actual_role.nil?
40
+ roles.delete actual_role
41
+ end
35
42
 
36
43
  def has_permission? perm
37
44
  return true if has_local_permission? perm
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Adman65-AccessControl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Hawkins
@@ -76,10 +76,10 @@ signing_key:
76
76
  specification_version: 3
77
77
  summary: Simple role based authorization for rails
78
78
  test_files:
79
- - spec/access_controlled_user_spec.rb
80
- - spec/models/permission_spec.rb
81
- - spec/models/role_spec.rb
82
79
  - spec/spec_helper.rb
83
80
  - spec/support/access_control_user.rb
84
81
  - spec/support/authorizable.rb
85
82
  - spec/support/schema.rb
83
+ - spec/models/permission_spec.rb
84
+ - spec/models/role_spec.rb
85
+ - spec/access_controlled_user_spec.rb