Refactored permissions check. Updated redis lib.

This commit is contained in:
Mike Cao 2022-12-01 10:58:50 -08:00
parent 1a7369e1f6
commit a4e80ca3e5
5 changed files with 58 additions and 15 deletions

View file

@ -120,3 +120,23 @@ export async function checkPermission(req: NextApiRequestAuth, type: UmamiApi.Pe
return userRole.length > 0;
}
export async function canViewWebsite(userId: string, websiteId: string) {
const website = await cache.fetchWebsite(websiteId);
if (website.userId) {
return userId === website.userId;
}
return false;
}
export async function canUpdateWebsite(userId: string, websiteId: string) {
const website = await cache.fetchWebsite(websiteId);
if (website.userId) {
return userId === website.userId;
}
return false;
}