diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index b9c36c68427..de8e8bdc3c1 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -4,6 +4,7 @@ /** * @copyright Copyright (c) 2016 Lukas Reschke * @copyright Copyright (c) 2016 Joas Schilling + * @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ * * @author Lukas Reschke * @author Joas Schilling @@ -1115,6 +1116,11 @@ public function addParticipantToRoom(string $newParticipant, string $source = 'u $this->participantService->addCircle($this->room, $circle, $participants); } elseif ($source === 'emails') { + // E-mails cannot be added if public rooms are disabled. + if ($this->config->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'no') { + return new DataResponse([], Http::STATUS_BAD_REQUEST); + } + $data = []; if ($this->roomService->setType($this->room, Room::TYPE_PUBLIC)) { $data = ['type' => $this->room->getType()]; diff --git a/lib/Manager.php b/lib/Manager.php index 4a9d5100b06..2ceca66a894 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -3,6 +3,7 @@ declare(strict_types=1); /** * @copyright Copyright (c) 2016 Joas Schilling + * @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ * * @license GNU AGPL version 3 or any later version * @@ -156,6 +157,7 @@ public function createRoomObject(array $row): Room { } return new Room( + $this->config, $this, $this->db, $this->dispatcher, @@ -908,6 +910,12 @@ public function getChangelogRoom(string $userId): Room { * @return Room */ public function createRoom(int $type, string $name = '', string $objectType = '', string $objectId = ''): Room { + + // Force group room if public room was requested and public rooms are disallowed. + if (($type === Room::TYPE_PUBLIC) && ($this->config->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'no')) { + $type = Room::TYPE_GROUP; + } + $token = $this->getNewToken(); $insert = $this->db->getQueryBuilder(); diff --git a/lib/Room.php b/lib/Room.php index 032325008e1..4567f1d9507 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -4,6 +4,7 @@ /** * @copyright Copyright (c) 2016 Lukas Reschke * @copyright Copyright (c) 2016 Joas Schilling + * @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ * * @author Lukas Reschke * @author Joas Schilling @@ -38,6 +39,7 @@ use OCA\Talk\Service\RoomService; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Comments\IComment; +use OCP\IConfig; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; @@ -185,8 +187,10 @@ class Room { protected ?string $currentUser = null; protected ?Participant $participant = null; + protected IConfig $config; - public function __construct(Manager $manager, + public function __construct(IConfig $config, + Manager $manager, IDBConnection $db, IEventDispatcher $dispatcher, ITimeFactory $timeFactory, @@ -216,6 +220,7 @@ public function __construct(Manager $manager, ?\DateTime $lobbyTimer, string $objectType, string $objectId) { + $this->config = $config; $this->manager = $manager; $this->db = $db; $this->dispatcher = $dispatcher; @@ -257,6 +262,11 @@ public function getType(): int { } public function setType(int $type): void { + // Force group room if public room was requested and public rooms are disallowed. + if (($type === self::TYPE_PUBLIC) && ($this->config->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'no')) { + $type = self::TYPE_GROUP; + } + $this->type = $type; } diff --git a/lib/Settings/Admin/AdminSettings.php b/lib/Settings/Admin/AdminSettings.php index 29f5f967166..7f9210066dc 100644 --- a/lib/Settings/Admin/AdminSettings.php +++ b/lib/Settings/Admin/AdminSettings.php @@ -3,6 +3,7 @@ declare(strict_types=1); /** * @copyright Copyright (c) 2019 Joas Schilling + * @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ * * @license GNU AGPL version 3 or any later version * @@ -146,6 +147,11 @@ protected function initMatterbridge(): void { 'matterbridge_enable', $this->serverConfig->getAppValue('spreed', 'enable_matterbridge', '0') === '1' ); + + $this->initialState->provideInitialState( + 'public_rooms_allowed', + $this->serverConfig->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'yes' + ); } protected function initStunServers(): void { diff --git a/lib/TInitialState.php b/lib/TInitialState.php index c1086bc66b6..c5e6ecd9a3c 100644 --- a/lib/TInitialState.php +++ b/lib/TInitialState.php @@ -3,6 +3,7 @@ declare(strict_types=1); /** * @copyright Copyright (c) 2020 Joas Schilling + * @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ * * @license GNU AGPL version 3 or any later version * @@ -105,6 +106,11 @@ protected function publishInitialStateForUser(IUser $user, IRootFolder $rootFold $appManager->isEnabledForUser('circles', $user) ); + $this->initialState->provideInitialState( + 'public_rooms_allowed', + $this->serverConfig->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'yes' + ); + $this->initialState->provideInitialState( 'guests_accounts_enabled', $appManager->isEnabledForUser('guests', $user) @@ -158,6 +164,11 @@ protected function publishInitialStateForUser(IUser $user, IRootFolder $rootFold 'enable_matterbridge', $this->serverConfig->getAppValue('spreed', 'enable_matterbridge', '0') === '1' ); + + $this->initialState->provideInitialState( + 'public_rooms_allowed', + $this->serverConfig->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'yes' + ); } protected function publishInitialStateForGuest(): void { diff --git a/src/components/ConversationSettings/ConversationSettingsDialog.vue b/src/components/ConversationSettings/ConversationSettingsDialog.vue index bb3896f1bad..daa27d9fd58 100644 --- a/src/components/ConversationSettings/ConversationSettingsDialog.vue +++ b/src/components/ConversationSettings/ConversationSettingsDialog.vue @@ -1,5 +1,6 @@ - @@ -148,6 +149,7 @@ export default { return { showSettings: false, matterbridgeEnabled: loadState('spreed', 'enable_matterbridge'), + publicRoomsEnabled: loadState('spreed', 'public_rooms_allowed'), isEditingDescription: false, isDescriptionLoading: false, showDeviceChecker: false, @@ -225,9 +227,11 @@ export default { handleShowSettings({ token }) { this.$store.dispatch('updateConversationSettingsToken', token) this.showSettings = true - this.$nextTick(() => { - this.$refs.linkShareSettings.$el.focus() - }) + if (loadState('spreed', 'public_rooms_allowed')) { + this.$nextTick(() => { + this.$refs.linkShareSettings.$el.focus() + }) + } }, handleHideSettings() { diff --git a/src/components/LeftSidebar/NewGroupConversation/NewGroupConversation.vue b/src/components/LeftSidebar/NewGroupConversation/NewGroupConversation.vue index 9ff46aa243b..33460e4fbb5 100644 --- a/src/components/LeftSidebar/NewGroupConversation/NewGroupConversation.vue +++ b/src/components/LeftSidebar/NewGroupConversation/NewGroupConversation.vue @@ -1,5 +1,6 @@ @@ -138,6 +139,7 @@ import isInCall from '../../../mixins/isInCall.js' import participant from '../../../mixins/participant.js' import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip.js' import { EventBus } from '../../../services/EventBus.js' +import { loadState } from '@nextcloud/initial-state' export default { @@ -177,6 +179,7 @@ export default { password: '', passwordProtect: false, listable: CONVERSATION.LISTABLE.NONE, + publicRoomsEnabled: loadState('spreed', 'public_rooms_allowed'), } }, diff --git a/src/components/RightSidebar/Participants/ParticipantsSearchResults/ParticipantsSearchResults.vue b/src/components/RightSidebar/Participants/ParticipantsSearchResults/ParticipantsSearchResults.vue index 392dcb4be28..390d072b42b 100644 --- a/src/components/RightSidebar/Participants/ParticipantsSearchResults/ParticipantsSearchResults.vue +++ b/src/components/RightSidebar/Participants/ParticipantsSearchResults/ParticipantsSearchResults.vue @@ -1,5 +1,6 @@