Skip to content

Commit 442423b

Browse files
committed
fix(QuotaRule): handle empty userIds in quota accounting
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
1 parent 47036c0 commit 442423b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/Service/OpenAiAPIService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(
5555
}
5656

5757
/**
58-
* @param string $userId
58+
* @param string $userId It can be an empty string
5959
* @param int $type
6060
* @param int $usage
6161
* @throws Exception If there is an error creating the quota usage.

lib/Service/QuotaRuleService.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,26 @@ public function __construct(
3434
private LoggerInterface $logger,
3535
) {
3636
}
37+
3738
/**
3839
* Returns the quota rule for the given user
3940
*
4041
* @param int $quotaType
41-
* @param string $userId
42+
* @param string $userId It can be an empty string
4243
* @return array
4344
*/
4445
public function getRule(int $quotaType, string $userId) {
4546
$cache = $this->cacheFactory->createDistributed(Application::APP_ID);
4647
$cacheKey = Application::QUOTA_RULES_CACHE_PREFIX . $quotaType . '-' . $userId;
4748
$rule = $cache->get($cacheKey);
4849
if ($rule === null) {
49-
$user = $this->userManager->get($userId);
50-
$groups = $this->groupManager->getUserGroupIds($user);
5150
try {
51+
$user = $this->userManager->get($userId);
52+
if ($user === null) {
53+
// re-use the db exception for not found users
54+
throw new DoesNotExistException('User not found: ' . $userId);
55+
}
56+
$groups = $this->groupManager->getUserGroupIds($user);
5257
$rule = $this->quotaRuleMapper->getRule($quotaType, $userId, $groups)->jsonSerialize();
5358
} catch (DoesNotExistException|MultipleObjectsReturnedException) {
5459
$rule = [

0 commit comments

Comments
 (0)