Skip to content

Commit 57c4bc2

Browse files
committed
fix: accept optional CurrentUser in hasPermissionForCategory
Avoids instantiating a new CurrentUser and hitting the DB on every call when the caller already has one. The parameter is optional to maintain backward compatibility.
1 parent d3c54bc commit 57c4bc2

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

phpmyfaq/src/phpMyFAQ/Permission/MediumPermission.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,19 @@ public function findOrCreateGroupByName(string $name, string $description = ''):
489489
* @param int $userId User ID
490490
* @param mixed $right Right ID, name, or PermissionType enum
491491
* @param int $categoryId Category ID
492+
* @param CurrentUser|null $currentUser Optional pre-loaded user to avoid repeated instantiation
492493
* @throws Exception
493494
*/
494-
public function hasPermissionForCategory(int $userId, mixed $right, int $categoryId): bool
495-
{
496-
$currentUser = new CurrentUser($this->configuration);
497-
$currentUser->getUserById($userId);
495+
public function hasPermissionForCategory(
496+
int $userId,
497+
mixed $right,
498+
int $categoryId,
499+
?CurrentUser $currentUser = null,
500+
): bool {
501+
if ($currentUser === null) {
502+
$currentUser = new CurrentUser($this->configuration);
503+
$currentUser->getUserById($userId);
504+
}
498505

499506
if ($currentUser->isSuperAdmin()) {
500507
return true;

0 commit comments

Comments
 (0)