mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 22:43:19 +00:00
Add /me route on API v1
This commit is contained in:
@@ -728,6 +728,12 @@ class V1 implements ControllerProviderInterface
|
|||||||
})->assert('databox_id', '\d+')->assert('story_id', '\d+');
|
})->assert('databox_id', '\d+')->assert('story_id', '\d+');
|
||||||
$controllers->get('/stories/{any_id}/{anyother_id}/', $bad_request_exception);
|
$controllers->get('/stories/{any_id}/{anyother_id}/', $bad_request_exception);
|
||||||
|
|
||||||
|
$controllers->get('/me/', function (SilexApplication $app, Request $request) {
|
||||||
|
$result = $app['api']->get_current_user($app, $request);
|
||||||
|
|
||||||
|
return $result->get_response();
|
||||||
|
});
|
||||||
|
|
||||||
return $controllers;
|
return $controllers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1949,6 +1949,53 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_current_user(Application $app, Request $request)
|
||||||
|
{
|
||||||
|
$result = new API_V1_result($app, $request, $this);
|
||||||
|
$result->set_datas(array('user' => $this->list_user($app['authentication']->getUser())));
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function list_user(\User_Adapter $user)
|
||||||
|
{
|
||||||
|
switch ($user->get_gender()) {
|
||||||
|
case 2;
|
||||||
|
$gender = 'Mr';
|
||||||
|
break;
|
||||||
|
case 1;
|
||||||
|
$gender = 'Mrs';
|
||||||
|
break;
|
||||||
|
case 0;
|
||||||
|
$gender = 'Miss';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'id' => $user->get_id(),
|
||||||
|
'email' => $user->get_email() ?: null,
|
||||||
|
'login' => $user->get_login() ?: null,
|
||||||
|
'first_name' => $user->get_firstname() ?: null,
|
||||||
|
'last_name' => $user->get_lastname() ?: null,
|
||||||
|
'display_name' => $user->get_display_name() ?: null,
|
||||||
|
'gender' => $gender,
|
||||||
|
'address' => $user->get_address() ?: null,
|
||||||
|
'zip_code' => $user->get_zipcode() ?: null,
|
||||||
|
'city' => $user->get_city() ?: null,
|
||||||
|
'country' => $user->get_country() ?: null,
|
||||||
|
'phone' => $user->get_tel() ?: null,
|
||||||
|
'fax' => $user->get_fax() ?: null,
|
||||||
|
'job' => $user->get_job() ?: null,
|
||||||
|
'position' => $user->get_position() ?: null,
|
||||||
|
'company' => $user->get_company() ?: null,
|
||||||
|
'geoname_id' => $user->get_geonameid() ?: null,
|
||||||
|
'last_connection' => $user->get_last_connection() ? $user->get_last_connection()->format(DATE_ATOM) : null,
|
||||||
|
'created_on' => $user->get_creation_date() ? $user->get_creation_date()->format(DATE_ATOM) : null,
|
||||||
|
'updated_on' => $user->get_modification_date() ? $user->get_modification_date()->format(DATE_ATOM) : null,
|
||||||
|
'locale' => $user->get_locale() ?: null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all databoxes of the current appbox
|
* List all databoxes of the current appbox
|
||||||
*
|
*
|
||||||
|
@@ -2051,6 +2051,53 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
|||||||
$this->assertDateAtom($item['created_on']);
|
$this->assertDateAtom($item['created_on']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRouteMe()
|
||||||
|
{
|
||||||
|
$this->setToken(self::$token);
|
||||||
|
|
||||||
|
$route = '/api/v1/me/';
|
||||||
|
|
||||||
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||||
|
|
||||||
|
self::$DI['client']->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||||
|
$content = $this->unserialize(self::$DI['client']->getResponse()->getContent());
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('user', $content['response']);
|
||||||
|
|
||||||
|
$this->evaluateGoodUserItem($content['response']['user'], self::$DI['user_notAdmin']);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function evaluateGoodUserItem($data, \User_Adapter $user)
|
||||||
|
{
|
||||||
|
foreach (array(
|
||||||
|
'id' => $user->get_id(),
|
||||||
|
'email' => $user->get_email() ?: null,
|
||||||
|
'login' => $user->get_login() ?: null,
|
||||||
|
'first_name' => $user->get_firstname() ?: null,
|
||||||
|
'last_name' => $user->get_lastname() ?: null,
|
||||||
|
'display_name' => $user->get_display_name() ?: null,
|
||||||
|
'address' => $user->get_address() ?: null,
|
||||||
|
'zip_code' => $user->get_zipcode() ?: null,
|
||||||
|
'city' => $user->get_city() ?: null,
|
||||||
|
'country' => $user->get_country() ?: null,
|
||||||
|
'phone' => $user->get_tel() ?: null,
|
||||||
|
'fax' => $user->get_fax() ?: null,
|
||||||
|
'job' => $user->get_job() ?: null,
|
||||||
|
'position' => $user->get_position() ?: null,
|
||||||
|
'company' => $user->get_company() ?: null,
|
||||||
|
'geoname_id' => $user->get_geonameid() ?: null,
|
||||||
|
'last_connection' => $user->get_last_connection() ? $user->get_last_connection()->format(DATE_ATOM) : null,
|
||||||
|
'created_on' => $user->get_creation_date() ? $user->get_creation_date()->format(DATE_ATOM) : null,
|
||||||
|
'updated_on' => $user->get_modification_date() ? $user->get_modification_date()->format(DATE_ATOM) : null,
|
||||||
|
'locale' => $user->get_locale() ?: null,
|
||||||
|
) as $key => $value) {
|
||||||
|
$this->assertArrayHasKey($key, $data);
|
||||||
|
if ($value) {
|
||||||
|
$this->assertEquals($value, $data[$key], 'Check key '.$key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function evaluateGoodFeed($feed)
|
protected function evaluateGoodFeed($feed)
|
||||||
{
|
{
|
||||||
$this->assertArrayHasKey('id', $feed);
|
$this->assertArrayHasKey('id', $feed);
|
||||||
|
Reference in New Issue
Block a user