Skip to content

Commit c1e882f

Browse files
committed
Document expiring grants and the prune command
Adds an Expiring grants section to README covering assignRoleUntil, givePermissionToUntil, the prune command and the expiry-propagates-from-role rule. Lists the new command in the Artisan commands block. CHANGELOG.md gains a 1.1.0 entry inventorying every new surface in this release.
1 parent 95ddd37 commit c1e882f

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [1.1.0] - 2026-05-18
10+
11+
### Added
12+
- `HasRoles::assignRoleUntil($role, $expiresAt)` — grant a role
13+
with an expiry timestamp.
14+
- `HasPermissions::givePermissionToUntil($permission, $expiresAt)`
15+
grant a permission with an expiry timestamp.
16+
- `permission:prune-expired` Artisan command to garbage-collect
17+
expired grant subdocs from user documents, with `--dry-run` and
18+
`--user-model=` options.
19+
- `Webrek\MongoPermission\Support\Expiry` helper centralizing
20+
expiry normalization between `DateTimeInterface`, BSON
21+
`UTCDateTime` and unix timestamps.
22+
- Composer keywords (`laravel`, `mongodb`, `permissions`, `roles`,
23+
`rbac`, `acl`, `authorization`, `multi-tenant`, `wildcard`) and
24+
`support.issues` / `support.source` URLs for Packagist surfacing.
25+
- CHANGELOG.md following Keep-a-Changelog.
26+
- README section comparing this package with
27+
`spatie/laravel-permission`.
28+
- README section "Expiring grants" documenting the new API and the
29+
prune command.
30+
31+
### Changed
32+
- `PermissionRegistrar` slug cache now stores grant entries with
33+
their expiry attached and re-filters expired entries on every
34+
read. Slug arrays returned by `getUserPermissionSlugs` and
35+
`getUserRoleSlugs` are unchanged in shape.
36+
- A role assignment's expiry propagates to every permission reached
37+
through that role: when the assignment expires, those permissions
38+
stop counting in `hasPermissionTo` and `getAllPermissions`.
39+
940
## [1.0.0] - 2026-05-18
1041

1142
### Added
@@ -45,5 +76,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4576
teams, strict isolation, wildcards, middlewares, Blade, Gate and
4677
commands.
4778

48-
[Unreleased]: https://github.com/webrek/laravel-mongo-permission/compare/v1.0.0...HEAD
79+
[Unreleased]: https://github.com/webrek/laravel-mongo-permission/compare/v1.1.0...HEAD
80+
[1.1.0]: https://github.com/webrek/laravel-mongo-permission/compare/v1.0.0...v1.1.0
4981
[1.0.0]: https://github.com/webrek/laravel-mongo-permission/releases/tag/v1.0.0

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,38 @@ Assignments made while a team is active are scoped to that team. Reads
137137
honor the active team. Setting `permission.strict_team_isolation = true`
138138
disables the "team_id = null is global" fallback.
139139

140+
## Expiring grants
141+
142+
Roles and permissions can be granted with an expiry. The grant
143+
stays on the user document but stops counting toward checks the
144+
moment `now()` passes the `expires_at` timestamp — even if the
145+
cache was warmed before the expiry.
146+
147+
```php
148+
$user->assignRoleUntil('admin', now()->addHours(2));
149+
$user->givePermissionToUntil('publish posts', now()->addDays(7));
150+
151+
$user->hasRole('admin'); // true for two hours
152+
$user->hasPermissionTo('publish posts'); // true for seven days
153+
154+
// After the expiry passes:
155+
$user->hasRole('admin'); // false
156+
```
157+
158+
Expired subdocs are not removed automatically. Run the prune
159+
command on a schedule (or ad-hoc) to garbage-collect them and free
160+
space on user documents:
161+
162+
```bash
163+
php artisan permission:prune-expired
164+
php artisan permission:prune-expired --dry-run
165+
php artisan permission:prune-expired --user-model="App\\Models\\User"
166+
```
167+
168+
A role granted with an expiry propagates that expiry to every
169+
permission reached through the role — once the role assignment
170+
expires, those permissions stop counting too.
171+
140172
## Wildcard permissions
141173

142174
`enable_wildcard_permission` defaults to `true`. Patterns use `.` as the
@@ -219,6 +251,7 @@ php artisan permission:create-role admin [--guard=web] [perm1 perm2 ...]
219251
php artisan permission:create-permission "edit articles" [--guard=web]
220252
php artisan permission:show [--guard=web] [--team=...]
221253
php artisan permission:cache-reset
254+
php artisan permission:prune-expired [--user-model=...] [--dry-run]
222255
```
223256

224257
## Configuration

0 commit comments

Comments
 (0)