Skip to content

Commit cb294a7

Browse files
committed
TODOs
1 parent 863ebbb commit cb294a7

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ Rabarber::Role.all_names # All roles grouped by context
136136
# Get users assigned to a role
137137
Rabarber::Role.assignees(:admin)
138138
```
139+
<!-- TODO: maybe Rabarber all these methods should be namespaced under Rabarber, i.e. Rabarber.add_role to hide existence of the model -->
140+
<!-- TODO: in this case names and all_names must be Rabarber.roles and Rabarber.all_roles respectively, seems more readable -->
139141

140142
## Controller Authorization
141143

@@ -181,11 +183,6 @@ class TicketsController < ApplicationController
181183
def index
182184
# Accessible to admin, manager, and support roles
183185
end
184-
185-
grant_access action: :destroy, roles: :owner, context: -> { Ticket.find(params[:id]) }
186-
def destroy
187-
# Accessible to admin and owner of the ticket
188-
end
189186
end
190187
```
191188

@@ -244,9 +241,7 @@ class ApplicationController < ActionController::Base
244241
private
245242

246243
def when_unauthorized
247-
# Default behavior: redirect back (HTML) or return 403 (other formats)
248-
# Custom behavior example:
249-
head :not_found # Hide existence of protected resources
244+
head :not_found # Custom behavior to hide existence of protected resources
250245
end
251246
end
252247
```
@@ -288,7 +283,7 @@ end
288283

289284
## Multi-tenancy / Context
290285

291-
All Rabarber methods accept a `context` parameter, allowing you to work with roles within specific scopes rather than globally.
286+
All Rabarber methods accept a `context` parameter, allowing you to work with roles within specific scopes. By default, context is `nil`, meaning roles are global.
292287

293288
### Contextual Role Assignment
294289

@@ -304,6 +299,9 @@ user.assign_roles(:admin, context: Project)
304299
user.has_role?(:owner, context: project)
305300
user.has_role?(:admin, context: Project)
306301

302+
# Revoke roles within a specific context
303+
user.revoke_roles(:owner, context: project)
304+
307305
# Get roles within context
308306
user.roles(context: project)
309307
Rabarber::Role.names(context: Project)
@@ -341,11 +339,11 @@ end
341339
Handle context changes when models are renamed or removed. These are irreversible data migrations.
342340

343341
```rb
344-
# Rename a context class (e.g., when you rename your Project model to Campaign)
345-
migrate_authorization_context!("Project", "Campaign")
342+
# Rename a context class (e.g., when you rename your Ticket model to Task)
343+
migrate_authorization_context!("Ticket", "Task")
346344

347-
# Remove orphaned context data (e.g., when you delete a model entirely)
348-
delete_authorization_context!("DeletedModel")
345+
# Remove orphaned context data (e.g., when you delete Ticket model entirely)
346+
delete_authorization_context!("Ticket")
349347
```
350348

351349
## View Helpers

lib/rabarber/inputs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def resolve_context(value)
5353
when Class
5454
{ context_type: value.to_s, context_id: nil }
5555
when ActiveRecord::Base
56-
# TODO: this should be included in the type definition somehow
56+
# TODO: this should be included in the type definition somehow, or maybe it makes sense to use dey-validation
5757
raise Dry::Types::CoercionError, "instance context not persisted" unless value.persisted?
5858

5959
{ context_type: value.class.to_s, context_id: value.public_send(value.class.primary_key) }

0 commit comments

Comments
 (0)