Commit a9be7c14 authored by Roman Ondráček's avatar Roman Ondráček

Core: remove password hash from user list method

Signed-off-by: Roman Ondráček's avatarRoman Ondráček <ondracek.roman@centrum.cz>
parent 47609dee
Pipeline #2083 passed with stages
in 13 minutes and 31 seconds
......@@ -71,7 +71,7 @@ class UserListCommand extends Command {
$header = ['ID', 'Username', 'Role', 'Language'];
$table = new Table($output);
$table->setHeaders($header);
$table->setRows($this->userManager->listUsers());
$table->setRows($this->userManager->getUsers());
$table->render();
return 0;
}
......
......@@ -61,26 +61,6 @@ class ConsoleUserManager extends UserManager {
return true;
}
/**
* Lists all registered users
* @return mixed[] Registered users
*/
public function listUsers(): array {
$users = $this->getUsers();
$this->removeHashes($users);
return $users;
}
/**
* Removes hashes from the information about the users
* @param mixed[] $users Information about the users
*/
private function removeHashes(array &$users): void {
foreach ($users as &$user) {
unset($user['password']);
}
}
/**
* Lists user names of all webapp's users
* @return mixed[] User names of all webapp's users
......
......@@ -121,7 +121,9 @@ class UserManager {
public function getUsers(): array {
$users = [];
foreach ($this->table->fetchAll() as $user) {
$users[] = $user->toArray();
$array = $user->toArray();
unset($array['password']);
$users[] = $array;
}
return $users;
}
......
......@@ -136,8 +136,12 @@ class UserManagerTest extends DatabaseTestCase {
*/
public function testGetUsersOne(): void {
$this->createUser();
$expected = [['id' => 1]];
$expected[0] += $this->data;
$expected = [[
'id' => 1,
'username' => 'admin',
'role' => 'power',
'language' => 'en',
]];
Assert::same($expected, $this->manager->getUsers());
}
......
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