Skip to content

Commit a959ce3

Browse files
committed
check for users,groups and circles
Signed-off-by: samin-z <samin.zavarkesh@gmail.com>
1 parent d598047 commit a959ce3

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

lib/Service/ColumnTypes/UsergroupBusiness.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCA\Tables\Db\Column;
1212
use OCA\Tables\Errors\BadRequestError;
1313
use OCA\Tables\Helper\CircleHelper;
14+
use OCP\IGroupManager;
1415
use OCP\IUserManager;
1516
use Psr\Log\LoggerInterface;
1617

@@ -20,6 +21,7 @@ public function __construct(
2021
protected LoggerInterface $logger,
2122
protected CircleHelper $circleHelper,
2223
protected IUserManager $userManager,
24+
protected IGroupManager $groupManager,
2325
) {
2426
parent::__construct($logger);
2527
}
@@ -53,15 +55,19 @@ public function validateValue(mixed $value, Column $column, string $userId, int
5355
if (!isset($userGroupEntry['type']) || !is_int($userGroupEntry['type'])) {
5456
throw new BadRequestError('Invalid usergroup type');
5557
}
56-
if ($userGroupEntry['type'] === UsergroupType::CIRCLE) {
57-
if ($this->userManager->get($userId) === null) {
58+
if ($userGroupEntry['type'] === UsergroupType::USER) {
59+
if (!$this->userManager->get($userGroupEntry['id'])) {
5860
throw new BadRequestError('User not found');
5961
}
60-
if (!$this->circleHelper->circleExists($userGroupEntry['id'], null)) {
61-
throw new BadRequestError('Circle does not exist');
62+
}
63+
if ($userGroupEntry['type'] === UsergroupType::GROUP) {
64+
if (!$this->groupManager->get($userGroupEntry['id'])) {
65+
throw new BadRequestError('Group not found.');
6266
}
67+
}
68+
if ($userGroupEntry['type'] === UsergroupType::CIRCLE) {
6369
if (!$this->circleHelper->circleExists($userGroupEntry['id'], $userId)) {
64-
throw new BadRequestError('Circle not found');
70+
throw new BadRequestError('Circle not found.');
6571
}
6672
}
6773
}

0 commit comments

Comments
 (0)