Skip to content

Commit ffa8d49

Browse files
authored
Merge pull request #2359 from nextcloud/fix/1355-add-arbitrary-team
fix: add arbitrary team
2 parents 1a1c8b6 + 0d5d097 commit ffa8d49

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

lib/Helper/CircleHelper.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,16 @@ public function getUserIdsInCircle(string $circleId): array {
129129
}
130130
}
131131

132+
public function circleExists(string $circleId, string $userId): bool {
133+
if (!$this->circlesEnabled) {
134+
return false;
135+
}
136+
137+
$userCircleIds = $this->getCircleIdsForUser($userId);
138+
if ($userCircleIds === null) {
139+
return false;
140+
}
141+
return in_array($circleId, $userCircleIds, true);
142+
}
143+
132144
}

lib/Service/ColumnTypes/UsergroupBusiness.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,72 @@
77

88
namespace OCA\Tables\Service\ColumnTypes;
99

10+
use OCA\Tables\Constants\UsergroupType;
1011
use OCA\Tables\Db\Column;
12+
use OCA\Tables\Errors\BadRequestError;
13+
use OCA\Tables\Helper\CircleHelper;
14+
use OCP\IGroupManager;
15+
use OCP\IUserManager;
16+
use Psr\Log\LoggerInterface;
1117

1218
class UsergroupBusiness extends SuperBusiness {
1319

20+
public function __construct(
21+
protected LoggerInterface $logger,
22+
protected CircleHelper $circleHelper,
23+
protected IUserManager $userManager,
24+
protected IGroupManager $groupManager,
25+
) {
26+
parent::__construct($logger);
27+
}
28+
29+
/**
30+
* @param mixed $value
31+
* @param Column $column
32+
* @param string $userId
33+
* @param int $tableId
34+
* @param int|null $rowId
35+
*
36+
* @throws BadRequestError
37+
*/
38+
public function validateValue(mixed $value, Column $column, string $userId, int $tableId, ?int $rowId): void {
39+
if ($value === null) {
40+
return;
41+
}
42+
43+
if (is_string($value)) {
44+
$value = json_decode($value, true);
45+
}
46+
47+
if (!is_array($value)) {
48+
throw new BadRequestError('Invalid value for usergroup column');
49+
}
50+
51+
foreach ($value as $userGroupEntry) {
52+
if (!isset($userGroupEntry['id']) || !is_string($userGroupEntry['id'])) {
53+
throw new BadRequestError('Invalid value for usergroup id');
54+
}
55+
if (!isset($userGroupEntry['type']) || !is_int($userGroupEntry['type'])) {
56+
throw new BadRequestError('Invalid usergroup type');
57+
}
58+
if ($userGroupEntry['type'] === UsergroupType::USER) {
59+
if (!$this->userManager->get($userGroupEntry['id'])) {
60+
throw new BadRequestError('User not found');
61+
}
62+
}
63+
if ($userGroupEntry['type'] === UsergroupType::GROUP) {
64+
if (!$this->groupManager->get($userGroupEntry['id'])) {
65+
throw new BadRequestError('Group not found');
66+
}
67+
}
68+
if ($userGroupEntry['type'] === UsergroupType::CIRCLE) {
69+
if (!$this->circleHelper->circleExists($userGroupEntry['id'], $userId)) {
70+
throw new BadRequestError('Circle not found');
71+
}
72+
}
73+
}
74+
}
75+
1476
/**
1577
* Parse frontend value (array) and transform for using it in the database (array)
1678
* Uses json encode just because wrapping methods currently all assume that

0 commit comments

Comments
 (0)