Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to disable public conversations #8357

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Prevent creating public rooms on the API
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Nov 16, 2022
commit bf2aeb4b858ca386bbd2bac7c0e4ffcb114ccb5d
5 changes: 4 additions & 1 deletion lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,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 @@ -1117,7 +1120,7 @@ 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') {
if (!$this->talkConfig->isAllowedToCreatePublicConversations()) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}

Expand Down
8 changes: 0 additions & 8 deletions lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
* @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 @@ -157,7 +156,6 @@ public function createRoomObject(array $row): Room {
}

return new Room(
$this->config,
$this,
$this->db,
$this->dispatcher,
Expand Down Expand Up @@ -912,12 +910,6 @@ 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();
Expand Down
1 change: 0 additions & 1 deletion lib/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
* @copyright Copyright (c) 2022 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
*
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Joas Schilling <coding@schilljs.com>
Expand Down
7 changes: 6 additions & 1 deletion tests/php/Service/RoomServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,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 @@ -51,6 +52,8 @@
* @group DB
*/
class RoomServiceTest extends TestCase {
/** @var Config|MockObject */
protected $config;
/** @var Manager|MockObject */
protected $manager;
/** @var ParticipantService|MockObject */
Expand All @@ -68,6 +71,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 @@ -76,6 +80,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 @@ -346,6 +351,7 @@ public function testVerifyPassword(): void {
});

$service = new RoomService(
$this->config,
$this->manager,
$this->participantService,
\OC::$server->get(IDBConnection::class),
Expand All @@ -357,7 +363,6 @@ public function testVerifyPassword(): void {
);

$room = new Room(
$this->createMock(IConfig::class),
$this->createMock(Manager::class),
$this->createMock(IDBConnection::class),
$dispatcher,
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