implemented the user view type and website sharing

This commit is contained in:
hsensh 2023-03-28 10:49:20 +03:00
parent 7a3443cd06
commit 66e67c7a3b
19 changed files with 260 additions and 68 deletions

View file

@ -8,7 +8,8 @@ export default async (req, res) => {
const { user_id, include_all } = req.query;
const { userId: currentUserId, isAdmin } = req.auth;
const { userId: currentUserId, isAdmin, isViewer } = req.auth;
const accountUuid = user_id || req.auth.accountUuid;
let account;
@ -26,7 +27,9 @@ export default async (req, res) => {
const websites =
isAdmin && include_all
? await getAllWebsites()
: await getUserWebsites({ userId: account?.id });
: await getUserWebsites({
OR: [{ userId: account?.id }, { viewers: { some: { userId: account?.id } } }],
});
return ok(res, websites);
}
@ -36,7 +39,7 @@ export default async (req, res) => {
const website_owner = account ? account.id : +owner;
if (website_owner !== currentUserId && !isAdmin) {
if ((website_owner !== currentUserId && !isAdmin) || isViewer) {
return unauthorized(res);
}