Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

bug fixes

daniel31x13508844dd9d28
diff --git a/components/ProfileDropdown.tsx b/components/ProfileDropdown.tsx
index 81e0505b..9d1260b8 100644
--- a/components/ProfileDropdown.tsx
+++ b/components/ProfileDropdown.tsx
@@ -6,6 +6,8 @@ import { signOut } from "next-auth/react";
import { useTranslation } from "next-i18next";
import { useUser } from "@/hooks/store/user";
+const stripeEnabled = process.env.NEXT_PUBLIC_STRIPE === "true";
+
export default function ProfileDropdown() {
const { t } = useTranslation();
const { settings, updateSettings } = useLocalSettingsStore();
@@ -73,7 +75,7 @@ export default function ProfileDropdown() {
</Link>
</li>
)}
- {!user.parentSubscriptionId && (
+ {!user.parentSubscriptionId && stripeEnabled && (
<li>
<Link
href="/settings/billing"
diff --git a/components/SettingsSidebar.tsx b/components/SettingsSidebar.tsx
index 54dfb53f..bfc1ed7a 100644
--- a/components/SettingsSidebar.tsx
+++ b/components/SettingsSidebar.tsx
@@ -2,11 +2,14 @@ import Link from "next/link";
import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
import { useTranslation } from "next-i18next";
+import { useUser } from "@/hooks/store/user";
export default function SettingsSidebar({ className }: { className?: string }) {
const { t } = useTranslation();
const LINKWARDEN_VERSION = process.env.version;
+ const { data: user } = useUser();
+
const router = useRouter();
const [active, setActive] = useState("");
@@ -73,7 +76,7 @@ export default function SettingsSidebar({ className }: { className?: string }) {
</div>
</Link>
- {process.env.NEXT_PUBLIC_STRIPE && (
+ {process.env.NEXT_PUBLIC_STRIPE && !user.parentSubscriptionId && (
<Link href="/settings/billing">
<div
className={`${
diff --git a/lib/api/controllers/users/userId/deleteUserById.ts b/lib/api/controllers/users/userId/deleteUserById.ts
index 2c3d864b..2570b25e 100644
--- a/lib/api/controllers/users/userId/deleteUserById.ts
+++ b/lib/api/controllers/users/userId/deleteUserById.ts
@@ -15,7 +15,16 @@ export default async function deleteUserById(
const user = await prisma.user.findUnique({
where: { id: userId },
include: {
- subscriptions: true,
+ subscriptions: {
+ include: {
+ user: true,
+ },
+ },
+ parentSubscription: {
+ include: {
+ user: true,
+ },
+ },
},
});
@@ -178,24 +187,36 @@ export default async function deleteUserById(
});
try {
- const listByEmail = await stripe.customers.list({
- email: user.email?.toLowerCase(),
- expand: ["data.subscriptions"],
- });
-
- if (listByEmail.data[0].subscriptions?.data[0].id) {
- const deleted = await stripe.subscriptions.cancel(
- listByEmail.data[0].subscriptions?.data[0].id,
- {
- cancellation_details: {
- comment: body.cancellation_details?.comment,
- feedback: body.cancellation_details?.feedback,
- },
- }
+ if (user.subscriptions?.id) {
+ const listByEmail = await stripe.customers.list({
+ email: user.email?.toLowerCase(),
+ expand: ["data.subscriptions"],
+ });
+
+ if (listByEmail.data[0].subscriptions?.data[0].id) {
+ const deleted = await stripe.subscriptions.cancel(
+ listByEmail.data[0].subscriptions?.data[0].id,
+ {
+ cancellation_details: {
+ comment: body.cancellation_details?.comment,
+ feedback: body.cancellation_details?.feedback,
+ },
+ }
+ );
+
+ return {
+ response: deleted,
+ status: 200,
+ };
+ }
+ } else if (user.parentSubscription?.id) {
+ await updateSeats(
+ user.parentSubscription.stripeSubscriptionId,
+ user.parentSubscription.quantity - 1
);
return {
- response: deleted,
+ response: "User account and all related data deleted successfully.",
status: 200,
};
}
diff --git a/lib/api/verifyCapacity.ts b/lib/api/verifyCapacity.ts
index bf41b42a..c87984bc 100644
--- a/lib/api/verifyCapacity.ts
+++ b/lib/api/verifyCapacity.ts
@@ -8,7 +8,15 @@ export const hasPassedLimit = async (
numberOfImports: number
) => {
if (!stripeEnabled) {
- return false;
+ const totalLinks = await prisma.link.count({
+ where: {
+ createdBy: {
+ id: userId,
+ },
+ },
+ });
+
+ return MAX_LINKS_PER_USER - (numberOfImports + totalLinks) < 0;
}
const user = await prisma.user.findUnique({
diff --git a/pages/settings/billing.tsx b/pages/settings/billing.tsx
index 1c561e34..37a938f2 100644
--- a/pages/settings/billing.tsx
+++ b/pages/settings/billing.tsx
@@ -28,13 +28,14 @@ export default function Billing() {
const router = useRouter();
const { t } = useTranslation();
+ const { data: account } = useUser();
+ const { data: users = [] } = useUsers();
+
useEffect(() => {
- if (!process.env.NEXT_PUBLIC_STRIPE) router.push("/settings/profile");
+ if (!process.env.NEXT_PUBLIC_STRIPE || account.parentSubscriptionId)
+ router.push("/settings/account");
}, []);
- const { data: users = [] } = useUsers();
- const { data: account } = useUser();
-
const [searchQuery, setSearchQuery] = useState("");
const [filteredUsers, setFilteredUsers] = useState<User[]>();
diff --git a/pages/settings/delete.tsx b/pages/settings/delete.tsx
index 0d11b877..0479d8fd 100644
--- a/pages/settings/delete.tsx
+++ b/pages/settings/delete.tsx
@@ -7,6 +7,7 @@ import Link from "next/link";
import Button from "@/components/ui/Button";
import { useTranslation } from "next-i18next";
import getServerSideProps from "@/lib/client/getServerSideProps";
+import { useUser } from "@/hooks/store/user";
export default function Delete() {
const [password, setPassword] = useState("");
@@ -15,6 +16,7 @@ export default function Delete() {
const [submitLoader, setSubmitLoader] = useState(false);
const { data } = useSession();
const { t } = useTranslation();
+ const { data: user } = useUser();
const submit = async () => {
const body = {
@@ -83,7 +85,7 @@ export default function Delete() {
/>
</div>
- {process.env.NEXT_PUBLIC_STRIPE && (
+ {process.env.NEXT_PUBLIC_STRIPE && !user.parentSubscriptionId && (
<fieldset className="border rounded-md p-2 border-primary">
<legend className="px-3 py-1 text-sm sm:text-base border rounded-md border-primary">
<b>{t("optional")}</b> <i>{t("feedback_help")}</i>
diff --git a/pages/subscribe.tsx b/pages/subscribe.tsx
index 20e95993..4c490f00 100644
--- a/pages/subscribe.tsx
+++ b/pages/subscribe.tsx
@@ -9,8 +9,6 @@ import getServerSideProps from "@/lib/client/getServerSideProps";
import { Trans, useTranslation } from "next-i18next";
import { useUser } from "@/hooks/store/user";
-const stripeEnabled = process.env.NEXT_PUBLIC_STRIPE === "true";
-
export default function Subscribe() {
const { t } = useTranslation();
const [submitLoader, setSubmitLoader] = useState(false);
diff --git a/prisma/migrations/20241030200844_createdby_fields_can_be_null/migration.sql b/prisma/migrations/20241030200844_createdby_fields_can_be_null/migration.sql
new file mode 100644
index 00000000..85c04d9e
--- /dev/null
+++ b/prisma/migrations/20241030200844_createdby_fields_can_be_null/migration.sql
@@ -0,0 +1,17 @@
+-- DropForeignKey
+ALTER TABLE "Collection" DROP CONSTRAINT "Collection_createdById_fkey";
+
+-- DropForeignKey
+ALTER TABLE "Link" DROP CONSTRAINT "Link_createdById_fkey";
+
+-- AlterTable
+ALTER TABLE "Collection" ALTER COLUMN "createdById" DROP NOT NULL;
+
+-- AlterTable
+ALTER TABLE "Link" ALTER COLUMN "createdById" DROP NOT NULL;
+
+-- AddForeignKey
+ALTER TABLE "Collection" ADD CONSTRAINT "Collection_createdById_fkey" FOREIGN KEY ("createdById") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "Link" ADD CONSTRAINT "Link_createdById_fkey" FOREIGN KEY ("createdById") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index ee369ddd..13418433 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -108,8 +108,8 @@ model Collection {
owner User @relation(fields: [ownerId], references: [id])
ownerId Int
members UsersAndCollections[]
- createdBy User @relation("CreatedCollections", fields: [createdById], references: [id])
- createdById Int
+ createdBy User? @relation("CreatedCollections", fields: [createdById], references: [id])
+ createdById Int?
links Link[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@ -138,8 +138,8 @@ model Link {
type String @default("url")
description String @default("")
pinnedBy User[] @relation("PinnedLinks")
- createdBy User @relation("CreatedLinks", fields: [createdById], references: [id])
- createdById Int
+ createdBy User? @relation("CreatedLinks", fields: [createdById], references: [id])
+ createdById Int?
collection Collection @relation(fields: [collectionId], references: [id])
collectionId Int
tags Tag[]