caber 0.2.0 → 0.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 +10 -0
- data/app/models/concerns/caber/object.rb +8 -0
- data/lib/caber/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71093a528267100a6e810a9906de6dc3bde29357d54f9b4557926c0d9ce5852b
|
4
|
+
data.tar.gz: cdcfda7d716bc8e5f9fd307d803ce8eba968477e724a872e03f8e088c02da0a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47d31508f48f5390523980e2507e6654412f4eca34e5af152cbb704fb4b7b72a35020189edf1afe41e04db3f88cd080f69f815a0546578e1719734c88a147b06
|
7
|
+
data.tar.gz: 2b48730f693d2ca3425ae70d2df0f950dfaa6dc24a353cbcba06bd08696772ed3cf3c668b2cce7c28e2b99d536ef87ac79ba76adb342fc03e4d6bccd164f4f73
|
data/README.md
CHANGED
@@ -114,6 +114,14 @@ document.revoke_permission("viewer", user)
|
|
114
114
|
document.revoke_all_permissions(user)
|
115
115
|
```
|
116
116
|
|
117
|
+
### Finding objects
|
118
|
+
|
119
|
+
You can get lists of objects that a user has some permission on:
|
120
|
+
|
121
|
+
```
|
122
|
+
Document.granted_to "viewer", user
|
123
|
+
# => All the documents that user has "viewer" permission on
|
124
|
+
```
|
117
125
|
|
118
126
|
## Development
|
119
127
|
|
@@ -135,3 +143,5 @@ This gem was created as part of [Manyfold](https://manyfold.app), with funding f
|
|
135
143
|
|
136
144
|
[<img src="https://nlnet.nl/logo/banner.png" alt="NLnet foundation logo" width="20%" />](https://nlnet.nl)
|
137
145
|
[<img src="https://nlnet.nl/image/logos/NGI0_tag.svg" alt="NGI Zero Logo" width="20%" />](https://nlnet.nl/entrust)
|
146
|
+
|
147
|
+
Name: `"ReBAC".downcase.reverse`
|
@@ -8,6 +8,14 @@ module Caber::Object
|
|
8
8
|
def self.can_grant_permissions_to(model)
|
9
9
|
has_many :"permitted_#{model.name.pluralize.parameterize}", through: :caber_relations, source: :subject, source_type: model.name
|
10
10
|
end
|
11
|
+
|
12
|
+
scope :granted_to, ->(permission, subject) {
|
13
|
+
includes(:caber_relations).where(
|
14
|
+
"caber_relations.subject_id": subject.id,
|
15
|
+
"caber_relations.subject_type": subject.class.name,
|
16
|
+
"caber_relations.permission": permission
|
17
|
+
)
|
18
|
+
}
|
11
19
|
end
|
12
20
|
|
13
21
|
def grant_permission_to(permission, subject)
|
data/lib/caber/version.rb
CHANGED