caber 0.3.0 → 0.4.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: f6bda935480f7b69fe515d693078cec12122b527fee405b593f83bda85dc6ba8
|
4
|
+
data.tar.gz: afde1293ded688ea93031794a4197465e9d799aa17c6ac8c8b0dca7897135e60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb3c8cbb9113114a4bb9d96686c839007b4809c445ead3a583d1f966a5ddb0aa1e824a612a49f31d517dcf167a56509327150182671b0d76ecee632a139c541e
|
7
|
+
data.tar.gz: 0dfa0445dbcfb9f78cf410b048b222809c6899ee31efe8ad12257468c1aac991ff552087913288638094e6f078bc853bf48db65ec551673dd99a76aa413e1e65
|
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Caber
|
2
2
|
|
3
|
-
|
3
|
+
![Gem Downloads (for latest version)](https://img.shields.io/gem/dtv/caber)
|
4
|
+
![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/rubygems/caber)
|
5
|
+
![Dependent repos (via libraries.io)](https://img.shields.io/librariesio/dependent-repos/rubygems/caber)
|
6
|
+
|
7
|
+
|
8
|
+
A simple [ReBAC](https://en.wikipedia.org/wiki/Relationship-based_access_control) / [Zanzibar](https://research.google/pubs/zanzibar-googles-consistent-global-authorization-system/) backend plugin for Rails apps. Allows you to easily specify permission relationships between pairs of objects, e.g. granting edit permission on a document to a specific user, like in Google Docs.
|
4
9
|
|
5
10
|
## Installation
|
6
11
|
|
@@ -123,6 +128,49 @@ Document.granted_to "viewer", user
|
|
123
128
|
# => All the documents that user has "viewer" permission on
|
124
129
|
```
|
125
130
|
|
131
|
+
## Usage with other gems
|
132
|
+
|
133
|
+
### Pundit
|
134
|
+
|
135
|
+
Caber makes for nice clear [Pundit](https://github.com/varvet/pundit) policies:
|
136
|
+
|
137
|
+
```
|
138
|
+
class DocumentPolicy < ApplicationPolicy
|
139
|
+
class Scope < ApplicationPolicy::Scope
|
140
|
+
def resolve
|
141
|
+
scope.granted_to(["viewer", "editor", "owner"], user)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def update?
|
146
|
+
record.grants_permission_to? ["editor", "owner"], user
|
147
|
+
end
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
151
|
+
### Rolify
|
152
|
+
|
153
|
+
Caber doesn't include groups specifically, but you can integrate it easily with a role management gem like [Rolify](https://github.com/RolifyCommunity/rolify) pretty easily. Make your Role class a subject, and you can grant permissions to roles:
|
154
|
+
|
155
|
+
```
|
156
|
+
class Document < ApplicationRecord
|
157
|
+
include Caber::Object
|
158
|
+
can_grant_permissions_to Role
|
159
|
+
end
|
160
|
+
|
161
|
+
class Role < ApplicationRecord
|
162
|
+
include Caber::Subject
|
163
|
+
can_have_permissions_on Document
|
164
|
+
|
165
|
+
scopify
|
166
|
+
end
|
167
|
+
|
168
|
+
document.grant_permission_to "editor", Role.find_by(name: "editor")
|
169
|
+
|
170
|
+
User.with_role(document.permitted_roles.with_permission("editor"))
|
171
|
+
# => all users with a role that can edit the document
|
172
|
+
```
|
173
|
+
|
126
174
|
## Development
|
127
175
|
|
128
176
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
@@ -131,11 +179,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
131
179
|
|
132
180
|
## Contributing
|
133
181
|
|
134
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/manyfold3d/caber. This project is intended to be a safe, welcoming space for collaboration, and
|
135
|
-
|
136
|
-
## Code of Conduct
|
137
|
-
|
138
|
-
Everyone interacting in the Caber project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/manyfold3d/caber/blob/master/CODE_OF_CONDUCT.md).
|
182
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/manyfold3d/caber. This project is intended to be a safe, welcoming space for collaboration; everyone interacting in the Caber project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/manyfold3d/caber/blob/master/CODE_OF_CONDUCT.md).
|
139
183
|
|
140
184
|
## Acknowledgements
|
141
185
|
|
@@ -11,15 +11,16 @@ module Caber::Object
|
|
11
11
|
|
12
12
|
scope :granted_to, ->(permission, subject) {
|
13
13
|
includes(:caber_relations).where(
|
14
|
-
"caber_relations.
|
15
|
-
"caber_relations.subject_type": subject.class.name,
|
14
|
+
"caber_relations.subject": subject,
|
16
15
|
"caber_relations.permission": permission
|
17
16
|
)
|
18
17
|
}
|
19
18
|
end
|
20
19
|
|
21
20
|
def grant_permission_to(permission, subject)
|
22
|
-
Caber::Relation.
|
21
|
+
rel = Caber::Relation.find_or_initialize_by(subject: subject, object: self)
|
22
|
+
rel.permission = permission
|
23
|
+
rel.save!
|
23
24
|
end
|
24
25
|
|
25
26
|
def grants_permission_to?(permission, subject)
|
data/lib/caber/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|