Skip to content

Commit fe666bd

Browse files
committed
Merge pull request KnpLabs#217 from guillermoandrae/master
Added user suspension & un-suspension, resolves KnpLabs#207.
2 parents fd6a5f9 + 81105b8 commit fe666bd

File tree

5 files changed

+118
-1
lines changed

5 files changed

+118
-1
lines changed

doc/enterprise.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
Provides information about a GitHub Enterprise installation. Wraps [GitHub Enterprise API](http://developer.github.com/v3/enterprise/).
55

6+
### Configuration
67
In order to configure the client to point to a GitHub Enterprise installation, do the following:
78

89
```php
@@ -20,5 +21,23 @@ $client->setEnterpriseUrl('https://ghe.host');
2021
$repositories = $client->api('user')->repositories('ornicar');
2122
```
2223

23-
To use the Stats and License APIs, you will need to authenticate using a GitHub Enterprise site admin account.
24+
### Authentication
25+
The Admin Stats, License, and User Administration API endpoints are only accessible to GitHub Enterprise site administrators. The Management Console API endpoints are only accessible via the Management Console password.
2426

27+
### User Administration
28+
29+
#### Suspend a user (Enterprise only)
30+
31+
> Requires [authentication](security.md).
32+
33+
```php
34+
$client->api('enterprise')->userAdmin()->suspend('ornicar');
35+
```
36+
37+
#### Unsuspend a user (Enterprise only)
38+
39+
> Requires [authentication](security.md).
40+
41+
```php
42+
$client->api('enterprise')->userAdmin()->unsuspend('ornicar');
43+
```

lib/Github/Api/Enterprise.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Github\Api\Enterprise\ManagementConsole;
66
use Github\Api\Enterprise\Stats;
77
use Github\Api\Enterprise\License;
8+
use Github\Api\Enterprise\UserAdmin;
89

910
/**
1011
* Getting information about a GitHub Enterprise instance.
@@ -38,4 +39,12 @@ public function console()
3839
{
3940
return new ManagementConsole($this->client);
4041
}
42+
43+
/**
44+
* @return UserAdmin
45+
*/
46+
public function userAdmin()
47+
{
48+
return new UserAdmin($this->client);
49+
}
4150
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Github\Api\Enterprise;
4+
5+
use Github\Api\AbstractApi;
6+
7+
class UserAdmin extends AbstractApi
8+
{
9+
/**
10+
* Suspend a user
11+
*
12+
* @link https://developer.github.com/v3/users/administration/#suspend-a-user
13+
*
14+
* @param string $username
15+
*
16+
* @return array
17+
*/
18+
public function suspend($username)
19+
{
20+
return $this->put('users/'.rawurldecode($username).'/suspended', array('Content-Length' => 0));
21+
}
22+
23+
/**
24+
* Unsuspend a user
25+
*
26+
* @link https://developer.github.com/v3/users/administration/#unsuspend-a-user
27+
*
28+
* @param string $username
29+
*
30+
* @return array
31+
*/
32+
public function unsuspend($username)
33+
{
34+
return $this->delete('users/'.rawurldecode($username).'/suspended');
35+
}
36+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace Github\Tests\Api\Enterprise;
3+
4+
use Github\Tests\Api\TestCase;
5+
6+
class UserAdminTest extends TestCase
7+
{
8+
/**
9+
* @test
10+
*/
11+
public function shouldSuspendUser()
12+
{
13+
$expectedArray = array();
14+
15+
$api = $this->getApiMock();
16+
$api->expects($this->once())
17+
->method('put')
18+
->with('users/l3l0/suspended')
19+
->will($this->returnValue($expectedArray));
20+
$this->assertEquals($expectedArray, $api->suspend('l3l0'));
21+
}
22+
23+
/**
24+
* @test
25+
*/
26+
public function shouldUnsuspendUser()
27+
{
28+
$expectedArray = array();
29+
30+
$api = $this->getApiMock();
31+
$api->expects($this->once())
32+
->method('delete')
33+
->with('users/l3l0/suspended')
34+
->will($this->returnValue($expectedArray));
35+
36+
$this->assertEquals($expectedArray, $api->unsuspend('l3l0'));
37+
}
38+
39+
protected function getApiClass()
40+
{
41+
return 'Github\Api\Enterprise\UserAdmin';
42+
}
43+
}

test/Github/Tests/Api/EnterpriseTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ public function shouldGetEnterpriseManagementConsoleApiObject()
3434
$this->assertInstanceOf('Github\Api\Enterprise\ManagementConsole', $api->console());
3535
}
3636

37+
/**
38+
* @test
39+
*/
40+
public function shouldGetEnterpriseUserAdminApiObject()
41+
{
42+
$api = $this->getApiMock();
43+
44+
$this->assertInstanceOf('Github\Api\Enterprise\UserAdmin', $api->userAdmin());
45+
}
46+
3747
protected function getApiClass()
3848
{
3949
return 'Github\Api\Enterprise';

0 commit comments

Comments
 (0)