mirror of https://github.com/ghostfolio/ghostfolio
Browse Source
* Support impersonation of all users for local development * Update changelogpull/1902/head
Thomas Kaul
2 years ago
committed by
GitHub
9 changed files with 67 additions and 23 deletions
@ -1,15 +1,35 @@ |
|||||
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; |
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() |
@Injectable() |
||||
export class ImpersonationService { |
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({ |
const accessObject = await this.prismaService.access.findFirst({ |
||||
where: { GranteeUser: { id: aUserId }, id: aId } |
where: { |
||||
|
GranteeUser: { id: this.request.user.id }, |
||||
|
id: aId |
||||
|
} |
||||
}); |
}); |
||||
|
|
||||
|
if (accessObject?.userId) { |
||||
return accessObject?.userId; |
return accessObject?.userId; |
||||
|
} else if ( |
||||
|
hasPermission( |
||||
|
this.request.user.permissions, |
||||
|
permissions.impersonateAllUsers |
||||
|
) |
||||
|
) { |
||||
|
return aId; |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
} |
} |
||||
} |
} |
||||
|
Loading…
Reference in new issue