1919use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
2020use OCP \AppFramework \Http \Attribute \NoSubAdminRequired ;
2121use OCP \AppFramework \Http \Attribute \PasswordConfirmationRequired ;
22+ use OCP \AppFramework \Http \Attribute \UserRateLimit ;
2223use OCP \AppFramework \Http \DataResponse ;
2324use OCP \AppFramework \OCS \OCSException ;
2425use OCP \AppFramework \OCS \OCSForbiddenException ;
4243 * @psalm-import-type Provisioning_APIUserDetailsGroupDisplayname from ResponseDefinitions
4344 */
4445class GroupsController extends AUserDataOCSController {
46+ public const int MAX_SEARCH_RESULTS = 500 ;
47+
4548
4649 public function __construct (
4750 string $ appName ,
@@ -75,15 +78,15 @@ public function __construct(
7578 * Get a list of groups
7679 *
7780 * @param string $search Text to search for
78- * @param ?int $limit Limit the amount of groups returned
81+ * @param ?int<1, 500> $limit Limit the amount of groups returned, defaults to 500
7982 * @param int $offset Offset for searching for groups
8083 * @return DataResponse<Http::STATUS_OK, array{groups: list<string>}, array{}>
8184 *
8285 * 200: Groups returned
8386 */
8487 #[NoAdminRequired]
8588 public function getGroups (string $ search = '' , ?int $ limit = null , int $ offset = 0 ): DataResponse {
86- $ groups = $ this ->groupManager -> search ($ search , $ limit , $ offset );
89+ $ groups = $ this ->searchGroups ($ search , $ limit , $ offset );
8790 $ groups = array_map (function ($ group ) {
8891 /** @var IGroup $group */
8992 return $ group ->getGID ();
@@ -96,7 +99,7 @@ public function getGroups(string $search = '', ?int $limit = null, int $offset =
9699 * Get a list of groups details
97100 *
98101 * @param string $search Text to search for
99- * @param ?int $limit Limit the amount of groups returned
102+ * @param ?int<1, 500> $limit Limit the amount of groups returned, defaults to 500
100103 * @param int $offset Offset for searching for groups
101104 * @return DataResponse<Http::STATUS_OK, array{groups: list<Provisioning_APIGroupDetails>}, array{}>
102105 *
@@ -106,7 +109,7 @@ public function getGroups(string $search = '', ?int $limit = null, int $offset =
106109 #[AuthorizedAdminSetting(settings: Sharing::class)]
107110 #[AuthorizedAdminSetting(settings: Users::class)]
108111 public function getGroupsDetails (string $ search = '' , ?int $ limit = null , int $ offset = 0 ): DataResponse {
109- $ groups = $ this ->groupManager -> search ($ search , $ limit , $ offset );
112+ $ groups = $ this ->searchGroups ($ search , $ limit , $ offset );
110113 $ groups = array_map (function ($ group ) {
111114 /** @var IGroup $group */
112115 return [
@@ -122,6 +125,17 @@ public function getGroupsDetails(string $search = '', ?int $limit = null, int $o
122125 return new DataResponse (['groups ' => $ groups ]);
123126 }
124127
128+ /**
129+ * @return list<IGroup>
130+ */
131+ private function searchGroups (string $ search , ?int $ limit , int $ offset ): array {
132+ if ($ limit === null || $ limit <= 0 || $ limit > self ::MAX_SEARCH_RESULTS ) {
133+ $ limit = self ::MAX_SEARCH_RESULTS ;
134+ }
135+
136+ return $ this ->groupManager ->search ($ search , $ limit , $ offset );
137+ }
138+
125139 /**
126140 * Get a list of users in the specified group
127141 *
@@ -254,6 +268,7 @@ public function getGroupUsersDetails(string $groupId, string $search = '', ?int
254268 * 200: Group created successfully
255269 */
256270 #[AuthorizedAdminSetting(settings:Users::class)]
271+ #[UserRateLimit(limit: 50 , period: 600 )]
257272 #[PasswordConfirmationRequired]
258273 public function addGroup (string $ groupid , string $ displayname = '' ): DataResponse {
259274 // Validate name
0 commit comments