effective_roles 2.4.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/app/helpers/effective_roles_helper.rb +17 -0
- data/config/effective_roles.rb +9 -3
- data/lib/effective_roles/version.rb +1 -1
- data/lib/effective_roles.rb +6 -1
- metadata +89 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43ff04eb475329ae2001305352cb8131942fd2f598a5273868720aeede0ca553
|
4
|
+
data.tar.gz: 100d76c0b230bd759fbc222714de32f443e42e5ef21dc00495bd7e4c1a4ad684
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54b6b93166130c94368c9d39505d24181d66ec7b8c63dd5c0a2488672ef9fbab7e00658558c45e99d49d58cfdef6bc4c7f5918129af4a90cd5ce7666348025fd
|
7
|
+
data.tar.gz: 90bb9ab5d3b7d86efbfafdeef445d8a94bae9352ad199173b6e3a96d551a4d77a3fffb13a7e858aa35c836583ea0d0852b462af226cc31e66af252137a8f1ee3
|
data/MIT-LICENSE
CHANGED
@@ -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
|
|
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.6.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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: effective_resources
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,90 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: devise
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: effective_test_bot
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: effective_developer
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: psych
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "<"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '4'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "<"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '4'
|
41
125
|
description: Assign multiple roles to any User or other ActiveRecord object. Select
|
42
126
|
only the appropriate objects based on intelligent, chainable ActiveRecord::Relation
|
43
127
|
finder methods.
|
@@ -80,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
164
|
- !ruby/object:Gem::Version
|
81
165
|
version: '0'
|
82
166
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
167
|
+
rubygems_version: 3.3.7
|
84
168
|
signing_key:
|
85
169
|
specification_version: 4
|
86
170
|
summary: Assign multiple roles to any User or other ActiveRecord object. Select only
|