Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): fix PATCH /configuration/users/current/parameters #2723

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
use Core\Application\Configuration\User\Repository\ReadUserRepositoryInterface;
use Core\Domain\Configuration\User\Model\User;

/**
* @phpstan-type _UserRecord array{
* contact_id: int|string,
* contact_alias: string,
* contact_name: string,
* contact_email: string,
* contact_admin: string,
* contact_theme: string,
* user_interface_density: string,
* user_can_reach_frontend: string,
* }
*/
class DbReadUserRepository extends AbstractRepositoryDRB implements ReadUserRepositoryInterface
{
use LoggerTrait;
Expand Down Expand Up @@ -111,9 +123,7 @@ public function findAllUsers(): array
$users = [];

while ($result = $statement->fetch(\PDO::FETCH_ASSOC)) {
/**
* @var array<string, string> $result
*/
/** @var _UserRecord $result */
$users[] = DbUserFactory::createFromRecord($result);
}

Expand All @@ -125,7 +135,6 @@ public function findAllUsers(): array
*/
public function findByContactGroups(ContactInterface $contact): array
{

$request = <<<'SQL'
SELECT SQL_CALC_FOUND_ROWS DISTINCT
contact_id,
Expand All @@ -134,7 +143,8 @@ public function findByContactGroups(ContactInterface $contact): array
contact_email,
contact_admin,
contact_theme,
user_interface_density
user_interface_density,
contact_oreon AS `user_can_reach_frontend`
FROM `:db`.contact
INNER JOIN `:db`.contactgroup_contact_relation AS cg
ON cg.contact_contact_id = contact.contact_id
Expand Down Expand Up @@ -178,9 +188,7 @@ public function findByContactGroups(ContactInterface $contact): array
$users = [];

while ($result = $statement->fetch(\PDO::FETCH_ASSOC)) {
/**
* @var array<string, string> $result
*/
/** @var _UserRecord $result */
$users[] = DbUserFactory::createFromRecord($result);
}

Expand All @@ -193,14 +201,26 @@ public function findByContactGroups(ContactInterface $contact): array
public function findById(int $userId): ?User
{
$statement = $this->db->prepare(
$this->translateDbName('SELECT * FROM `:db`.contact WHERE contact_id = :contact_id')
$this->translateDbName(
<<<'SQL'
SELECT
contact_id,
contact_alias,
contact_name,
contact_email,
contact_admin,
contact_theme,
user_interface_density,
contact_oreon AS `user_can_reach_frontend`
FROM `:db`.contact
WHERE contact_id = :contact_id
SQL
)
);
$statement->bindValue(':contact_id', $userId, \PDO::PARAM_INT);
$statement->execute();
if ($result = $statement->fetch(\PDO::FETCH_ASSOC)) {
/**
* @var array<string, string> $result
*/
/** @var _UserRecord $result */
return DbUserFactory::createFromRecord($result);
}

Expand All @@ -225,11 +245,14 @@ public function findUserIdsByAliases(array $userAliases): array
$bindValues[':' . $key] = $userAlias;
}

$bindFields = implode(',', array_keys($bindValues));
$statement = $this->db->prepare(
$this->translateDbName(
'SELECT contact_id
FROM `:db`.contact
WHERE contact_alias IN (' . implode(',', array_keys($bindValues)) . ')'
<<<SQL
SELECT contact_id
FROM `:db`.contact
WHERE contact_alias IN ({$bindFields})
SQL
)
);

Expand All @@ -255,8 +278,10 @@ public function findUserIdsByAliases(array $userAliases): array
public function findAvailableThemes(): array
{
$statement = $this->db->query(
'SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = \'contact\' AND COLUMN_NAME = \'contact_theme\''
<<<'SQL'
SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'contact' AND COLUMN_NAME = 'contact_theme'
SQL
);
if ($statement !== false && $result = $statement->fetch(\PDO::FETCH_ASSOC)) {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@

use Core\Domain\Configuration\User\Model\User;

/**
* @phpstan-import-type _UserRecord from DbReadUserRepository
*/
class DbUserFactory
{
/**
* @param array<string, string> $user
* @param _UserRecord $user
*
* @throws \Assert\AssertionFailedException
*
Expand Down