caber 0.3.0 → 0.3.1

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: 71093a528267100a6e810a9906de6dc3bde29357d54f9b4557926c0d9ce5852b
4
- data.tar.gz: cdcfda7d716bc8e5f9fd307d803ce8eba968477e724a872e03f8e088c02da0a5
3
+ metadata.gz: 3e3022bcc88c31576a8e8f204063bb1cb3a3a2365cee60f5d5d8769779821719
4
+ data.tar.gz: 9509f57e488c365e11cba921957db94d0f518e476f5457f56c8f12a39c160f54
5
5
  SHA512:
6
- metadata.gz: 47d31508f48f5390523980e2507e6654412f4eca34e5af152cbb704fb4b7b72a35020189edf1afe41e04db3f88cd080f69f815a0546578e1719734c88a147b06
7
- data.tar.gz: 2b48730f693d2ca3425ae70d2df0f950dfaa6dc24a353cbcba06bd08696772ed3cf3c668b2cce7c28e2b99d536ef87ac79ba76adb342fc03e4d6bccd164f4f73
6
+ metadata.gz: 6c3fb313ae9125c1bf96a857be7abc2b8c2dead1aa4a8e1c9347d08c3e3b2dbe634e6919dac1ccafb673e97002855d0b1ded604fc77d64e4da1b0055b8ba744e
7
+ data.tar.gz: bb2d952b4fe708bc50194f167bf11cd01fdfdaf5d02a64a50a9c2cd8d3d8f66d0980d84f1c1922f54237cf216bd958788edbbe0b447f7229381c6bf211ed9f52
data/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Caber
2
2
 
3
- A simple ReBAC / Zanzibar gem for Rails apps.
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 contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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,8 +11,7 @@ module Caber::Object
11
11
 
12
12
  scope :granted_to, ->(permission, subject) {
13
13
  includes(:caber_relations).where(
14
- "caber_relations.subject_id": subject.id,
15
- "caber_relations.subject_type": subject.class.name,
14
+ "caber_relations.subject": subject,
16
15
  "caber_relations.permission": permission
17
16
  )
18
17
  }
data/lib/caber/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Caber
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith