-
Notifications
You must be signed in to change notification settings - Fork 18
feat: Add RBAC permissions API support #337
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
80575f9
feat: Add RBAC permissions support with PATCH method
csrbarber 51653bc
fix: Use "organization" as default resource_type_slug in fixtures
csrbarber 26efda9
docs: Add PHPDoc blocks to RBAC permission methods
csrbarber d84c48f
feat: Add type hints to RBAC public method parameters
gjtorikian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| <?php | ||
|
|
||
| namespace WorkOS; | ||
|
|
||
| class RBAC | ||
| { | ||
| public const DEFAULT_PAGE_SIZE = 10; | ||
|
|
||
| /** | ||
| * Create a Permission. | ||
| * | ||
| * @param string $slug The slug of the Permission | ||
| * @param string $name The name of the Permission | ||
| * @param null|string $description The description of the Permission | ||
| * @param null|string $resourceTypeSlug The resource type slug of the Permission | ||
| * | ||
| * @throws Exception\WorkOSException | ||
| * | ||
| * @return Resource\Permission | ||
| */ | ||
| public function createPermission( | ||
| string $slug, | ||
| string $name, | ||
| ?string $description = null, | ||
| ?string $resourceTypeSlug = null | ||
| ) { | ||
csrbarber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $path = "authorization/permissions"; | ||
|
|
||
| $params = [ | ||
| "slug" => $slug, | ||
| "name" => $name, | ||
| ]; | ||
|
|
||
| if (isset($description)) { | ||
| $params["description"] = $description; | ||
| } | ||
| if (isset($resourceTypeSlug)) { | ||
| $params["resource_type_slug"] = $resourceTypeSlug; | ||
| } | ||
|
|
||
| $response = Client::request(Client::METHOD_POST, $path, null, $params, true); | ||
|
|
||
| return Resource\Permission::constructFromResponse($response); | ||
| } | ||
|
|
||
| /** | ||
| * List Permissions. | ||
| * | ||
| * @param int $limit Maximum number of records to return | ||
| * @param null|string $before Permission ID to look before | ||
| * @param null|string $after Permission ID to look after | ||
| * @param null|string $order The order in which to paginate records | ||
| * | ||
| * @throws Exception\WorkOSException | ||
| * | ||
| * @return array{?string, ?string, Resource\Permission[]} | ||
| */ | ||
| public function listPermissions( | ||
| int $limit = self::DEFAULT_PAGE_SIZE, | ||
| ?string $before = null, | ||
| ?string $after = null, | ||
| ?string $order = null | ||
| ) { | ||
| $path = "authorization/permissions"; | ||
|
|
||
| $params = [ | ||
| "limit" => $limit, | ||
| "before" => $before, | ||
| "after" => $after, | ||
| "order" => $order, | ||
| ]; | ||
|
|
||
| $response = Client::request(Client::METHOD_GET, $path, null, $params, true); | ||
|
|
||
| $permissions = []; | ||
| list($before, $after) = Util\Request::parsePaginationArgs($response); | ||
| foreach ($response["data"] as $responseData) { | ||
| \array_push($permissions, Resource\Permission::constructFromResponse($responseData)); | ||
| } | ||
|
|
||
| return [$before, $after, $permissions]; | ||
| } | ||
|
|
||
| /** | ||
| * Get a Permission. | ||
| * | ||
| * @param string $slug The slug of the Permission | ||
| * | ||
| * @throws Exception\WorkOSException | ||
| * | ||
| * @return Resource\Permission | ||
| */ | ||
| public function getPermission(string $slug) | ||
| { | ||
| $path = "authorization/permissions/{$slug}"; | ||
csrbarber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $response = Client::request(Client::METHOD_GET, $path, null, null, true); | ||
|
|
||
| return Resource\Permission::constructFromResponse($response); | ||
| } | ||
|
|
||
| /** | ||
| * Update a Permission. | ||
| * | ||
| * @param string $slug The slug of the Permission to update | ||
| * @param null|string $name The updated name of the Permission | ||
| * @param null|string $description The updated description of the Permission | ||
| * | ||
| * @throws Exception\WorkOSException | ||
| * | ||
| * @return Resource\Permission | ||
| */ | ||
| public function updatePermission( | ||
| string $slug, | ||
| ?string $name = null, | ||
| ?string $description = null | ||
| ) { | ||
| $path = "authorization/permissions/{$slug}"; | ||
|
|
||
| $params = []; | ||
|
|
||
| if (isset($name)) { | ||
| $params["name"] = $name; | ||
| } | ||
| if (isset($description)) { | ||
| $params["description"] = $description; | ||
| } | ||
|
|
||
| $response = Client::request(Client::METHOD_PATCH, $path, null, $params, true); | ||
|
|
||
| return Resource\Permission::constructFromResponse($response); | ||
| } | ||
csrbarber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Delete a Permission. | ||
| * | ||
| * @param string $slug The slug of the Permission to delete | ||
| * | ||
| * @throws Exception\WorkOSException | ||
| * | ||
| * @return array | ||
| */ | ||
| public function deletePermission(string $slug) | ||
| { | ||
| $path = "authorization/permissions/{$slug}"; | ||
|
|
||
| $response = Client::request(Client::METHOD_DELETE, $path, null, null, true); | ||
|
|
||
| return $response; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
|
|
||
| namespace WorkOS\Resource; | ||
|
|
||
| /** | ||
| * Class Permission. | ||
| * | ||
| * @property string $id | ||
| * @property string $slug | ||
| * @property string $name | ||
| * @property string $description | ||
| * @property string $resource_type_slug | ||
| * @property bool $system | ||
| * @property string $created_at | ||
| * @property string $updated_at | ||
| */ | ||
|
|
||
| class Permission extends BaseWorkOSResource | ||
| { | ||
| public const RESOURCE_TYPE = "permission"; | ||
|
|
||
| public const RESOURCE_ATTRIBUTES = [ | ||
| "id", | ||
| "slug", | ||
| "name", | ||
| "description", | ||
| "resource_type_slug", | ||
| "system", | ||
| "created_at", | ||
| "updated_at" | ||
| ]; | ||
|
|
||
| public const RESPONSE_TO_RESOURCE_KEY = [ | ||
| "id" => "id", | ||
| "slug" => "slug", | ||
| "name" => "name", | ||
| "description" => "description", | ||
| "resource_type_slug" => "resource_type_slug", | ||
| "system" => "system", | ||
| "created_at" => "created_at", | ||
| "updated_at" => "updated_at" | ||
| ]; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.