effective_roles 2.2.1 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7ff9e1eeeb8d78b3f50617feee6d0de9d591478bb8a8cc69f11d2a94bb7c4d0
4
- data.tar.gz: 66289a8ec1e2206d24a3e612b43b1da5e34311fdaff50973d7995b23052d5ee8
3
+ metadata.gz: 9bfa0c4c2878a1c88ee466c2cc321ad1ad8016adf44b521d710b81f11bda17d1
4
+ data.tar.gz: bb370586b9e8ff441156be67dcc9b296c7a445602100a8d571b49db406ee9300
5
5
  SHA512:
6
- metadata.gz: dc6fccdfa2a4e1b534218b0d37ca175e6b5e339bc493130569ee3e0649c4a4505e52d358d28be3ab2de90c9b2cc7f74beb4c8fed9afffaadc2ab7f3877ed5e33
7
- data.tar.gz: 0a5c756b3e12e9dd69c156ba2fe8360dd7caf3612a623641c45f08bf18b8fcffe9790687bf344141cd149f877907b41fbb9a2f0270a4546dbf3e555b031e7a66
6
+ metadata.gz: 85b549b0bddf0e29f1ac29eb37b49a227f49a6d8fd44396c727bc47c067e6ecb9f9297f4f5cf1f4ae274ac96b7bdd7aad6a59a8453dd2b46ca748d6f5585e44d
7
+ data.tar.gz: 45c5c8fd2a446bec85814198e8e609e67011758ddac0f2d8529ef8854f2a4b51d4a389f39f9f72ad7614c738f675b9bbc366901217bb94e50e8a98e4427e1f17
@@ -53,6 +53,8 @@ module ActsAsRoleRestricted
53
53
  end
54
54
 
55
55
  module ClassMethods
56
+ def acts_as_role_restricted?; true; end
57
+
56
58
  # Call with for_role(:admin) or for_role(@user.roles) or for_role([:admin, :member]) or for_role(:admin, :member, ...)
57
59
 
58
60
  # Returns all records which have been assigned any of the the given roles
@@ -87,17 +89,42 @@ module ActsAsRoleRestricted
87
89
  end
88
90
  end
89
91
 
92
+ def roles
93
+ EffectiveRoles.roles_for(roles_mask)
94
+ end
95
+
90
96
  def roles=(roles)
91
97
  self.roles_mask = EffectiveRoles.roles_mask_for(roles)
92
98
  end
93
99
 
94
- def roles
95
- EffectiveRoles.roles_for(roles_mask)
100
+ def add_role(role)
101
+ raise('expected role to be a symbol') unless role.kind_of?(Symbol)
102
+ raise('unknown role') unless EffectiveRoles.roles_mask_for(role) > 0
103
+
104
+ assign_attributes(roles: roles | [role])
105
+ end
106
+
107
+ def add_role!(role)
108
+ add_role(role); save!
109
+ end
110
+
111
+ def remove_role(role)
112
+ raise('expected role to be a symbol') unless role.kind_of?(Symbol)
113
+ raise('unknown role') unless EffectiveRoles.roles_mask_for(role) > 0
114
+
115
+ assign_attributes(roles: roles - [role])
116
+ end
117
+
118
+ def remove_role!(role)
119
+ remove_role(role); save!
96
120
  end
97
121
 
98
122
  # if user.is? :admin
99
123
  def is?(role)
100
- roles.include?(role.try(:to_sym))
124
+ raise('expected role to be a symbol') unless role.kind_of?(Symbol)
125
+ raise('unknown role') unless EffectiveRoles.roles_mask_for(role) > 0
126
+
127
+ roles.include?(role)
101
128
  end
102
129
 
103
130
  # if user.is_any?(:admin, :editor)
@@ -4,7 +4,7 @@ module EffectiveRoles
4
4
 
5
5
  # Include acts_as_addressable concern and allow any ActiveRecord object to call it
6
6
  initializer 'effective_roles.active_record' do |app|
7
- ActiveSupport.on_load :active_record do
7
+ app.config.to_prepare do
8
8
  ActiveRecord::Base.extend(ActsAsRoleRestricted::Base)
9
9
  end
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveRoles
2
- VERSION = '2.2.1'.freeze
2
+ VERSION = '2.3.2'.freeze
3
3
  end
@@ -102,12 +102,7 @@ module EffectiveRoles
102
102
  assignable_roles
103
103
  end.uniq
104
104
 
105
- # Check boxes
106
- multiple = resource.acts_as_role_restricted_options[:multiple] if multiple.nil?
107
- return assigned_roles if multiple
108
-
109
- # Radios
110
- (resource.roles - assigned_roles).present? ? [] : assigned_roles
105
+ assigned_roles
111
106
  end
112
107
 
113
108
  def self.assignable_roles_present?(resource)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_roles
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-15 00:00:00.000000000 Z
11
+ date: 2022-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails