fix guest actions

This commit is contained in:
Emily
2024-06-19 23:38:22 +02:00
parent c1a15c8fc2
commit 149592394d
9 changed files with 27 additions and 13 deletions

View File

@@ -3,7 +3,7 @@ import { ProjectModel } from "~/../shared/schema/ProjectSchema";
import { LITLYX_PROJECT_ID } from '@data/LITLYX'
import { hasAccessToProject } from "./utils/hasAccessToProject";
export async function getUserProjectFromId(project_id: string, user: AuthContext | undefined) {
export async function getUserProjectFromId(project_id: string, user: AuthContext | undefined, allowGuest: boolean = true) {
if (project_id == LITLYX_PROJECT_ID) {
const project = await ProjectModel.findOne({ _id: project_id });
return project;
@@ -11,8 +11,9 @@ export async function getUserProjectFromId(project_id: string, user: AuthContext
if (!user?.logged) return;
const project = await ProjectModel.findById(project_id);
if (!project) return;
const hasAccess = await hasAccessToProject(user.id, project_id, project);
const [hasAccess, role] = await hasAccessToProject(user.id, project_id, project);
if (!hasAccess) return;
if (role === 'GUEST' && !allowGuest) return false;
return project;
}