mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 08:43:09 +02:00
wip
This commit is contained in:
parent
8bdf0dd135
commit
40df6c5168
8 changed files with 32 additions and 9 deletions
|
@ -16,7 +16,7 @@ export class ModerationLogService {
|
|||
}
|
||||
|
||||
@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({
|
||||
id: this.idService.genId(),
|
||||
createdAt: new Date(),
|
||||
|
|
|
@ -14,6 +14,7 @@ import { StreamMessages } from '@/server/api/stream/types.js';
|
|||
import { IdService } from '@/core/IdService.js';
|
||||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||
import type { Packed } from '@/misc/json-schema';
|
||||
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||
|
||||
export type RolePolicies = {
|
||||
|
@ -87,6 +88,7 @@ export class RoleService implements OnApplicationShutdown {
|
|||
private userEntityService: UserEntityService,
|
||||
private globalEventService: GlobalEventService,
|
||||
private idService: IdService,
|
||||
private moderationLogService: ModerationLogService,
|
||||
) {
|
||||
//this.onMessage = this.onMessage.bind(this);
|
||||
|
||||
|
@ -355,9 +357,11 @@ export class RoleService implements OnApplicationShutdown {
|
|||
}
|
||||
|
||||
@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 role = await this.rolesRepository.findOneByOrFail({ id: roleId });
|
||||
|
||||
const existing = await this.roleAssignmentsRepository.findOneBy({
|
||||
roleId: roleId,
|
||||
userId: userId,
|
||||
|
@ -387,11 +391,22 @@ export class RoleService implements OnApplicationShutdown {
|
|||
});
|
||||
|
||||
this.globalEventService.publishInternalEvent('userRoleAssigned', created);
|
||||
|
||||
if (moderator) {
|
||||
this.moderationLogService.log(moderator, 'roleAssigned', {
|
||||
roleId: roleId,
|
||||
roleName: role.name,
|
||||
userId: userId,
|
||||
expiresAt: expiresAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@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 role = await this.rolesRepository.findOneByOrFail({ id: roleId });
|
||||
|
||||
const existing = await this.roleAssignmentsRepository.findOneBy({ roleId, userId });
|
||||
if (existing == null) {
|
||||
|
@ -411,6 +426,14 @@ export class RoleService implements OnApplicationShutdown {
|
|||
});
|
||||
|
||||
this.globalEventService.publishInternalEvent('userRoleUnassigned', existing);
|
||||
|
||||
if (moderator) {
|
||||
this.moderationLogService.log(moderator, 'roleUnassigned', {
|
||||
roleId: roleId,
|
||||
roleName: role.name,
|
||||
userId: userId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
|
|
|
@ -74,7 +74,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
roleIdsThatCanBeUsedThisEmojiAsReaction: ps.roleIdsThatCanBeUsedThisEmojiAsReaction ?? [],
|
||||
});
|
||||
|
||||
this.moderationLogService.insertModerationLog(me, 'addEmoji', {
|
||||
this.moderationLogService.log(me, 'addEmoji', {
|
||||
emojiId: emoji.id,
|
||||
});
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
super(meta, paramDef, async (ps, me) => {
|
||||
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;
|
||||
}
|
||||
|
||||
this.moderationLogService.insertModerationLog(me, 'promoteQueue');
|
||||
this.moderationLogService.log(me, 'promoteQueue');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
isSuspended: true,
|
||||
});
|
||||
|
||||
this.moderationLogService.insertModerationLog(me, 'suspend', {
|
||||
this.moderationLogService.log(me, 'suspend', {
|
||||
targetId: user.id,
|
||||
});
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
isSuspended: false,
|
||||
});
|
||||
|
||||
this.moderationLogService.insertModerationLog(me, 'unsuspend', {
|
||||
this.moderationLogService.log(me, 'unsuspend', {
|
||||
targetId: user.id,
|
||||
});
|
||||
|
||||
|
|
|
@ -398,7 +398,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
}
|
||||
|
||||
await this.metaService.update(set);
|
||||
this.moderationLogService.insertModerationLog(me, 'updateMeta');
|
||||
this.moderationLogService.log(me, 'updateMeta');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue