Compare commits
3 commits
develop
...
refine-mod
Author | SHA1 | Date | |
---|---|---|---|
|
0085b1aca9 | ||
|
bcacebc89f | ||
|
40df6c5168 |
9 changed files with 57 additions and 16 deletions
|
@ -16,7 +16,7 @@ export class ModerationLogService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async insertModerationLog(moderator: { id: User['id'] }, type: string, info?: Record<string, any>) {
|
public async log(moderator: { id: User['id'] }, type: string, info?: Record<string, any>) {
|
||||||
await this.moderationLogsRepository.insert({
|
await this.moderationLogsRepository.insert({
|
||||||
id: this.idService.genId(),
|
id: this.idService.genId(),
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { StreamMessages } from '@/server/api/stream/types.js';
|
||||||
import { IdService } from '@/core/IdService.js';
|
import { IdService } from '@/core/IdService.js';
|
||||||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||||
import type { Packed } from '@/misc/json-schema';
|
import type { Packed } from '@/misc/json-schema';
|
||||||
|
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
||||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||||
|
|
||||||
export type RolePolicies = {
|
export type RolePolicies = {
|
||||||
|
@ -87,6 +88,7 @@ export class RoleService implements OnApplicationShutdown {
|
||||||
private userEntityService: UserEntityService,
|
private userEntityService: UserEntityService,
|
||||||
private globalEventService: GlobalEventService,
|
private globalEventService: GlobalEventService,
|
||||||
private idService: IdService,
|
private idService: IdService,
|
||||||
|
private moderationLogService: ModerationLogService,
|
||||||
) {
|
) {
|
||||||
//this.onMessage = this.onMessage.bind(this);
|
//this.onMessage = this.onMessage.bind(this);
|
||||||
|
|
||||||
|
@ -355,9 +357,11 @@ export class RoleService implements OnApplicationShutdown {
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async assign(userId: User['id'], roleId: Role['id'], expiresAt: Date | null = null): Promise<void> {
|
public async assign(userId: User['id'], roleId: Role['id'], expiresAt: Date | null = null, moderator?: User): Promise<void> {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
|
const role = await this.rolesRepository.findOneByOrFail({ id: roleId });
|
||||||
|
|
||||||
const existing = await this.roleAssignmentsRepository.findOneBy({
|
const existing = await this.roleAssignmentsRepository.findOneBy({
|
||||||
roleId: roleId,
|
roleId: roleId,
|
||||||
userId: userId,
|
userId: userId,
|
||||||
|
@ -387,11 +391,22 @@ export class RoleService implements OnApplicationShutdown {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.globalEventService.publishInternalEvent('userRoleAssigned', created);
|
this.globalEventService.publishInternalEvent('userRoleAssigned', created);
|
||||||
|
|
||||||
|
if (moderator) {
|
||||||
|
this.moderationLogService.log(moderator, 'roleAssigned', {
|
||||||
|
roleId: roleId,
|
||||||
|
roleName: role.name,
|
||||||
|
userId: userId,
|
||||||
|
expiresAt: expiresAt,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async unassign(userId: User['id'], roleId: Role['id']): Promise<void> {
|
public async unassign(userId: User['id'], roleId: Role['id'], moderator?: User): Promise<void> {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
|
const role = await this.rolesRepository.findOneByOrFail({ id: roleId });
|
||||||
|
|
||||||
const existing = await this.roleAssignmentsRepository.findOneBy({ roleId, userId });
|
const existing = await this.roleAssignmentsRepository.findOneBy({ roleId, userId });
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
|
@ -411,6 +426,14 @@ export class RoleService implements OnApplicationShutdown {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.globalEventService.publishInternalEvent('userRoleUnassigned', existing);
|
this.globalEventService.publishInternalEvent('userRoleUnassigned', existing);
|
||||||
|
|
||||||
|
if (moderator) {
|
||||||
|
this.moderationLogService.log(moderator, 'roleUnassigned', {
|
||||||
|
roleId: roleId,
|
||||||
|
roleName: role.name,
|
||||||
|
userId: userId,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
@ -432,6 +455,26 @@ export class RoleService implements OnApplicationShutdown {
|
||||||
redisPipeline.exec();
|
redisPipeline.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@bindThis
|
||||||
|
public async update(role: Role, params: Partial<Role>, moderator?: User): Promise<void> {
|
||||||
|
const date = new Date();
|
||||||
|
await this.rolesRepository.update(role.id, {
|
||||||
|
updatedAt: date,
|
||||||
|
...params,
|
||||||
|
});
|
||||||
|
|
||||||
|
const updated = await this.rolesRepository.findOneByOrFail({ id: role.id });
|
||||||
|
this.globalEventService.publishInternalEvent('roleUpdated', updated);
|
||||||
|
|
||||||
|
if (moderator) {
|
||||||
|
this.moderationLogService.log(moderator, 'roleUpdated', {
|
||||||
|
roleId: role.id,
|
||||||
|
before: role,
|
||||||
|
after: updated,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
this.redisForSub.off('message', this.onMessage);
|
this.redisForSub.off('message', this.onMessage);
|
||||||
|
|
|
@ -74,7 +74,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
roleIdsThatCanBeUsedThisEmojiAsReaction: ps.roleIdsThatCanBeUsedThisEmojiAsReaction ?? [],
|
roleIdsThatCanBeUsedThisEmojiAsReaction: ps.roleIdsThatCanBeUsedThisEmojiAsReaction ?? [],
|
||||||
});
|
});
|
||||||
|
|
||||||
this.moderationLogService.insertModerationLog(me, 'addEmoji', {
|
this.moderationLogService.log(me, 'addEmoji', {
|
||||||
emojiId: emoji.id,
|
emojiId: emoji.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
this.queueService.destroy();
|
this.queueService.destroy();
|
||||||
|
|
||||||
this.moderationLogService.insertModerationLog(me, 'clearQueue');
|
this.moderationLogService.log(me, 'clearQueue');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.moderationLogService.insertModerationLog(me, 'promoteQueue');
|
this.moderationLogService.log(me, 'promoteQueue');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||||
import type { RolesRepository } from '@/models/index.js';
|
import type { RolesRepository } from '@/models/index.js';
|
||||||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { ApiError } from '@/server/api/error.js';
|
import { ApiError } from '@/server/api/error.js';
|
||||||
|
import { RoleService } from '@/core/RoleService.js';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['admin', 'role'],
|
tags: ['admin', 'role'],
|
||||||
|
@ -66,16 +66,16 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
@Inject(DI.rolesRepository)
|
@Inject(DI.rolesRepository)
|
||||||
private rolesRepository: RolesRepository,
|
private rolesRepository: RolesRepository,
|
||||||
|
|
||||||
private globalEventService: GlobalEventService,
|
private roleService: RoleService,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
const role = await this.rolesRepository.findOneBy({ id: ps.roleId });
|
const role = await this.rolesRepository.findOneBy({ id: ps.roleId });
|
||||||
if (role == null) {
|
if (role == null) {
|
||||||
throw new ApiError(meta.errors.noSuchRole);
|
throw new ApiError(meta.errors.noSuchRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
await this.rolesRepository.update(ps.roleId, {
|
await this.roleService.update(role, {
|
||||||
updatedAt: date,
|
updatedAt: date,
|
||||||
name: ps.name,
|
name: ps.name,
|
||||||
description: ps.description,
|
description: ps.description,
|
||||||
|
@ -91,9 +91,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
canEditMembersByModerator: ps.canEditMembersByModerator,
|
canEditMembersByModerator: ps.canEditMembersByModerator,
|
||||||
displayOrder: ps.displayOrder,
|
displayOrder: ps.displayOrder,
|
||||||
policies: ps.policies,
|
policies: ps.policies,
|
||||||
});
|
}, me);
|
||||||
const updated = await this.rolesRepository.findOneByOrFail({ id: ps.roleId });
|
|
||||||
this.globalEventService.publishInternalEvent('roleUpdated', updated);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
isSuspended: true,
|
isSuspended: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.moderationLogService.insertModerationLog(me, 'suspend', {
|
this.moderationLogService.log(me, 'suspend', {
|
||||||
targetId: user.id,
|
targetId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
isSuspended: false,
|
isSuspended: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.moderationLogService.insertModerationLog(me, 'unsuspend', {
|
this.moderationLogService.log(me, 'unsuspend', {
|
||||||
targetId: user.id,
|
targetId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -398,7 +398,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.metaService.update(set);
|
await this.metaService.update(set);
|
||||||
this.moderationLogService.insertModerationLog(me, 'updateMeta');
|
this.moderationLogService.log(me, 'updateMeta');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue