From 956466497ad0076cb6d0443bd6da027482b77e73 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Thu, 26 Apr 2018 18:07:56 +0200 Subject: [PATCH] FEAT #7387 #7388 Add users from entities and groups --- core/Test/AutocompleteControllerTest.php | 2 +- src/app/entity/controllers/EntityController.php | 1 + src/app/user/controllers/UserController.php | 4 ++-- src/core/lang/lang-en.php | 2 ++ src/core/lang/lang-fr.php | 2 ++ 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/Test/AutocompleteControllerTest.php b/core/Test/AutocompleteControllerTest.php index 38a912a7ca7..2e68b6d6155 100644 --- a/core/Test/AutocompleteControllerTest.php +++ b/core/Test/AutocompleteControllerTest.php @@ -50,7 +50,7 @@ class AutocompleteControllerTest extends TestCase $this->assertNotEmpty($responseBody); $this->assertSame('user', $responseBody[0]->type); - $this->assertInternalType('string', $responseBody[0]->id); + $this->assertInternalType('int', $responseBody[0]->id); $this->assertNotEmpty($responseBody[0]->id); $this->assertInternalType('string', $responseBody[0]->idToDisplay); $this->assertNotEmpty($responseBody[0]->idToDisplay); diff --git a/src/app/entity/controllers/EntityController.php b/src/app/entity/controllers/EntityController.php index 3c7bb27ba7f..e05b4ca0088 100644 --- a/src/app/entity/controllers/EntityController.php +++ b/src/app/entity/controllers/EntityController.php @@ -145,6 +145,7 @@ class EntityController $entity['instances'] = count($instances); $redirects = BasketModel::getGroupActionRedirect(['select' => [1], 'where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]); $entity['redirects'] = count($redirects); + $entity['canAdminUsers'] = ServiceModel::hasService(['id' => 'admin_users', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin']); return $response->withJson(['entity' => $entity]); } diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index 22b4f6f3377..9d993de9aa8 100644 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -633,7 +633,7 @@ class UserController if (empty($group)) { return $response->withStatus(400)->withJson(['errors' => 'Group not found']); } elseif (UserModel::hasGroup(['id' => $aArgs['id'], 'groupId' => $data['groupId']])) { - return $response->withStatus(400)->withJson(['errors' => 'User is already linked to this group']); + return $response->withStatus(400)->withJson(['errors' => _USER_ALREADY_LINK_GROUP]); } if (empty($data['role'])) { $data['role'] = ''; @@ -745,7 +745,7 @@ class UserController if (empty(EntityModel::getById(['entityId' => $data['entityId']]))) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } elseif (UserModel::hasEntity(['id' => $aArgs['id'], 'entityId' => $data['entityId']])) { - return $response->withStatus(400)->withJson(['errors' => 'User is already linked to this entity']); + return $response->withStatus(400)->withJson(['errors' => _USER_ALREADY_LINK_ENTITY]); } if (empty($data['role'])) { $data['role'] = ''; diff --git a/src/core/lang/lang-en.php b/src/core/lang/lang-en.php index 83d8ea51deb..2553deed59e 100644 --- a/src/core/lang/lang-en.php +++ b/src/core/lang/lang-en.php @@ -75,6 +75,8 @@ define('_USER_GROUP_SUPPRESSION', 'Group deleted for user'); define('_USER_ENTITY_CREATION', 'Entity added for user'); define('_USER_ENTITY_MODIFICATION', 'Entity updated for user'); define('_USER_ENTITY_SUPPRESSION', 'Entity deleted for user'); +define('_USER_ALREADY_LINK_GROUP', 'User is already linked to this group'); +define('_USER_ALREADY_LINK_ENTITY', 'User is already linked to this entity'); define('_VISA_USER', 'For visa'); define('_WRONG_FILE_TYPE', 'This type of file is not allowed'); define('_CAN_NOT_MOVE_IN_CHILD_ENTITY', 'Parent entity must not be a subentity'); diff --git a/src/core/lang/lang-fr.php b/src/core/lang/lang-fr.php index d8e3ad5979f..1d40889e155 100644 --- a/src/core/lang/lang-fr.php +++ b/src/core/lang/lang-fr.php @@ -75,6 +75,8 @@ define('_USER_GROUP_SUPPRESSION', 'Groupe supprimé pour utilisateur'); define('_USER_ENTITY_CREATION', 'Entité ajoutée pour utilisateur'); define('_USER_ENTITY_MODIFICATION', 'Entité modifiée pour utilisateur'); define('_USER_ENTITY_SUPPRESSION', 'Entité supprimée pour utilisateur'); +define('_USER_ALREADY_LINK_GROUP', 'L\'utilisateur est déjà lié à ce groupe'); +define('_USER_ALREADY_LINK_ENTITY', 'L\'utilisateur est déjà lié à cette entité'); define('_VISA_USER', 'Pour visa'); define('_WRONG_FILE_TYPE', 'Ce type de fichier n\'est pas permis'); define('_CAN_NOT_MOVE_IN_CHILD_ENTITY', 'L\'entité parente ne doit pas être dans une entité fille'); -- GitLab