Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ public function isNotAllowedToCreateConversations(IUser $user): bool {
return empty(array_intersect($allowedGroups, $userGroups));
}

public function isAllowedToCreatePublicConversations(): bool {
return $this->config->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'yes';
}

public function getAttachmentFolder(string $userId): string {
return $this->config->getUserValue($userId, 'spreed', 'attachment_folder', '/Talk');
}
Expand Down
9 changes: 9 additions & 0 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/**
* @copyright Copyright (c) 2016 Lukas Reschke <[email protected]>
* @copyright Copyright (c) 2016 Joas Schilling <[email protected]>
* @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
*
* @author Lukas Reschke <[email protected]>
* @author Joas Schilling <[email protected]>
Expand Down Expand Up @@ -660,6 +661,9 @@ public function createRoom(int $roomType, string $invite = '', string $roomName
}
return $this->createGroupRoom($invite);
case Room::TYPE_PUBLIC:
if (!$this->talkConfig->isAllowedToCreatePublicConversations()) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
return $this->createEmptyRoom($roomName);
}

Expand Down Expand Up @@ -1115,6 +1119,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->talkConfig->isAllowedToCreatePublicConversations()) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}

$data = [];
if ($this->roomService->setType($this->room, Room::TYPE_PUBLIC)) {
$data = ['type' => $this->room->getType()];
Expand Down
10 changes: 9 additions & 1 deletion lib/Service/RoomService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace OCA\Talk\Service;

use InvalidArgumentException;
use OCA\Talk\Config;
use OCA\Talk\Events\ModifyLobbyEvent;
use OCA\Talk\Events\ModifyRoomEvent;
use OCA\Talk\Events\RoomEvent;
Expand All @@ -48,6 +49,7 @@
use OCP\Share\IManager as IShareManager;

class RoomService {
protected Config $config;
protected Manager $manager;
protected ParticipantService $participantService;
protected IDBConnection $db;
Expand All @@ -57,14 +59,16 @@ class RoomService {
protected IEventDispatcher $dispatcher;
protected IJobList $jobList;

public function __construct(Manager $manager,
public function __construct(Config $config,
Manager $manager,
ParticipantService $participantService,
IDBConnection $db,
ITimeFactory $timeFactory,
IShareManager $shareManager,
IHasher $hasher,
IEventDispatcher $dispatcher,
IJobList $jobList) {
$this->config = $config;
$this->manager = $manager;
$this->participantService = $participantService;
$this->db = $db;
Expand Down Expand Up @@ -355,6 +359,10 @@ public function setType(Room $room, int $newType, bool $allowSwitchingOneToOne =
return false;
}

if ($newType === Room::TYPE_PUBLIC && !$this->config->isAllowedToCreatePublicConversations()) {
return false;
}

$oldType = $room->getType();

$event = new ModifyRoomEvent($room, 'type', $newType, $oldType);
Expand Down
6 changes: 6 additions & 0 deletions lib/Settings/Admin/AdminSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019 Joas Schilling <[email protected]>
* @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
*
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions lib/TInitialState.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Joas Schilling <[email protected]>
* @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
*
Expand Down Expand Up @@ -105,6 +106,11 @@ protected function publishInitialStateForUser(IUser $user, IRootFolder $rootFold
$appManager->isEnabledForUser('circles', $user)
);

$this->initialState->provideInitialState(
'public_rooms_allowed',
$this->talkConfig->isAllowedToCreatePublicConversations()
);

$this->initialState->provideInitialState(
'guests_accounts_enabled',
$appManager->isEnabledForUser('guests', $user)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!--
- @copyright Copyright (c) 2020 Vincent Petry <[email protected]>
- @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
-
- @author Vincent Petry <[email protected]>
-
Expand Down Expand Up @@ -55,7 +56,7 @@
:title="t('spreed', 'Moderation')">
<ListableSettings v-if="canFullModerate"
:token="token" />
<LinkShareSettings v-if="canFullModerate"
<LinkShareSettings v-if="canFullModerate && publicRoomsEnabled"
ref="linkShareSettings" />
<ExpirationSettings :token="token" />
</NcAppSettingsSection>
Expand Down Expand Up @@ -138,6 +139,7 @@ export default {
return {
showSettings: false,
matterbridgeEnabled: loadState('spreed', 'enable_matterbridge'),
publicRoomsEnabled: loadState('spreed', 'public_rooms_allowed'),
isEditingDescription: false,
isDescriptionLoading: false,
showDeviceChecker: false,
Expand Down Expand Up @@ -215,9 +217,11 @@ export default {
handleShowSettings({ token }) {
this.$store.dispatch('updateConversationSettingsToken', token)
this.showSettings = true
this.$nextTick(() => {
this.$refs.linkShareSettings.$el.focus()
})
if (this.publicRoomsEnabled) {
this.$nextTick(() => {
this.$refs.linkShareSettings.$el.focus()
})
}
},

handleHideSettings() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!--
- @copyright Copyright (c) 2019 Marco Ambrosini <[email protected]>
- @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
-
- @author Marco Ambrosini <[email protected]>
-
Expand Down Expand Up @@ -45,7 +46,7 @@
<template v-if="page === 0">
<SetConversationName v-model="conversationNameInput"
@click-enter="handleEnter" />
<NcCheckboxRadioSwitch :checked.sync="isPublic">
<NcCheckboxRadioSwitch v-if="publicRoomsEnabled" :checked.sync="isPublic">
{{ t('spreed', 'Allow guests to join via link') }}
</NcCheckboxRadioSwitch>
<!-- Password protection -->
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -177,6 +179,7 @@ export default {
password: '',
passwordProtect: false,
listable: CONVERSATION.LISTABLE.NONE,
publicRoomsEnabled: loadState('spreed', 'public_rooms_allowed'),
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/services/conversationsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const searchPossibleConversations = async function({ searchText, token, onlyUser
if (!onlyUsers) {
shareTypes.push(SHARE.TYPE.GROUP)
shareTypes.push(SHARE.TYPE.CIRCLE)
if (token !== 'new') {
if (token !== 'new' && loadState('spreed', 'public_rooms_allowed')) {
shareTypes.push(SHARE.TYPE.EMAIL)

if (loadState('spreed', 'federation_enabled')) {
Expand Down
7 changes: 7 additions & 0 deletions tests/php/Service/RoomServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Joas Schilling <[email protected]>
* @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
*
Expand All @@ -25,6 +26,7 @@

use InvalidArgumentException;
use OC\EventDispatcher\EventDispatcher;
use OCA\Talk\Config;
use OCA\Talk\Events\VerifyRoomPasswordEvent;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
Expand All @@ -49,6 +51,8 @@
* @group DB
*/
class RoomServiceTest extends TestCase {
/** @var Config|MockObject */
protected $config;
/** @var Manager|MockObject */
protected $manager;
/** @var ParticipantService|MockObject */
Expand All @@ -66,6 +70,7 @@ class RoomServiceTest extends TestCase {
public function setUp(): void {
parent::setUp();

$this->config = $this->createMock(Config::class);
$this->manager = $this->createMock(Manager::class);
$this->participantService = $this->createMock(ParticipantService::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
Expand All @@ -74,6 +79,7 @@ public function setUp(): void {
$this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->jobList = $this->createMock(IJobList::class);
$this->service = new RoomService(
$this->config,
$this->manager,
$this->participantService,
\OC::$server->get(IDBConnection::class),
Expand Down Expand Up @@ -344,6 +350,7 @@ public function testVerifyPassword(): void {
});

$service = new RoomService(
$this->config,
$this->manager,
$this->participantService,
\OC::$server->get(IDBConnection::class),
Expand Down
1 change: 1 addition & 0 deletions tests/php/Signaling/BackendNotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public function setUp(): void {
$this->jobList = $this->createMock(IJobList::class);

$this->roomService = new RoomService(
$this->config,
$this->manager,
$this->participantService,
$dbConnection,
Expand Down