* add first concept * add reverse share funcionality to frontend * allow creator to limit share expiration * moved reverse share in seperate module * add table to manage reverse shares * delete complete share if reverse share was deleted * optimize function names * add db migration * enable reverse share email notifications * fix config variable descriptions * fix migration for new installations
23 lines
720 B
TypeScript
23 lines
720 B
TypeScript
import { CanActivate, ExecutionContext, Injectable } from "@nestjs/common";
|
|
import { User } from "@prisma/client";
|
|
import { Request } from "express";
|
|
import { PrismaService } from "src/prisma/prisma.service";
|
|
|
|
@Injectable()
|
|
export class ReverseShareOwnerGuard implements CanActivate {
|
|
constructor(private prisma: PrismaService) {}
|
|
|
|
async canActivate(context: ExecutionContext) {
|
|
const request: Request = context.switchToHttp().getRequest();
|
|
const { reverseShareId } = request.params;
|
|
|
|
const reverseShare = await this.prisma.reverseShare.findUnique({
|
|
where: { id: reverseShareId },
|
|
});
|
|
|
|
if (!reverseShare) return false;
|
|
|
|
return reverseShare.creatorId == (request.user as User).id;
|
|
}
|
|
}
|