-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13488 from nextcloud/feat/13446/api-for-media-pre…
…ference feat(calls): Add appconfig and user preference for default setting of…
- Loading branch information
Showing
28 changed files
with
211 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Talk\Settings; | ||
|
||
use OCA\Files_Sharing\SharedStorage; | ||
use OCA\Talk\AppInfo\Application; | ||
use OCA\Talk\Model\Attendee; | ||
use OCA\Talk\Participant; | ||
use OCA\Talk\Service\ParticipantService; | ||
use OCP\Config\BeforePreferenceSetEvent; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Files\Folder; | ||
use OCP\Files\IRootFolder; | ||
use OCP\Files\NotFoundException; | ||
use OCP\Files\NotPermittedException; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* @template-implements IEventListener<Event> | ||
*/ | ||
class BeforePreferenceSetEventListener implements IEventListener { | ||
public function __construct( | ||
protected IRootFolder $rootFolder, | ||
protected ParticipantService $participantService, | ||
protected LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof BeforePreferenceSetEvent)) { | ||
// Unrelated | ||
return; | ||
} | ||
|
||
if ($event->getAppId() !== Application::APP_ID) { | ||
return; | ||
} | ||
|
||
$event->setValid($this->validatePreference( | ||
$event->getUserId(), | ||
$event->getConfigKey(), | ||
$event->getConfigValue(), | ||
)); | ||
} | ||
|
||
/** | ||
* @internal Make private/protected once SettingsController route was removed | ||
*/ | ||
public function validatePreference(string $userId, string $key, string $value): bool { | ||
if ($key === 'attachment_folder') { | ||
return $this->validateAttachmentFolder($userId, $value); | ||
} | ||
|
||
// "boolean" yes/no | ||
if ($key === UserPreference::CALLS_START_WITHOUT_MEDIA | ||
|| $key === UserPreference::PLAY_SOUNDS) { | ||
return $value === 'yes' || $value === 'no'; | ||
} | ||
|
||
// "privacy" 0/1 | ||
if ($key === UserPreference::TYPING_PRIVACY | ||
|| $key === UserPreference::READ_STATUS_PRIVACY) { | ||
$valid = $value === (string)Participant::PRIVACY_PRIVATE || $value === (string)Participant::PRIVACY_PUBLIC; | ||
|
||
if ($valid && $key === 'read_status_privacy') { | ||
$this->participantService->updateReadPrivacyForActor(Attendee::ACTOR_USERS, $userId, (int)$value); | ||
} | ||
return $valid; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
protected function validateAttachmentFolder(string $userId, string $value): bool { | ||
try { | ||
$userFolder = $this->rootFolder->getUserFolder($userId); | ||
$node = $userFolder->get($value); | ||
if (!$node instanceof Folder) { | ||
throw new NotPermittedException('Node is not a directory'); | ||
} | ||
if ($node->isShared()) { | ||
throw new NotPermittedException('Folder is shared'); | ||
} | ||
return !$node->getStorage()->instanceOfStorage(SharedStorage::class); | ||
} catch (NotFoundException) { | ||
$userFolder->newFolder($value); | ||
return true; | ||
} catch (NotPermittedException) { | ||
} catch (\Exception $e) { | ||
$this->logger->error($e->getMessage(), ['exception' => $e]); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Talk\Settings; | ||
|
||
class UserPreference { | ||
public const CALLS_START_WITHOUT_MEDIA = 'calls_start_without_media'; | ||
public const PLAY_SOUNDS = 'play_sounds'; | ||
public const TYPING_PRIVACY = 'typing_privacy'; | ||
public const READ_STATUS_PRIVACY = 'read_status_privacy'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.