invitational 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/app/services/invitational/checks_for_invitation.rb +6 -2
- data/lib/invitational/cancan.rb +24 -13
- data/lib/invitational/version.rb +1 -1
- metadata +2 -7
- data/app/assets/javascripts/invitational/application.js +0 -15
- data/app/assets/stylesheets/invitational/application.css +0 -13
- data/app/controllers/invitational/application_controller.rb +0 -4
- data/app/helpers/invitational/application_helper.rb +0 -4
- data/app/views/layouts/invitational/application.html.erb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35c05aee3ab709cc47a1e71a237f376e122a0235
|
4
|
+
data.tar.gz: cb2dd18f0d4de8fbc32b460aebfb2b4506ff255d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbebbf65af7035028eadad8fdae4aa0a29e288b057f06aa6ff4d37dcea42cc9b12d7a8b106147d875baec782b1e1e2c9f4d5b27b45b4bb9e9a4a41659b7949ce
|
7
|
+
data.tar.gz: 5b45c2359e524077bb1ad9ab7695ee6379c88bcf0acfec744ea40364c54422d8158a4fc4db6abe5bd7432319327cbd471c36989445d5c6a9787c80de9d59eeaa
|
data/README.md
CHANGED
@@ -227,9 +227,9 @@ You can test to see if the a user is an uberadmin through:
|
|
227
227
|
current_user.uberadmin?
|
228
228
|
```
|
229
229
|
|
230
|
-
##
|
230
|
+
##CanCanCan
|
231
231
|
|
232
|
-
Invitational adds a new condition key to
|
232
|
+
Invitational adds a new condition key to CanCanCan's abilities, `:role`. This allows you to define the role(s)
|
233
233
|
that a user must be invited into for a specific entity in order to perform the specified action. For example,
|
234
234
|
to indicate that a user invited to a parent entity in an admin role can manage the parent entity, but a user
|
235
235
|
invited to a staff role can only read the parent entity, in your `ability.rb` file:
|
@@ -237,6 +237,7 @@ invited to a staff role can only read the parent entity, in your `ability.rb` fi
|
|
237
237
|
```
|
238
238
|
can :manage, Parent, roles: [:admin]
|
239
239
|
can :read, Parent, roles: [:staff]
|
240
|
+
cannot :edit, Parent, roles: [:consultant]
|
240
241
|
```
|
241
242
|
|
242
243
|
###System Roles
|
@@ -1,8 +1,12 @@
|
|
1
1
|
module Invitational
|
2
2
|
class ChecksForInvitation
|
3
3
|
|
4
|
-
def self.for user, invitable, roles=nil
|
5
|
-
|
4
|
+
def self.for user, invitable, roles=nil, role_specific=false
|
5
|
+
if role_specific
|
6
|
+
self.specific_invite?(user, invitable, roles)
|
7
|
+
else
|
8
|
+
self.uberadmin?(user) || self.specific_invite?(user, invitable, roles)
|
9
|
+
end
|
6
10
|
end
|
7
11
|
|
8
12
|
private
|
data/lib/invitational/cancan.rb
CHANGED
@@ -7,13 +7,24 @@ module Invitational
|
|
7
7
|
roles = conditions.delete(:roles) if conditions
|
8
8
|
conditions = nil if conditions and conditions.empty?
|
9
9
|
|
10
|
-
block ||= setup_role_based_block_for roles, subject, action
|
10
|
+
block ||= setup_role_based_block_for roles, subject, action, false
|
11
11
|
end
|
12
12
|
|
13
13
|
rules << ::CanCan::Rule.new(true, action, subject, conditions, block)
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def cannot(action = nil, subject = nil, conditions = nil, &block)
|
17
|
+
if conditions && conditions.has_key?(:roles)
|
18
|
+
roles = conditions.delete(:roles) if conditions
|
19
|
+
conditions = nil if conditions and conditions.empty?
|
20
|
+
|
21
|
+
block ||= setup_role_based_block_for roles, subject, action, true
|
22
|
+
end
|
23
|
+
|
24
|
+
rules << ::CanCan::Rule.new(false, action, subject, conditions, block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def setup_role_based_block_for roles, subject, action, role_specific
|
17
28
|
key = subject.name.underscore + action.to_s
|
18
29
|
|
19
30
|
if roles.respond_to? :values
|
@@ -30,35 +41,35 @@ module Invitational
|
|
30
41
|
|
31
42
|
block = ->(model){
|
32
43
|
roles = role_mappings[key]
|
33
|
-
check_permission_for model, user, roles
|
44
|
+
check_permission_for model, user, roles, role_specific
|
34
45
|
}
|
35
46
|
|
36
47
|
block
|
37
48
|
end
|
38
49
|
|
39
|
-
def check_permission_for model, user, in_roles
|
50
|
+
def check_permission_for model, user, in_roles, role_specific
|
40
51
|
|
41
52
|
in_roles.inject(false) do |result,role|
|
42
53
|
result || if role.respond_to? :values
|
43
|
-
check_permission_for_keyed_roles model, user, role
|
54
|
+
check_permission_for_keyed_roles model, user, role, role_specific
|
44
55
|
else
|
45
|
-
Invitational::ChecksForInvitation.for(user, model, role)
|
56
|
+
Invitational::ChecksForInvitation.for(user, model, role, role_specific)
|
46
57
|
end
|
47
58
|
end
|
48
59
|
|
49
60
|
end
|
50
61
|
|
51
|
-
def check_permission_for_keyed_roles model, user, role
|
62
|
+
def check_permission_for_keyed_roles model, user, role, role_specific
|
52
63
|
key = role.keys.first
|
53
64
|
|
54
65
|
if key == :system_roles
|
55
|
-
check_permission_for_system_role user, role
|
66
|
+
check_permission_for_system_role user, role, role_specific
|
56
67
|
else
|
57
|
-
check_permission_for_attribute model, user, role
|
68
|
+
check_permission_for_attribute model, user, role, role_specific
|
58
69
|
end
|
59
70
|
end
|
60
71
|
|
61
|
-
def check_permission_for_system_role user, role
|
72
|
+
def check_permission_for_system_role user, role, role_specific
|
62
73
|
roles = role.values.flatten
|
63
74
|
|
64
75
|
user.uberadmin? || roles.any? do |system_role|
|
@@ -66,16 +77,16 @@ module Invitational
|
|
66
77
|
end
|
67
78
|
end
|
68
79
|
|
69
|
-
def check_permission_for_attribute model, user, role
|
80
|
+
def check_permission_for_attribute model, user, role, role_specific
|
70
81
|
method = role.keys.first
|
71
82
|
related = model.send(method)
|
72
83
|
|
73
84
|
if related.respond_to? :any?
|
74
85
|
related.any? do |model|
|
75
|
-
check_permission_for model, user, role.values.flatten
|
86
|
+
check_permission_for model, user, role.values.flatten, role_specific
|
76
87
|
end
|
77
88
|
else
|
78
|
-
check_permission_for related, user, role.values.flatten
|
89
|
+
check_permission_for related, user, role.values.flatten, role_specific
|
79
90
|
end
|
80
91
|
end
|
81
92
|
|
data/lib/invitational/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: invitational
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Goerlich
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -135,10 +135,6 @@ files:
|
|
135
135
|
- MIT-LICENSE
|
136
136
|
- README.md
|
137
137
|
- Rakefile
|
138
|
-
- app/assets/javascripts/invitational/application.js
|
139
|
-
- app/assets/stylesheets/invitational/application.css
|
140
|
-
- app/controllers/invitational/application_controller.rb
|
141
|
-
- app/helpers/invitational/application_helper.rb
|
142
138
|
- app/modules/invitational/accepts_invitation_as.rb
|
143
139
|
- app/modules/invitational/invitation_core.rb
|
144
140
|
- app/modules/invitational/invited_to.rb
|
@@ -148,7 +144,6 @@ files:
|
|
148
144
|
- app/services/invitational/creates_invitation.rb
|
149
145
|
- app/services/invitational/creates_system_user_invitation.rb
|
150
146
|
- app/services/invitational/creates_uber_admin_invitation.rb
|
151
|
-
- app/views/layouts/invitational/application.html.erb
|
152
147
|
- config/routes.rb
|
153
148
|
- db/migrate/20130528220144_create_invitations.rb
|
154
149
|
- lib/generators/invitational/install/USAGE
|
@@ -1,15 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// the compiled file.
|
9
|
-
//
|
10
|
-
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
-
// GO AFTER THE REQUIRES BELOW.
|
12
|
-
//
|
13
|
-
//= require jquery
|
14
|
-
//= require jquery_ujs
|
15
|
-
//= require_tree .
|
@@ -1,13 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
-
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
-
*
|
11
|
-
*= require_self
|
12
|
-
*= require_tree .
|
13
|
-
*/
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Invitational</title>
|
5
|
-
<%= stylesheet_link_tag "invitational/application", :media => "all" %>
|
6
|
-
<%= javascript_include_tag "invitational/application" %>
|
7
|
-
<%= csrf_meta_tags %>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
<%= yield %>
|
12
|
-
|
13
|
-
</body>
|
14
|
-
</html>
|