From 48a3dd770a78010696422708999ecf2700ee0d4e Mon Sep 17 00:00:00 2001 From: Kieran Klukas <92754843+kcoderhtml@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:18:35 -0400 Subject: [PATCH 1/6] Refactor import statement in users.astro to remove unused Organization import --- src/pages/users.astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/users.astro b/src/pages/users.astro index 2953ac8..77c69c0 100644 --- a/src/pages/users.astro +++ b/src/pages/users.astro @@ -44,7 +44,7 @@ if (!session) { }); } -import { db, User, Organization } from "astro:db"; +import { db, User } from "astro:db"; import { like } from "astro:db"; let error = null; From 040d8db2e1befeb0f8fccad5bd0110cad2faf362 Mon Sep 17 00:00:00 2001 From: Kieran Klukas <92754843+kcoderhtml@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:33:00 -0400 Subject: [PATCH 2/6] feat: add settings page with form to update team name --- src/pages/settings.astro | 119 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 src/pages/settings.astro diff --git a/src/pages/settings.astro b/src/pages/settings.astro new file mode 100644 index 0000000..c3f7598 --- /dev/null +++ b/src/pages/settings.astro @@ -0,0 +1,119 @@ +--- +import Base from "../Layouts/Base.astro"; +import AuthContainer from "../components/AuthContainer.astro"; + +import { getSession } from "auth-astro/server"; +import { type Session } from "@auth/core/types"; + +type ExtendedSession = { + team: string; + teamName: string; + teamImage: string; + user: { + role: string; + }; +}; + +const session = (await getSession(Astro.request)) as Session & ExtendedSession; +let error = ""; + +if (Astro.request.method === "POST") { + const data = await Astro.request.formData(); + if (data.has("updateName") && session.user.role === "admin") { + const name = data.get("name") as string; + await db + .update(Organization) + .set({ name }) + .where(like(Organization.team, session.team)); + } else { + error = + "You do not have the necessary permissions to update the team name."; + } +} + +import { db, like, Organization } from "astro:db"; +const team = ( + await db + .select() + .from(Organization) + .where(like(Organization.team, session.team)) +)[0]; +--- + + +
+ +
+ + { + error && ( +
+

Error: {error}

+
+ ) + } + +
+
+
+ + + + + +
+
+ + +
+ + + From 846efef87726462840b9552e58d59a83e5d7f5eb Mon Sep 17 00:00:00 2001 From: Kieran Klukas <92754843+kcoderhtml@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:36:45 -0400 Subject: [PATCH 3/6] feat: Add functionality to delete team in settings page --- src/pages/settings.astro | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/pages/settings.astro b/src/pages/settings.astro index c3f7598..b903df0 100644 --- a/src/pages/settings.astro +++ b/src/pages/settings.astro @@ -29,6 +29,12 @@ if (Astro.request.method === "POST") { error = "You do not have the necessary permissions to update the team name."; } + + if (data.has("delete") && session.user.role === "admin") { + await db.delete(Organization).where(like(Organization.team, session.team)); + } else { + error = "You do not have the necessary permissions to delete the team."; + } } import { db, like, Organization } from "astro:db"; @@ -55,6 +61,15 @@ const team = (
+
+ + +
+
Date: Mon, 22 Apr 2024 12:37:21 -0400 Subject: [PATCH 4/6] chore: add error and moved styling --- src/pages/settings.astro | 51 +++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/pages/settings.astro b/src/pages/settings.astro index b903df0..62bc039 100644 --- a/src/pages/settings.astro +++ b/src/pages/settings.astro @@ -51,15 +51,15 @@ const team = (
- { - error && ( -
-

Error: {error}

-
- ) - } -
+ { + error && ( +
+

Error: {error}

+
+ ) + } +
@@ -88,23 +88,30 @@ const team = ( >
- -
+ +