caber 0.2.0 → 0.3.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: 32626bb698069dab3797b3fe532bce89def4fc6a91c0662e030b93df58c7b0c4
4
- data.tar.gz: 999efb197f1567376feb709b6d2e77d83d2d4d0f79e42ecdae8c7e2429997f9d
3
+ metadata.gz: 71093a528267100a6e810a9906de6dc3bde29357d54f9b4557926c0d9ce5852b
4
+ data.tar.gz: cdcfda7d716bc8e5f9fd307d803ce8eba968477e724a872e03f8e088c02da0a5
5
5
  SHA512:
6
- metadata.gz: 67c2028ca5dd0aead722b9ea20961c41e2fe8fe6733c4b68b732f08f4292b32b568ac7f3b6e49d0f30168b01cc7c78ff457f319410c7e504856640c57800c605
7
- data.tar.gz: 868d630bf81d19a45b9ff058cdac098ccb6115f985e1a9c0426e30243ed6b36e8dbf2b16b3da1a68e889906d2b571cf1aed9beac62ed9ce4940f6ee638cec7a9
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
@@ -1,3 +1,3 @@
1
1
  module Caber
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith