summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2021-07-15 18:50:19 +0200
committerGitHub <noreply@github.com>2021-07-15 18:50:19 +0200
commit92007d579d2bdb44f4297ebc43ca54f4a953d851 (patch)
tree0fa0c2e3db9def8bb31115438c45e42b2c19370c
parent888eca7b9ed56663ad43c08642848fbfdafe6175 (diff)
parent4cab78438115af58f3718b1e92e4da9182fd98ac (diff)
Merge pull request #6024 from nextcloud/bugfix/noid/check-circles-membership
Check circles membership when trying to add
-rw-r--r--lib/Controller/RoomController.php7
-rw-r--r--lib/Service/ParticipantService.php25
-rw-r--r--psalm.xml1
3 files changed, 28 insertions, 5 deletions
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php
index 32f5e82a6..29127132a 100644
--- a/lib/Controller/RoomController.php
+++ b/lib/Controller/RoomController.php
@@ -28,7 +28,6 @@ declare(strict_types=1);
namespace OCA\Talk\Controller;
use InvalidArgumentException;
-use OCA\Circles\Api\v1\Circles;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Chat\MessageParser;
use OCA\Talk\Config;
@@ -738,9 +737,8 @@ class RoomController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
- /** @var Circles $circlesApi */
try {
- $circle = Circles::detailsCircle($targetCircleId);
+ $circle = $this->participantService->getCircle($targetCircleId, $this->userId);
} catch (\Exception $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
@@ -1063,9 +1061,8 @@ class RoomController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
- /** @var Circles $circlesApi */
try {
- $circle = Circles::detailsCircle($newParticipant);
+ $circle = $this->participantService->getCircle($newParticipant, $this->userId);
} catch (\Exception $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php
index 0b69ab3ae..be27b16ed 100644
--- a/lib/Service/ParticipantService.php
+++ b/lib/Service/ParticipantService.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace OCA\Talk\Service;
+use OCA\Circles\Api\v1\Circles;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
use OCA\Talk\Config;
@@ -397,6 +398,30 @@ class ParticipantService {
}
/**
+ * @param string $circleId
+ * @param string $userId
+ * @return Circle
+ * @throws ParticipantNotFoundException
+ */
+ public function getCircle(string $circleId, string $userId): Circle {
+ try {
+ $circle = Circles::detailsCircle($circleId);
+ } catch (\Exception $e) {
+ throw new ParticipantNotFoundException('Circle not found');
+ }
+
+ // FIXME use \OCA\Circles\Manager::getLink() in the future
+ $membersInCircle = $circle->getInheritedMembers();
+ foreach ($membersInCircle as $member) {
+ if ($member->isLocal() && $member->getUserType() === Member::TYPE_USER && $member->getUserId() === $userId) {
+ return $circle;
+ }
+ }
+
+ throw new ParticipantNotFoundException('Circle found but not a member');
+ }
+
+ /**
* @param Room $room
* @param Circle $circle
* @param Participant[] $existingParticipants
diff --git a/psalm.xml b/psalm.xml
index ea6b96759..4ffa77ec0 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -24,6 +24,7 @@
<referencedClass name="Doctrine\DBAL\Platforms\PostgreSQL94Platform" />
<referencedClass name="Doctrine\DBAL\Types\Types" />
<referencedClass name="OC" />
+ <referencedClass name="OCA\Circles\Api\v1\Circles" />
<referencedClass name="OCA\Circles\Model\Circle" />
<referencedClass name="OCA\Circles\Model\Member" />
<referencedClass name="OCA\DAV\CardDAV\PhotoCache" />