Skip to content

Commit d0ee020

Browse files
authored
Fix(backend): Limit antenna/webhook/list to exact amount (#14036)
... not +1 * Update antennas/clips e2e test
1 parent 379ce01 commit d0ee020

File tree

9 files changed

+12
-14
lines changed

9 files changed

+12
-14
lines changed

packages/backend/src/core/ClipService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class ClipService {
4141
const currentCount = await this.clipsRepository.countBy({
4242
userId: me.id,
4343
});
44-
if (currentCount > (await this.roleService.getUserPolicies(me.id)).clipLimit) {
44+
if (currentCount >= (await this.roleService.getUserPolicies(me.id)).clipLimit) {
4545
throw new ClipService.TooManyClipsError();
4646
}
4747

@@ -102,7 +102,7 @@ export class ClipService {
102102
const currentCount = await this.clipNotesRepository.countBy({
103103
clipId: clip.id,
104104
});
105-
if (currentCount > (await this.roleService.getUserPolicies(me.id)).noteEachClipsLimit) {
105+
if (currentCount >= (await this.roleService.getUserPolicies(me.id)).noteEachClipsLimit) {
106106
throw new ClipService.TooManyClipNotesError();
107107
}
108108

packages/backend/src/core/UserListService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class UserListService implements OnApplicationShutdown, OnModuleInit {
9595
const currentCount = await this.userListMembershipsRepository.countBy({
9696
userListId: list.id,
9797
});
98-
if (currentCount > (await this.roleService.getUserPolicies(me.id)).userEachUserListsLimit) {
98+
if (currentCount >= (await this.roleService.getUserPolicies(me.id)).userEachUserListsLimit) {
9999
throw new UserListService.TooManyUsersError();
100100
}
101101

packages/backend/src/server/api/endpoints/antennas/create.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
9393
const currentAntennasCount = await this.antennasRepository.countBy({
9494
userId: me.id,
9595
});
96-
if (currentAntennasCount > (await this.roleService.getUserPolicies(me.id)).antennaLimit) {
96+
if (currentAntennasCount >= (await this.roleService.getUserPolicies(me.id)).antennaLimit) {
9797
throw new ApiError(meta.errors.tooManyAntennas);
9898
}
9999

packages/backend/src/server/api/endpoints/i/import-antennas.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
7878
if (file.size === 0) throw new ApiError(meta.errors.emptyFile);
7979
const antennas: (_Antenna & { userListAccts: string[] | null })[] = JSON.parse(await this.downloadService.downloadTextFile(file.url));
8080
const currentAntennasCount = await this.antennasRepository.countBy({ userId: me.id });
81-
if (currentAntennasCount + antennas.length > (await this.roleService.getUserPolicies(me.id)).antennaLimit) {
81+
if (currentAntennasCount + antennas.length >= (await this.roleService.getUserPolicies(me.id)).antennaLimit) {
8282
throw new ApiError(meta.errors.tooManyAntennas);
8383
}
8484
this.queueService.createImportAntennasJob(me, antennas);

packages/backend/src/server/api/endpoints/i/webhooks/create.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
8585
const currentWebhooksCount = await this.webhooksRepository.countBy({
8686
userId: me.id,
8787
});
88-
if (currentWebhooksCount > (await this.roleService.getUserPolicies(me.id)).webhookLimit) {
88+
if (currentWebhooksCount >= (await this.roleService.getUserPolicies(me.id)).webhookLimit) {
8989
throw new ApiError(meta.errors.tooManyWebhooks);
9090
}
9191

packages/backend/src/server/api/endpoints/users/lists/create-from-public.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
100100
const currentCount = await this.userListsRepository.countBy({
101101
userId: me.id,
102102
});
103-
if (currentCount > (await this.roleService.getUserPolicies(me.id)).userListLimit) {
103+
if (currentCount >= (await this.roleService.getUserPolicies(me.id)).userListLimit) {
104104
throw new ApiError(meta.errors.tooManyUserLists);
105105
}
106106

packages/backend/src/server/api/endpoints/users/lists/create.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
6161
const currentCount = await this.userListsRepository.countBy({
6262
userId: me.id,
6363
});
64-
if (currentCount > (await this.roleService.getUserPolicies(me.id)).userListLimit) {
64+
if (currentCount >= (await this.roleService.getUserPolicies(me.id)).userListLimit) {
6565
throw new ApiError(meta.errors.tooManyUserLists);
6666
}
6767

packages/backend/test/e2e/antennas.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ describe('アンテナ', () => {
163163
});
164164

165165
test('が上限いっぱいまで作成できること', async () => {
166-
// antennaLimit + 1まで作れるのがキモ
167-
const response = await Promise.all([...Array(DEFAULT_POLICIES.antennaLimit + 1)].map(() => successfulApiCall({
166+
const response = await Promise.all([...Array(DEFAULT_POLICIES.antennaLimit)].map(() => successfulApiCall({
168167
endpoint: 'antennas/create',
169168
parameters: { ...defaultParam },
170169
user: alice,

packages/backend/test/e2e/clips.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ describe('クリップ', () => {
153153
});
154154

155155
test('の作成はポリシーで定められた数以上はできない。', async () => {
156-
// ポリシー + 1まで作れるという所がミソ
157-
const clipLimit = DEFAULT_POLICIES.clipLimit + 1;
156+
const clipLimit = DEFAULT_POLICIES.clipLimit;
158157
for (let i = 0; i < clipLimit; i++) {
159158
await create();
160159
}
@@ -327,7 +326,7 @@ describe('クリップ', () => {
327326
});
328327

329328
test('の一覧(clips/list)が取得できる(上限いっぱい)', async () => {
330-
const clipLimit = DEFAULT_POLICIES.clipLimit + 1;
329+
const clipLimit = DEFAULT_POLICIES.clipLimit;
331330
const clips = await createMany({}, clipLimit);
332331
const res = await list({
333332
parameters: { limit: 1 }, // FIXME: 無視されて11全部返ってくる
@@ -705,7 +704,7 @@ describe('クリップ', () => {
705704

706705
// TODO: 17000msくらいかかる...
707706
test('をポリシーで定められた上限いっぱい(200)を超えて追加はできない。', async () => {
708-
const noteLimit = DEFAULT_POLICIES.noteEachClipsLimit + 1;
707+
const noteLimit = DEFAULT_POLICIES.noteEachClipsLimit;
709708
const noteList = await Promise.all([...Array(noteLimit)].map((_, i) => post(alice, {
710709
text: `test ${i}`,
711710
}) as unknown)) as Misskey.entities.Note[];

0 commit comments

Comments
 (0)