added collaboration mode for collections
This commit is contained in:
@@ -8,7 +8,13 @@ import { prisma } from "@/lib/api/db";
|
||||
export default async function (userId: number) {
|
||||
const collections = await prisma.collection.findMany({
|
||||
where: {
|
||||
ownerId: userId,
|
||||
OR: [
|
||||
{ ownerId: userId },
|
||||
{ members: { some: { user: { id: userId } } } },
|
||||
],
|
||||
},
|
||||
include: {
|
||||
members: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import { Collection } from "@prisma/client";
|
||||
import { NewCollection } from "@/types/global";
|
||||
import { existsSync, mkdirSync } from "fs";
|
||||
|
||||
export default async function (collection: Collection, userId: number) {
|
||||
export default async function (collection: NewCollection, userId: number) {
|
||||
if (!collection || collection.name.trim() === "")
|
||||
return {
|
||||
response: "Please enter a valid collection.",
|
||||
@@ -41,6 +41,14 @@ export default async function (collection: Collection, userId: number) {
|
||||
},
|
||||
name: collection.name,
|
||||
description: collection.description,
|
||||
members: {
|
||||
create: collection.members.map((e) => ({
|
||||
user: { connect: { email: e.email } },
|
||||
canCreate: e.canCreate,
|
||||
canUpdate: e.canUpdate,
|
||||
canDelete: e.canDelete,
|
||||
})),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -7,15 +7,12 @@ import { prisma } from "@/lib/api/db";
|
||||
import { ExtendedLink } from "@/types/global";
|
||||
import fs from "fs";
|
||||
import { Link, UsersAndCollections } from "@prisma/client";
|
||||
import hasAccessToCollection from "@/lib/api/hasAccessToCollection";
|
||||
import getPermission from "@/lib/api/getPermission";
|
||||
|
||||
export default async function (link: ExtendedLink, userId: number) {
|
||||
if (!link) return { response: "Please choose a valid link.", status: 401 };
|
||||
|
||||
const collectionIsAccessible = await hasAccessToCollection(
|
||||
userId,
|
||||
link.collectionId
|
||||
);
|
||||
const collectionIsAccessible = await getPermission(userId, link.collectionId);
|
||||
|
||||
const memberHasAccess = collectionIsAccessible?.members.some(
|
||||
(e: UsersAndCollections) => e.userId === userId && e.canDelete
|
||||
|
||||
@@ -9,7 +9,7 @@ import getTitle from "../../getTitle";
|
||||
import archive from "../../archive";
|
||||
import { Link, UsersAndCollections } from "@prisma/client";
|
||||
import AES from "crypto-js/aes";
|
||||
import hasAccessToCollection from "@/lib/api/hasAccessToCollection";
|
||||
import getPermission from "@/lib/api/getPermission";
|
||||
|
||||
export default async function (link: ExtendedLink, userId: number) {
|
||||
link.collection.name = link.collection.name.trim();
|
||||
@@ -21,7 +21,7 @@ export default async function (link: ExtendedLink, userId: number) {
|
||||
}
|
||||
|
||||
if (link.collection.ownerId) {
|
||||
const collectionIsAccessible = await hasAccessToCollection(
|
||||
const collectionIsAccessible = await getPermission(
|
||||
userId,
|
||||
link.collection.id
|
||||
);
|
||||
|
||||
@@ -6,15 +6,12 @@
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import { ExtendedLink } from "@/types/global";
|
||||
import { Link, UsersAndCollections } from "@prisma/client";
|
||||
import hasAccessToCollection from "@/lib/api/hasAccessToCollection";
|
||||
import getPermission from "@/lib/api/getPermission";
|
||||
|
||||
export default async function (link: ExtendedLink, userId: number) {
|
||||
if (!link) return { response: "Please choose a valid link.", status: 401 };
|
||||
|
||||
const collectionIsAccessible = await hasAccessToCollection(
|
||||
userId,
|
||||
link.collectionId
|
||||
);
|
||||
const collectionIsAccessible = await getPermission(userId, link.collectionId);
|
||||
|
||||
const memberHasAccess = collectionIsAccessible?.members.some(
|
||||
(e: UsersAndCollections) => e.userId === userId && e.canUpdate
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2022-present Daniel31x13 <daniel31x13@gmail.com>
|
||||
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import { prisma } from "@/lib/api/db";
|
||||
|
||||
export default async function (email: string) {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
email,
|
||||
},
|
||||
});
|
||||
|
||||
const unsensitiveUserInfo = {
|
||||
name: user?.name,
|
||||
email: user?.email,
|
||||
createdAt: user?.createdAt,
|
||||
};
|
||||
|
||||
return { response: unsensitiveUserInfo || null, status: 200 };
|
||||
}
|
||||
Reference in New Issue
Block a user