Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Rudolf <github.com@daniel-rudolf.de>2020-05-08 13:57:40 +0300
committerDaniel Rudolf <github.com@daniel-rudolf.de>2020-05-08 13:57:40 +0300
commit2ebd3a4b10417dcab8910dc7c29717e597165696 (patch)
tree70b91d74b1629aa65b86ff08ce8547c8fa83afaf /lib
parent3cacb89e4f2bf329dc3396b75dfe0cb57815a35f (diff)
Add --owner option to talk:room:* commands
Signed-off-by: Daniel Rudolf <github.com@daniel-rudolf.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/Room/Create.php8
-rw-r--r--lib/Command/Room/TRoomCommand.php29
-rw-r--r--lib/Command/Room/Update.php14
3 files changed, 51 insertions, 0 deletions
diff --git a/lib/Command/Room/Create.php b/lib/Command/Room/Create.php
index dc20fd182..ade38c826 100644
--- a/lib/Command/Room/Create.php
+++ b/lib/Command/Room/Create.php
@@ -88,6 +88,11 @@ class Create extends Base {
InputOption::VALUE_REQUIRED,
'Protects the room to create with the given password'
)->addOption(
+ 'owner',
+ null,
+ InputOption::VALUE_REQUIRED,
+ 'Sets the given user as owner of the room to create'
+ )->addOption(
'moderator',
null,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
@@ -103,6 +108,7 @@ class Create extends Base {
$public = $input->getOption('public');
$readonly = $input->getOption('readonly');
$password = $input->getOption('password');
+ $owner = $input->getOption('owner');
$moderators = $input->getOption('moderator');
$name = trim($name);
@@ -121,6 +127,8 @@ class Create extends Base {
$this->addRoomParticipantsByGroup($room, $groups);
$this->addRoomParticipantsByCircle($room, $circles);
$this->addRoomModerators($room, $moderators);
+
+ $this->setRoomOwner($room, $owner);
} catch (Exception $e) {
$room->deleteRoom();
diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php
index a99ef1547..1b65d8d0d 100644
--- a/lib/Command/Room/TRoomCommand.php
+++ b/lib/Command/Room/TRoomCommand.php
@@ -124,6 +124,35 @@ trait TRoomCommand
}
/**
+ * @param Room $room
+ * @param string $userId
+ *
+ * @throws InvalidArgumentException
+ */
+ protected function setRoomOwner(Room $room, string $userId): void {
+ try {
+ $participant = $room->getParticipant($userId);
+ } catch (ParticipantNotFoundException $e) {
+ throw new InvalidArgumentException(sprintf("User '%s' is no participant.", $userId));
+ }
+
+ $room->setParticipantType($participant, Participant::OWNER);
+ }
+
+ /**
+ * @param Room $room
+ *
+ * @throws InvalidArgumentException
+ */
+ protected function unsetRoomOwner(Room $room): void {
+ foreach ($room->getParticipants() as $participant) {
+ if ($participant->getParticipantType() === Participant::OWNER) {
+ $room->setParticipantType($participant, Participant::USER);
+ }
+ }
+ }
+
+ /**
* @param Room $room
* @param string[] $groupIds
*
diff --git a/lib/Command/Room/Update.php b/lib/Command/Room/Update.php
index 6dee4da7c..814e9e0e5 100644
--- a/lib/Command/Room/Update.php
+++ b/lib/Command/Room/Update.php
@@ -80,6 +80,11 @@ class Update extends Base {
null,
InputOption::VALUE_REQUIRED,
'Sets a new password for the room; pass an empty value to remove password protection'
+ )->addOption(
+ 'owner',
+ null,
+ InputOption::VALUE_REQUIRED,
+ 'Sets the given user as owner of the room; pass an empty value to remove the owner'
);
}
@@ -89,6 +94,7 @@ class Update extends Base {
$public = $input->getOption('public');
$readOnly = $input->getOption('readonly');
$password = $input->getOption('password');
+ $owner = $input->getOption('owner');
if (!in_array($public, [null, '0', '1'], true)) {
$output->writeln('<error>Invalid value for option "--public" given.</error>');
@@ -128,6 +134,14 @@ class Update extends Base {
if ($password !== null) {
$this->setRoomPassword($room, $password);
}
+
+ if ($owner !== null) {
+ if ($owner !== '') {
+ $this->setRoomOwner($room, $owner);
+ } else {
+ $this->unsetRoomOwner($room);
+ }
+ }
} catch (Exception $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
return 1;