effective_roles 2.5.0 → 2.7.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff6ad1f95215dd736ce5bd90f0754ea6504a1227acaec9941fd18a7734cedd29
|
4
|
+
data.tar.gz: 21ae8733e66d032ad5079bbf61877f968f2f6b036d1c69be1114500750a15cea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab959b54a62a9d139532fba9051e49dcbc0b614dcb6421ca856377544c2a36bf085438f8df56d1179a3b2b948d90cfdbb73fea29f806e341df474792178e1565
|
7
|
+
data.tar.gz: 675002338facfd196544a287588d2693ff617afddd506ea9b04122128edc34f2af3f087331d2fcff689f41a762c0522f1ce859bcb7915c053dad4b48c638faa6
|
@@ -1,4 +1,21 @@
|
|
1
1
|
module EffectiveRolesHelper
|
2
|
+
|
3
|
+
def roles_badges(obj)
|
4
|
+
roles = Array(obj.try(:roles) || obj) - [nil, '']
|
5
|
+
|
6
|
+
if (unexpected = roles - EffectiveRoles.roles).present?
|
7
|
+
raise "Unexpected value: #{unexpected}. Expected an acts_as_roleable object or an array of roles."
|
8
|
+
end
|
9
|
+
|
10
|
+
badges = roles.map do |role|
|
11
|
+
color = EffectiveRoles.color(role)
|
12
|
+
|
13
|
+
content_tag(:span, role, class: ("badge badge-#{color}" if color.present?), title: role.to_s.titleize)
|
14
|
+
end
|
15
|
+
|
16
|
+
badges.join(' ').html_safe
|
17
|
+
end
|
18
|
+
|
2
19
|
def effective_roles_summary(obj, options = {}) # User or a Post, any acts_as_roleable
|
3
20
|
raise 'expected an acts_as_roleable object' unless obj.respond_to?(:roles)
|
4
21
|
|
@@ -73,7 +73,11 @@ module ActsAsRoleRestricted
|
|
73
73
|
def with_role_sql(*roles)
|
74
74
|
roles = roles.flatten.compact
|
75
75
|
roles = roles.first.roles if roles.length == 1 && roles.first.respond_to?(:roles)
|
76
|
-
roles =
|
76
|
+
roles = roles.map { |role| role.to_sym }
|
77
|
+
|
78
|
+
if(invalid = (roles - EffectiveRoles.roles)).present?
|
79
|
+
raise("unknown role :#{invalid.to_sentence}")
|
80
|
+
end
|
77
81
|
|
78
82
|
roles.map { |role| "(#{self.table_name}.roles_mask & %d > 0)" % 2**EffectiveRoles.roles.index(role) }.join(' OR ')
|
79
83
|
end
|
@@ -81,7 +85,11 @@ module ActsAsRoleRestricted
|
|
81
85
|
def without_role(*roles)
|
82
86
|
roles = roles.flatten.compact
|
83
87
|
roles = roles.first.roles if roles.length == 1 && roles.first.respond_to?(:roles)
|
84
|
-
roles =
|
88
|
+
roles = roles.map { |role| role.to_sym }
|
89
|
+
|
90
|
+
if(invalid = (roles - EffectiveRoles.roles)).present?
|
91
|
+
raise("unknown role :#{invalid.to_sentence}")
|
92
|
+
end
|
85
93
|
|
86
94
|
where(
|
87
95
|
roles.map { |role| "NOT(#{self.table_name}.roles_mask & %d > 0)" % 2**EffectiveRoles.roles.index(role) }.join(' AND ')
|
data/config/effective_roles.rb
CHANGED
@@ -23,11 +23,17 @@ EffectiveRoles.setup do |config|
|
|
23
23
|
# Or just keep it simple, and use this Hash syntax of permissions for every resource
|
24
24
|
#
|
25
25
|
config.role_descriptions = {
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
26
|
+
superadmin: 'full access to everything. Can manage users and all website content.',
|
27
|
+
admin: 'full access to website content. Cannot manage users.',
|
28
|
+
member: 'cannot access admin area. Can see all content in members-only sections of the website.'
|
29
29
|
}
|
30
30
|
|
31
|
+
# config.role_colors
|
32
|
+
# ========================
|
33
|
+
# Assign a bootstrap color to a role. Optional.
|
34
|
+
# Used by the roles_badges() helper to display this role as a badge
|
35
|
+
# config.role_colors = { superadmin: :primary, admin: :secondary, member: :light }
|
36
|
+
|
31
37
|
# config.assignable_roles
|
32
38
|
# Which roles can be assigned by whom
|
33
39
|
# =======================
|
data/lib/effective_roles.rb
CHANGED
@@ -5,7 +5,7 @@ require 'effective_roles/version'
|
|
5
5
|
module EffectiveRoles
|
6
6
|
|
7
7
|
def self.config_keys
|
8
|
-
[:roles, :role_descriptions, :assignable_roles, :layout]
|
8
|
+
[:roles, :role_descriptions, :role_colors, :assignable_roles, :layout]
|
9
9
|
end
|
10
10
|
|
11
11
|
include EffectiveGem
|
@@ -39,6 +39,11 @@ module EffectiveRoles
|
|
39
39
|
roles_for(roles).map { |r| 2 ** config.roles.index(r) }.sum
|
40
40
|
end
|
41
41
|
|
42
|
+
def self.color(role)
|
43
|
+
raise('expected a role') unless role.kind_of?(Symbol)
|
44
|
+
(role_colors || {})[role]
|
45
|
+
end
|
46
|
+
|
42
47
|
def self.roles_collection(resource, current_user = nil, only: nil, except: nil, multiple: nil, skip_disabled: nil)
|
43
48
|
if assignable_roles.present?
|
44
49
|
raise('expected object to respond to is_role_restricted?') unless resource.respond_to?(:is_role_restricted?)
|
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.
|
4
|
+
version: 2.7.0
|
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:
|
11
|
+
date: 2024-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|