Skip to content

Commit 3c96943

Browse files
fix(core): add rate limit and extract people menu types
Assisted-by: Cursor:Composer Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent dd93bda commit 3c96943

4 files changed

Lines changed: 18 additions & 13 deletions

File tree

core/Controller/ContactsMenuController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCP\AppFramework\Http;
1414
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
1515
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
16+
use OCP\AppFramework\Http\Attribute\UserRateLimit;
1617
use OCP\AppFramework\Http\JSONResponse;
1718
use OCP\Contacts\ContactsMenu\IEntry;
1819
use OCP\ICacheFactory;
@@ -85,6 +86,7 @@ public function getTeams(): array {
8586
* @throws Exception
8687
*/
8788
#[NoAdminRequired]
89+
#[UserRateLimit(limit: 30, period: 300)]
8890
#[FrontpageRoute(verb: 'GET', url: '/contactsmenu/preview-avatars')]
8991
public function previewAvatars(?string $teamId = null): array {
9092
$user = $this->userSession->getUser();

core/src/tests/views/ContactsMenu.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6+
import type { IPreviewUser } from '../../types/contactsMenu.ts'
7+
68
import { cleanup, findAllByRole, render } from '@testing-library/vue'
79
import { afterEach, describe, expect, it, vi } from 'vitest'
810
import ContactsMenu from '../../views/ContactsMenu.vue'
@@ -19,15 +21,10 @@ vi.mock('@nextcloud/auth', () => ({
1921

2022
afterEach(cleanup)
2123

22-
function mockDefaultGets(previewUsers: Array<{ uid: string, fullName: string, isUser?: boolean }> = []) {
24+
function mockDefaultGets(previewUsers: IPreviewUser[] = []) {
2325
axios.get.mockImplementation(async (url: string) => {
2426
if (String(url).includes('/contactsmenu/preview-avatars')) {
25-
return {
26-
data: previewUsers.map((user) => ({
27-
isUser: true,
28-
...user,
29-
})),
30-
}
27+
return { data: previewUsers }
3128
}
3229
return { data: [] }
3330
})

core/src/types/contactsMenu.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
export interface IPreviewUser {
7+
uid: string
8+
fullName: string
9+
isUser: boolean
10+
}

core/src/views/ContactsMenu.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
-->
55

66
<script setup lang="ts">
7+
import type { IPreviewUser } from '../types/contactsMenu.ts'
8+
79
import { mdiAccountGroupOutline, mdiContacts, mdiMagnify } from '@mdi/js'
810
import { getCurrentUser } from '@nextcloud/auth'
911
import axios from '@nextcloud/axios'
@@ -24,12 +26,6 @@ import NcTextField from '@nextcloud/vue/components/NcTextField'
2426
import ContactMenuEntry from '../components/ContactsMenu/ContactMenuEntry.vue'
2527
import logger from '../logger.js'
2628
27-
interface IPreviewUser {
28-
uid: string
29-
fullName: string
30-
isUser: boolean
31-
}
32-
3329
const storage = getBuilder('core:contacts')
3430
.persist(true)
3531
.clearOnLogout(true)

0 commit comments

Comments
 (0)