diff --git a/doc/enterprise.md b/doc/enterprise.md index b4673061e74..9e38f13dce6 100644 --- a/doc/enterprise.md +++ b/doc/enterprise.md @@ -3,6 +3,7 @@ Provides information about a GitHub Enterprise installation. Wraps [GitHub Enterprise API](http://developer.github.com/v3/enterprise/). +### Configuration In order to configure the client to point to a GitHub Enterprise installation, do the following: ```php @@ -20,5 +21,23 @@ $client->setEnterpriseUrl('https://ghe.host'); $repositories = $client->api('user')->repositories('ornicar'); ``` -To use the Stats and License APIs, you will need to authenticate using a GitHub Enterprise site admin account. +### Authentication +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. +### User Administration + +#### Suspend a user (Enterprise only) + +> Requires [authentication](security.md). + +```php +$client->api('enterprise')->userAdmin()->suspend('ornicar'); +``` + +#### Unsuspend a user (Enterprise only) + +> Requires [authentication](security.md). + +```php +$client->api('enterprise')->userAdmin()->unsuspend('ornicar'); +``` diff --git a/lib/Github/Api/Enterprise.php b/lib/Github/Api/Enterprise.php index 48f90f06b27..c23171a6614 100644 --- a/lib/Github/Api/Enterprise.php +++ b/lib/Github/Api/Enterprise.php @@ -5,6 +5,7 @@ use Github\Api\Enterprise\ManagementConsole; use Github\Api\Enterprise\Stats; use Github\Api\Enterprise\License; +use Github\Api\Enterprise\UserAdmin; /** * Getting information about a GitHub Enterprise instance. @@ -38,4 +39,12 @@ public function console() { return new ManagementConsole($this->client); } + + /** + * @return UserAdmin + */ + public function userAdmin() + { + return new UserAdmin($this->client); + } } diff --git a/lib/Github/Api/Enterprise/UserAdmin.php b/lib/Github/Api/Enterprise/UserAdmin.php new file mode 100644 index 00000000000..d01a975515c --- /dev/null +++ b/lib/Github/Api/Enterprise/UserAdmin.php @@ -0,0 +1,36 @@ +put('users/'.rawurldecode($username).'/suspended', array('Content-Length' => 0)); + } + + /** + * Unsuspend a user + * + * @link https://developer.github.com/v3/users/administration/#unsuspend-a-user + * + * @param string $username + * + * @return array + */ + public function unsuspend($username) + { + return $this->delete('users/'.rawurldecode($username).'/suspended'); + } +} diff --git a/test/Github/Tests/Api/Enterprise/UserAdminTest.php b/test/Github/Tests/Api/Enterprise/UserAdminTest.php new file mode 100644 index 00000000000..42e6358bfff --- /dev/null +++ b/test/Github/Tests/Api/Enterprise/UserAdminTest.php @@ -0,0 +1,43 @@ +getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('users/l3l0/suspended') + ->will($this->returnValue($expectedArray)); + $this->assertEquals($expectedArray, $api->suspend('l3l0')); + } + + /** + * @test + */ + public function shouldUnsuspendUser() + { + $expectedArray = array(); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('users/l3l0/suspended') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->unsuspend('l3l0')); + } + + protected function getApiClass() + { + return 'Github\Api\Enterprise\UserAdmin'; + } +} \ No newline at end of file diff --git a/test/Github/Tests/Api/EnterpriseTest.php b/test/Github/Tests/Api/EnterpriseTest.php index cccd446c6d9..319e6e16232 100644 --- a/test/Github/Tests/Api/EnterpriseTest.php +++ b/test/Github/Tests/Api/EnterpriseTest.php @@ -34,6 +34,16 @@ public function shouldGetEnterpriseManagementConsoleApiObject() $this->assertInstanceOf('Github\Api\Enterprise\ManagementConsole', $api->console()); } + /** + * @test + */ + public function shouldGetEnterpriseUserAdminApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Enterprise\UserAdmin', $api->userAdmin()); + } + protected function getApiClass() { return 'Github\Api\Enterprise';