Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing resourceId casting #32

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ Checks to see if the current caller has permission to do something.
can(
string|array $action,
string|\BeatSwitch\Lock\Resources\Resource $resource = null,
int $resourceId = null
string $resourceId = null
)
```

Expand All @@ -533,7 +533,7 @@ Checks to see if it's forbidden for the current caller to do something.
cannot(
string|array $action,
string|\BeatSwitch\Lock\Resources\Resource $resource = null,
int $resourceId = null
string $resourceId = null
)
```

Expand All @@ -545,7 +545,7 @@ Sets a `Privilege` permission on a caller to allow it to do something. Removes a
allow(
string|array $action,
string|\BeatSwitch\Lock\Resources\Resource $resource = null,
int $resourceId = null,
string $resourceId = null,
\BeatSwitch\Lock\Permissions\Condition[] $conditions = []
)
```
Expand All @@ -558,7 +558,7 @@ Sets a `Restriction` permission on a caller to prevent it from doing something.
deny(
string|array $action,
string|\BeatSwitch\Lock\Resources\Resource $resource = null,
int $resourceId = null,
string $resourceId = null,
\BeatSwitch\Lock\Permissions\Condition[] $conditions = []
)
```
Expand All @@ -571,7 +571,7 @@ Toggles the value for the given permission.
toggle(
string|array $action,
string|\BeatSwitch\Lock\Resources\Resource $resource = null,
int $resourceId = null
string $resourceId = null
)
```

Expand Down Expand Up @@ -674,15 +674,15 @@ We'll assume we have a `CallerPermission` model class with at least the followin
- `type` (varchar, 10)
- `action` (varchar, 100)
- `resource_type` (varchar, 100, nullable)
- `resource_id` (int, 11, nullable)
- `resource_id` (varchar, 36, nullable)

And we have a `RolePermission` model with the following database columns:

- `role` (varchar, 100)
- `type` (varchar, 10)
- `action` (varchar, 100)
- `resource_type` (varchar, 100, nullable)
- `resource_id` (int, 11, nullable)
- `resource_id` (varchar, 36, nullable)

Let's check out a full implementation of the driver below. Notice that for the `getCallerPermissions` method we're using the `PermissionFactory` class to easily map the data and create `Permission` objects from them. The `PermissionFactory`'s `createFromData` method will accept both arrays and objects.

Expand Down
12 changes: 12 additions & 0 deletions src/Drivers/ArrayDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ public function hasRolePermission(Role $role, Permission $permission)
return false;
}

/**
* Removes all permissions for a resource, used
* for performance-critical massive removals.
*
* @param \BeatSwitch\Lock\Resources\Resource
* @return void
*/
public function clearPermissionsForResource(Resource $resource)
{
throw new \Exception('Unimplemented method "ArrayDriver::clearPermissionsForResource"');
}

/**
* Creates a key to store the caller's permissions
*
Expand Down
10 changes: 10 additions & 0 deletions src/Drivers/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use BeatSwitch\Lock\Callers\Caller;
use BeatSwitch\Lock\Permissions\Permission;
use BeatSwitch\Lock\Roles\Role;
use BeatSwitch\Lock\Resources\Resource;

/**
* A contract to identify an implementation to store permissions to
Expand Down Expand Up @@ -82,4 +83,13 @@ public function removeRolePermission(Role $role, Permission $permission);
* @return bool
*/
public function hasRolePermission(Role $role, Permission $permission);

/**
* Removes all permissions for a resource, used
* for performance-critical massive removals.
*
* @param \BeatSwitch\Lock\Resources\Resource
* @return void
*/
public function clearPermissionsForResource(Resource $resource);
}
Loading