From 201a1741839c6ee1d53c5529bd517e91a81da65c Mon Sep 17 00:00:00 2001 From: Vinciane <vinciane.bizet@maarch.org> Date: Mon, 11 Feb 2019 19:02:21 +0100 Subject: [PATCH] ROLLBACK #9422 --- src/app/user/controllers/UserController.php | 40 ++++++++++--------- src/app/user/models/UserModelAbstract.php | 3 +- .../user/user-administration.component.ts | 2 +- .../unitTests/app/user/UserControllerTest.php | 18 ++++----- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index 0e7c00bbcff..235eb3671ef 100755 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -164,16 +164,17 @@ class UserController return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); } - $existingUser = UserModel::get([ - 'select' => ['id', 'status'], - 'where' => ['lower(user_id) = lower(?)'], - 'data' => [$data['userId']], - 'limit' => 1 - ]); - - if(!empty($existingUser)){ - $existingUser = $existingUser[0]; - } + $existingUser = UserModel::getByLogin(['login' => $data['userId'], 'select' => ['id', 'status']]); + // $existingUser = UserModel::get([ + // 'select' => ['id', 'status'], + // 'where' => ['lower(user_id) = lower(?)'], + // 'data' => [$data['userId']], + // 'limit' => 1 + // ]); + + // if(!empty($existingUser)){ + // $existingUser = $existingUser[0]; + // } if (!empty($existingUser) && $existingUser['status'] == 'DEL') { UserModel::updateStatus(['id' => $existingUser['id'], 'status' => 'OK']); @@ -493,16 +494,17 @@ class UserController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $user = UserModel::get([ - 'select' => ['status'], - 'where' => ['lower(user_id) = lower(?)'], - 'data' => [$aArgs['userId']], - 'limit' => 1 - ]); + $user = UserModel::getByLogin(['login' => $aArgs['userId'], 'select' => ['status']]); + // $user = UserModel::get([ + // 'select' => ['status'], + // 'where' => ['lower(user_id) = lower(?)'], + // 'data' => [$aArgs['userId']], + // 'limit' => 1 + // ]); - if(!empty($user)){ - $user = $user[0]; - } + // if(!empty($user)){ + // $user = $user[0]; + // } return $response->withJson(['status' => $user['status']]); } diff --git a/src/app/user/models/UserModelAbstract.php b/src/app/user/models/UserModelAbstract.php index 976add721c1..3c4b08e7c36 100755 --- a/src/app/user/models/UserModelAbstract.php +++ b/src/app/user/models/UserModelAbstract.php @@ -67,7 +67,8 @@ abstract class UserModelAbstract DatabaseModel::insert([ 'table' => 'users', 'columnsValues' => [ - 'user_id' => strtolower($aArgs['user']['userId']), + //'user_id' => strtolower($aArgs['user']['userId']), + 'user_id' => $aArgs['user']['userId'], 'firstname' => $aArgs['user']['firstname'], 'lastname' => $aArgs['user']['lastname'], 'mail' => $aArgs['user']['mail'], diff --git a/src/frontend/app/administration/user/user-administration.component.ts b/src/frontend/app/administration/user/user-administration.component.ts index 45aa36784fb..7c3b4167f62 100755 --- a/src/frontend/app/administration/user/user-administration.component.ts +++ b/src/frontend/app/administration/user/user-administration.component.ts @@ -557,7 +557,7 @@ export class UserAdministrationComponent extends AutoCompletePlugin implements O if (this.creationMode) { var r = true; - this.user.userId = this.user.userId.toLowerCase(); + //this.user.userId = this.user.userId.toLowerCase(); this.http.get(this.coreUrl + "rest/users/" + this.user.userId + "/status") .subscribe((data: any) => { diff --git a/test/unitTests/app/user/UserControllerTest.php b/test/unitTests/app/user/UserControllerTest.php index 977063d5661..0898097f57f 100755 --- a/test/unitTests/app/user/UserControllerTest.php +++ b/test/unitTests/app/user/UserControllerTest.php @@ -61,7 +61,7 @@ class UserControllerTest extends TestCase $responseBody = json_decode((string)$response->getBody()); $this->assertSame(self::$id, $responseBody->id); - $this->assertSame('test-ckent', $responseBody->user_id); + $this->assertSame('TEST-CKENT', $responseBody->user_id); $this->assertSame('TEST-CLARK', $responseBody->firstname); $this->assertSame('TEST-KENT', $responseBody->lastname); $this->assertSame('OK', $responseBody->status); @@ -80,7 +80,7 @@ class UserControllerTest extends TestCase $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); $request = \Slim\Http\Request::createFromEnvironment($environment); $aArgs = [ - 'user_id' => 'test-ckent', + 'user_id' => 'TEST-CKENT', 'firstname' => 'TEST-CLARK2', 'lastname' => 'TEST-KENT2', 'mail' => 'ck@dailyP.com', @@ -89,7 +89,7 @@ class UserControllerTest extends TestCase 'enabled' => 'N', ]; $fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request); - + $response = $userController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]); $responseBody = json_decode((string)$response->getBody()); @@ -102,7 +102,7 @@ class UserControllerTest extends TestCase $responseBody = json_decode((string)$response->getBody()); $this->assertSame(self::$id, $responseBody->id); - $this->assertSame('test-ckent', $responseBody->user_id); + $this->assertSame('TEST-CKENT', $responseBody->user_id); $this->assertSame('TEST-CLARK2', $responseBody->firstname); $this->assertSame('TEST-KENT2', $responseBody->lastname); $this->assertSame('OK', $responseBody->status); @@ -347,7 +347,7 @@ class UserControllerTest extends TestCase $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getStatusByUserId($request, new \Slim\Http\Response(), ['userId' => 'test-ckent']); + $response = $userController->getStatusByUserId($request, new \Slim\Http\Response(), ['userId' => 'TEST-CKENT']); $responseBody = json_decode((string)$response->getBody()); $this->assertSame('OK', $responseBody->status); @@ -386,7 +386,7 @@ class UserControllerTest extends TestCase $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']); $request = \Slim\Http\Request::createFromEnvironment($environment); - $response = $userController->getStatusByUserId($request, new \Slim\Http\Response(), ['userId' => 'test-ckent']); + $response = $userController->getStatusByUserId($request, new \Slim\Http\Response(), ['userId' => 'TEST-CKENT']); $responseBody = json_decode((string)$response->getBody()); $this->assertSame('ABS', $responseBody->status); @@ -466,7 +466,7 @@ class UserControllerTest extends TestCase $environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'PUT']); $request = \Slim\Http\Request::createFromEnvironment($environment); $aArgs = [ - 'user_id' => 'test-ckentquota', + 'user_id' => 'TEST-CKENTquota', 'firstname' => 'TEST-CLARKquota2', 'lastname' => 'TEST-KENTquota2', 'mail' => 'ck@dailyP.com', @@ -483,7 +483,7 @@ class UserControllerTest extends TestCase // UPDATE disabled user for user_quota (avoid notification sending) $aArgs = [ - 'user_id' => 'test-ckentquota', + 'user_id' => 'TEST-CKENTquota', 'firstname' => 'TEST-CLARKquota2', 'lastname' => 'TEST-KENTquota2', 'mail' => 'ck@dailyP.com', @@ -636,7 +636,7 @@ class UserControllerTest extends TestCase $responseBody = json_decode((string)$response->getBody()); $this->assertSame(self::$id, $responseBody->id); - $this->assertSame('test-ckent', $responseBody->user_id); + $this->assertSame('TEST-CKENT', $responseBody->user_id); $this->assertSame('TEST-CLARK2', $responseBody->firstname); $this->assertSame('TEST-KENT2', $responseBody->lastname); $this->assertSame('DEL', $responseBody->status); -- GitLab