Add API endpoints to interact with organiztion roles · KnpLabs/php-github-api@1f77a93 · GitHub
Skip to content

Commit 1f77a93

Browse files
committed
Add API endpoints to interact with organiztion roles
1 parent 71fec50 commit 1f77a93

5 files changed

Lines changed: 363 additions & 0 deletions

File tree

‎doc/README.md‎

Lines changed: 1 addition & 0 deletions
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
## Organization / Webhooks API
2+
[Back to the navigation](../README.md)
3+
4+
Listing, showing, assigning, and removing orgniazationroles.
5+
Wraps [GitHub Organization Roles API](https://docs.github.com/en/rest/orgs/organization-roles).
6+
7+
Additional APIs:
8+
* [Organization](../doc/organization)
9+
10+
### List all organizaton roles in an organization
11+
12+
> Requires [authentication](../security.md).
13+
14+
```php
15+
$roles = $client->organization()->organizationRoles()->all('acme');
16+
```
17+
18+
Returns a counter and a list of organization roles in the organization.
19+
20+
### Get an organization role in an organization
21+
22+
> Requires [authentication](../security.md).
23+
24+
```php
25+
$role = $client->organization()->organizationRoles()->show('acme', 123);
26+
```
27+
28+
Returns a single organization role in the organization.
29+
30+
### List all teams with role assigned in an organization
31+
32+
> Requires [authentication](../security.md).
33+
34+
```php
35+
$users = $client->organization()->organizationRoles()->listTeamsWithRole('acme', 1);
36+
```
37+
38+
Returns a list of teams with the role assigned to them.
39+
40+
### Assign a single role to a team in an organization
41+
42+
> Requires [authentication](../security.md).
43+
44+
```php
45+
$client->organization()->organizationRoles()->assignRoleToTeam('acme', 1, 'admin-user');
46+
```
47+
48+
No content is returned.
49+
50+
### Remove a single role from a team in an organization
51+
52+
> Requires [authentication](../security.md).
53+
54+
```php
55+
$client->organization()->organizationRoles()->removeRoleFromTeam('acme', 1, 'admin-team');
56+
```
57+
58+
No content is returned.
59+
60+
### Remove all roles from a team in an organization
61+
62+
> Requires [authentication](../security.md).
63+
64+
```php
65+
$client->organization()->organizationRoles()->removeAllRolesFromTeam('acme', 'admin-team');
66+
```
67+
68+
No content is returned.
69+
70+
### List all users with role assigned in an organization
71+
72+
> Requires [authentication](../security.md).
73+
74+
```php
75+
$users = $client->organization()->organizationRoles()->listUsersWithRole('acme', 1);
76+
```
77+
78+
Returns a list of users with the role assigned to them.
79+
80+
### Assign a single role to a user in an organization
81+
82+
> Requires [authentication](../security.md).
83+
84+
```php
85+
$client->organization()->organizationRoles()->assignRoleToUser('acme', 1, 'admin-user');
86+
```
87+
88+
No content is returned.
89+
90+
### Remove a single role from a user in an organization
91+
92+
> Requires [authentication](../security.md).
93+
94+
```php
95+
$client->organization()->organizationRoles()->removeRoleFromUser('acme', 1, 'admin-user');
96+
```
97+
98+
No content is returned.
99+
100+
### Remove all roles from a user in an organization
101+
102+
> Requires [authentication](../security.md).
103+
104+
```php
105+
$client->organization()->organizationRoles()->removeAllRolesFromUser('acme', 'admin-user');
106+
```
107+
108+
No content is returned.

‎lib/Github/Api/Organization.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Github\Api\Organization\Actions\Variables;
88
use Github\Api\Organization\Hooks;
99
use Github\Api\Organization\Members;
10+
use Github\Api\Organization\OrganizationRoles;
1011
use Github\Api\Organization\OutsideCollaborators;
1112
use Github\Api\Organization\SecretScanning;
1213
use Github\Api\Organization\Teams;
@@ -158,4 +159,9 @@ public function secretScanning(): SecretScanning
158159
{
159160
return new SecretScanning($this->getClient());
160161
}
162+
163+
public function organizationRoles(): OrganizationRoles
164+
{
165+
return new OrganizationRoles($this->getClient());
166+
}
161167
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Github\Api\Organization;
4+
5+
use Github\Api\AbstractApi;
6+
7+
/**
8+
* @link https://docs.github.com/en/rest/orgs/organization-roles
9+
*/
10+
class OrganizationRoles extends AbstractApi
11+
{
12+
public function all(string $organization)
13+
{
14+
return $this->get('/orgs/'.rawurlencode($organization).'/organization-roles');
15+
}
16+
17+
public function show(string $organization, int $roleId)
18+
{
19+
return $this->get('/orgs/'.rawurlencode($organization).'/organization-roles/'.$roleId);
20+
}
21+
22+
public function listTeamsWithRole(string $organization, int $roleId)
23+
{
24+
return $this->get('/orgs/'.rawurlencode($organization).'/organization-roles/'.$roleId.'/teams');
25+
}
26+
27+
public function assignRoleToTeam(string $organization, int $roleId, string $teamSlug): void
28+
{
29+
$this->put('/orgs/'.rawurlencode($organization).'/organization-roles/teams/'.rawurlencode($teamSlug).'/'.$roleId);
30+
}
31+
32+
public function removeRoleFromTeam(string $organization, int $roleId, string $teamSlug): void
33+
{
34+
$this->delete('/orgs/'.rawurlencode($organization).'/organization-roles/teams/'.rawurlencode($teamSlug).'/'.$roleId);
35+
}
36+
37+
public function removeAllRolesFromTeam(string $organization, string $teamSlug): void
38+
{
39+
$this->delete('/orgs/'.rawurlencode($organization).'/organization-roles/teams/'.rawurlencode($teamSlug));
40+
}
41+
42+
public function listUsersWithRole(string $organization, int $roleId): array
43+
{
44+
return $this->get('/orgs/'.rawurlencode($organization).'/organization-roles/'.$roleId.'/users');
45+
}
46+
47+
public function assignRoleToUser(string $organization, int $roleId, string $username): void
48+
{
49+
$this->put('/orgs/'.rawurlencode($organization).'/organization-roles/users/'.rawurlencode($username).'/'.$roleId);
50+
}
51+
52+
public function removeRoleFromUser(string $organization, int $roleId, string $username): void
53+
{
54+
$this->delete('/orgs/'.rawurlencode($organization).'/organization-roles/users/'.rawurlencode($username).'/'.$roleId);
55+
}
56+
57+
public function removeAllRolesFromUser(string $organization, string $username): void
58+
{
59+
$this->delete('/orgs/'.rawurlencode($organization).'/organization-roles/users/'.rawurlencode($username));
60+
}
61+
}
Lines changed: 187 additions & 0 deletions

0 commit comments

Comments
 (0)