Commit 15175eb5 authored by Florian Azizian's avatar Florian Azizian

FIX #11270 TIME 0:20 get custom fields

parent 77e4e5fe
......@@ -128,6 +128,7 @@ $app->get('/contactsFilling', \Contact\controllers\ContactController::class . ':
$app->put('/contactsFilling', \Contact\controllers\ContactController::class . ':updateFilling');
//CustomFields
$app->get('/customFields', \CustomField\controllers\CustomFieldController::class . ':get');
$app->post('/customFields', \CustomField\controllers\CustomFieldController::class . ':create');
$app->put('/customFields/{id}', \CustomField\controllers\CustomFieldController::class . ':update');
$app->delete('/customFields/{id}', \Contact\controllers\ContactController::class . ':delete');
......
......@@ -26,6 +26,21 @@ use Slim\Http\Response;
class CustomFieldController
{
public function get(Request $request, Response $response)
{
if (!ServiceModel::hasService(['id' => 'admin_custom_fields', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
$customFields = CustomFieldModel::get();
foreach ($customFields as $key => $customField) {
$customFields[$key]['values'] = json_decode($customField['values'], true);
}
return $response->withJson(['customFields' => $customFields]);
}
public function create(Request $request, Response $response)
{
if (!ServiceModel::hasService(['id' => 'admin_custom_fields', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
......
......@@ -54,6 +54,18 @@ class CustomFieldControllerTest extends TestCase
$this->assertSame('Custom field with this label already exists', $responseBody->errors);
}
public function testReadList()
{
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$customFieldController = new \CustomField\controllers\CustomFieldController();
$response = $customFieldController->get($request, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertNotNull($responseBody->customFields);
}
public function testUpdate()
{
$customFieldController = new \CustomField\controllers\CustomFieldController();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment