feat: vacation mode & hide counters
This commit is contained in:
parent
c2a7ae59e8
commit
fa0e7f6413
19 changed files with 314 additions and 95 deletions
|
@ -412,11 +412,13 @@ export class UserEntityService implements OnModuleInit {
|
|||
}, options);
|
||||
|
||||
const user = typeof src === 'object' ? src : await this.usersRepository.findOneByOrFail({ id: src });
|
||||
const meObject = await this.usersRepository.findOneByOrFail({ id: me?.id });
|
||||
const meProfile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id });
|
||||
|
||||
const isDetailed = opts.schema !== 'UserLite';
|
||||
const meId = me ? me.id : null;
|
||||
const isMe = meId === user.id;
|
||||
const iAmModerator = me ? await this.roleService.isModerator(me as MiUser) : false;
|
||||
const iAmModerator = me ? (await this.roleService.isModerator(me as MiUser)) && !meObject.isVacation && meProfile.twoFactorEnabled : false;
|
||||
if (user.isSuspended && !iAmModerator) throw new IdentifiableError('85ab9bd7-3a41-4530-959d-f07073900109', `User ${user.id} has been suspended.`);
|
||||
|
||||
const profile = isDetailed
|
||||
|
|
|
@ -481,6 +481,10 @@ export const packedMeDetailedOnlySchema = {
|
|||
type: 'boolean',
|
||||
nullable: true, optional: false,
|
||||
},
|
||||
isVacation: {
|
||||
type: 'boolean',
|
||||
nullable: true, optional: false,
|
||||
},
|
||||
injectFeaturedNote: {
|
||||
type: 'boolean',
|
||||
nullable: false, optional: false,
|
||||
|
|
|
@ -310,7 +310,7 @@ export class ApiCallService implements OnApplicationShutdown {
|
|||
}
|
||||
}
|
||||
|
||||
if ((ep.meta.requireModerator || ep.meta.requireAdmin) && !user!.isRoot) {
|
||||
if (ep.meta.requireModerator || ep.meta.requireAdmin) {
|
||||
const myRoles = await this.roleService.getUserRoles(user!.id);
|
||||
const isModerator = myRoles.some(r => r.isModerator || r.isAdministrator);
|
||||
const isAdmin = myRoles.some(r => r.isAdministrator);
|
||||
|
@ -324,6 +324,14 @@ export class ApiCallService implements OnApplicationShutdown {
|
|||
id: 'abce13fe-1d9f-4e85-8f00-4a5251155470',
|
||||
});
|
||||
}
|
||||
if (user?.isVacation) {
|
||||
throw new ApiError({
|
||||
message: 'You are on vacation.',
|
||||
code: 'VACATION_MODE',
|
||||
kind: 'permission',
|
||||
id: 'bbe5ef78-fab6-46a2-9e29-64639747096c',
|
||||
});
|
||||
}
|
||||
if (ep.meta.requireModerator && !isModerator) {
|
||||
throw new ApiError({
|
||||
message: 'You are not assigned to a proper role.',
|
||||
|
|
|
@ -28,12 +28,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
constructor(
|
||||
private cacheService: CacheService,
|
||||
private apDbResolverService: ApDbResolverService,
|
||||
private authenticateService: AuthenticateService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
this.cacheService.dispose();
|
||||
this.apDbResolverService.dispose();
|
||||
this.authenticateService.dispose()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,6 +187,7 @@ export const paramDef = {
|
|||
preventAiLearning: { type: 'boolean' },
|
||||
isBot: { type: 'boolean' },
|
||||
isCat: { type: 'boolean' },
|
||||
isVacation: { type: 'boolean' },
|
||||
injectFeaturedNote: { type: 'boolean' },
|
||||
receiveAnnouncementEmail: { type: 'boolean' },
|
||||
alwaysMarkNsfw: { type: 'boolean' },
|
||||
|
@ -341,6 +342,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
if (typeof ps.noCrawle === 'boolean') profileUpdates.noCrawle = ps.noCrawle;
|
||||
if (typeof ps.preventAiLearning === 'boolean') profileUpdates.preventAiLearning = ps.preventAiLearning;
|
||||
if (typeof ps.isCat === 'boolean') updates.isCat = ps.isCat;
|
||||
if (typeof ps.isVacation === 'boolean') updates.isVacation = ps.isVacation;
|
||||
if (typeof ps.injectFeaturedNote === 'boolean') profileUpdates.injectFeaturedNote = ps.injectFeaturedNote;
|
||||
if (typeof ps.receiveAnnouncementEmail === 'boolean') profileUpdates.receiveAnnouncementEmail = ps.receiveAnnouncementEmail;
|
||||
if (typeof ps.alwaysMarkNsfw === 'boolean') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue