Feature/extend support for impersonation mode (#1898)
* Support impersonation of all users for local development * Update changelogpull/1902/head
parent
672d8dfab2
commit
f4c748f67a
@ -1,15 +1,35 @@
|
||||
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
|
||||
import { RequestWithUser } from '@ghostfolio/common/types';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { REQUEST } from '@nestjs/core';
|
||||
|
||||
@Injectable()
|
||||
export class ImpersonationService {
|
||||
public constructor(private readonly prismaService: PrismaService) {}
|
||||
public constructor(
|
||||
private readonly prismaService: PrismaService,
|
||||
@Inject(REQUEST) private readonly request: RequestWithUser
|
||||
) {}
|
||||
|
||||
public async validateImpersonationId(aId = '', aUserId: string) {
|
||||
public async validateImpersonationId(aId = '') {
|
||||
const accessObject = await this.prismaService.access.findFirst({
|
||||
where: { GranteeUser: { id: aUserId }, id: aId }
|
||||
where: {
|
||||
GranteeUser: { id: this.request.user.id },
|
||||
id: aId
|
||||
}
|
||||
});
|
||||
|
||||
return accessObject?.userId;
|
||||
if (accessObject?.userId) {
|
||||
return accessObject?.userId;
|
||||
} else if (
|
||||
hasPermission(
|
||||
this.request.user.permissions,
|
||||
permissions.impersonateAllUsers
|
||||
)
|
||||
) {
|
||||
return aId;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue