Skip to content

Commit

Permalink
Merge pull request #13154 from nextcloud/techdebt/noid/ensure-admin-c…
Browse files Browse the repository at this point in the history
…onfig-range

fix(appconfig): Ensure configs are within ranges
  • Loading branch information
nickvergessen authored Aug 28, 2024
2 parents 36bfbcb + 82db78d commit 7fc69bb
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions lib/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,30 @@ public function getAllowedTalkGroupIds(): array {
return \is_array($groups) ? $groups : [];
}

/**
* @return Participant::PRIVACY_*
*/
public function getUserReadPrivacy(string $userId): int {
return (int)$this->config->getUserValue(
return match ((int)$this->config->getUserValue(
$userId,
'spreed', 'read_status_privacy',
(string)Participant::PRIVACY_PUBLIC);
(string)Participant::PRIVACY_PUBLIC)) {
Participant::PRIVACY_PUBLIC => Participant::PRIVACY_PUBLIC,
default => Participant::PRIVACY_PRIVATE,
};
}

/**
* @return Participant::PRIVACY_*
*/
public function getUserTypingPrivacy(string $userId): int {
return (int)$this->config->getUserValue(
return match ((int)$this->config->getUserValue(
$userId,
'spreed', 'typing_privacy',
(string)Participant::PRIVACY_PUBLIC);

(string)Participant::PRIVACY_PUBLIC)) {
Participant::PRIVACY_PUBLIC => Participant::PRIVACY_PUBLIC,
default => Participant::PRIVACY_PRIVATE,
};
}

/**
Expand Down Expand Up @@ -256,11 +267,15 @@ public function isNotAllowedToCreateConversations(IUser $user): bool {
return empty(array_intersect($allowedGroups, $userGroups));
}

/**
* @return int<0, 255>
* @psalm-return int-mask-of<Attendee::PERMISSIONS_*>
*/
public function getDefaultPermissions(): int {
// Admin configured default permissions
$configurableDefault = $this->config->getAppValue('spreed', 'default_permissions');
if ($configurableDefault !== '') {
return (int)$configurableDefault;
return min(Attendee::PERMISSIONS_MAX_CUSTOM, max(Attendee::PERMISSIONS_DEFAULT, (int)$configurableDefault));
}

// Falling back to an unrestricted set of permissions, only ignoring the lobby is off
Expand Down

0 comments on commit 7fc69bb

Please sign in to comment.