enhance: ユーザーリストおよびユーザーリスト内のユーザーの作成可能数を設定可能に

This commit is contained in:
syuilo
2023-01-14 17:38:16 +09:00
parent c41879c542
commit 76c049522e
9 changed files with 88 additions and 4 deletions

View File

@@ -25,6 +25,8 @@ export type RoleOptions = {
webhookLimit: number;
clipLimit: number;
noteEachClipsLimit: number;
userListLimit: number;
userEachUserListsLimit: number;
};
export const DEFAULT_ROLE: RoleOptions = {
@@ -39,6 +41,8 @@ export const DEFAULT_ROLE: RoleOptions = {
webhookLimit: 3,
clipLimit: 10,
noteEachClipsLimit: 200,
userListLimit: 10,
userEachUserListsLimit: 50,
};
@Injectable()
@@ -212,6 +216,8 @@ export class RoleService implements OnApplicationShutdown {
webhookLimit: Math.max(...getOptionValues('webhookLimit')),
clipLimit: Math.max(...getOptionValues('clipLimit')),
noteEachClipsLimit: Math.max(...getOptionValues('noteEachClipsLimit')),
userListLimit: Math.max(...getOptionValues('userListLimit')),
userEachUserListsLimit: Math.max(...getOptionValues('userEachUserListsLimit')),
};
}

View File

@@ -10,6 +10,7 @@ import { DI } from '@/di-symbols.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { ProxyAccountService } from '@/core/ProxyAccountService.js';
import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
@Injectable()
export class UserListService {
@@ -23,13 +24,21 @@ export class UserListService {
private userEntityService: UserEntityService,
private idService: IdService,
private userFollowingService: UserFollowingService,
private roleService: RoleService,
private globalEventServie: GlobalEventService,
private proxyAccountService: ProxyAccountService,
) {
}
@bindThis
public async push(target: User, list: UserList) {
public async push(target: User, list: UserList, me: User) {
const currentCount = await this.userListJoiningsRepository.countBy({
userListId: list.id,
});
if (currentCount > (await this.roleService.getUserRoleOptions(me.id)).userEachUserListsLimit) {
throw new Error('Too many users');
}
await this.userListJoiningsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),