Add sharing to pixel and link detail pages
This commit is contained in:
1 parent
c4226bc63d
commit
64bf4c378c
23 files changed
+582
-43
No files matched your search
@@ -3,15 +3,19 @@ import { PERMISSIONS } from '@/lib/constants';
|
||||
import type { Auth } from '@/lib/types';
|
||||
import { getLink, getTeamUser } from '@/queries/prisma';
|
||||
|
||||
export async function canViewLink({ user }: Auth, linkId: string) {
|
||||
if (!user) {
|
||||
return false;
|
||||
export async function canViewLink({ user, shareToken }: Auth, linkId: string) {
|
||||
if (user?.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (user.isAdmin) {
|
||||
if (shareToken?.linkId === linkId || shareToken?.websiteId === linkId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const link = await getLink(linkId);
|
||||
|
||||
if (link.userId) {
|
||||
|
||||
@@ -3,15 +3,19 @@ import { PERMISSIONS } from '@/lib/constants';
|
||||
import type { Auth } from '@/lib/types';
|
||||
import { getPixel, getTeamUser } from '@/queries/prisma';
|
||||
|
||||
export async function canViewPixel({ user }: Auth, pixelId: string) {
|
||||
if (!user) {
|
||||
return false;
|
||||
export async function canViewPixel({ user, shareToken }: Auth, pixelId: string) {
|
||||
if (user?.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (user.isAdmin) {
|
||||
if (shareToken?.pixelId === pixelId || shareToken?.websiteId === pixelId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const pixel = await getPixel(pixelId);
|
||||
|
||||
if (pixel.userId) {
|
||||
|
||||
@@ -9,7 +9,12 @@ export async function canViewWebsite({ user, shareToken }: Auth, websiteId: stri
|
||||
return true;
|
||||
}
|
||||
|
||||
if (shareToken?.websiteId === websiteId || shareToken?.websiteIds?.includes(websiteId)) {
|
||||
if (
|
||||
shareToken?.websiteId === websiteId ||
|
||||
shareToken?.pixelId === websiteId ||
|
||||
shareToken?.linkId === websiteId ||
|
||||
shareToken?.websiteIds?.includes(websiteId)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user