From 0373c11946146556a2840d9663693b352894c5e2 Mon Sep 17 00:00:00 2001 From: skyFzz Date: Thu, 25 Sep 2025 19:37:16 -0400 Subject: [PATCH 1/3] Add admin dashboard --- Dockerfile.dev | 2 +- Makefile | 3 --- main.go | 6 ++++-- migrations/seed.sql | 7 +++++++ templates/index.html.tpl | 15 +++++++++++++++ 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index 8c0e079..a5e78bf 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM golang:1.23.2-alpine +FROM golang:1.25-alpine RUN apk add make curl diff --git a/Makefile b/Makefile index cfc73b9..bb2284b 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,8 @@ all: build tailwind: @mkdir -p tmp - @if [ ! -f tmp/tailwindcss ]; then curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 -o tmp/tailwindcss; fi - @chmod +x tmp/tailwindcss prepare: tailwind build: tailwind - @tmp/tailwindcss -i styles.css -o static/tailwind.css --minify @go build -o tmp/main . diff --git a/main.go b/main.go index fa67b11..57b83c0 100644 --- a/main.go +++ b/main.go @@ -142,12 +142,13 @@ func (r *Router) index(w http.ResponseWriter, req *http.Request) { if hasUserId { row := r.db.QueryRow(` UPDATE users SET last_seen_timestamp = strftime('%s', 'now') WHERE buck_id = ?1 - RETURNING name_num, discord_id, added_to_mailinglist + RETURNING name_num, discord_id, added_to_mailinglist, is_admin `, userId) var nameNum string var discordId sql.NullString var isOnMailingList bool - err := row.Scan(&nameNum, &discordId, &isOnMailingList) + var isAdmin bool + err := row.Scan(&nameNum, &discordId, &isOnMailingList, &isAdmin) if err != nil { log.Println("Failed to get user:", err, userId) http.Redirect(w, req, "/signout", http.StatusTemporaryRedirect) @@ -189,6 +190,7 @@ func (r *Router) index(w http.ResponseWriter, req *http.Request) { "canAttend": canAttend, "hasLinkedDiscord": discordId.Valid, "isOnMailingList": isOnMailingList, + "isAdmin": isAdmin, }) if err != nil { log.Println("Failed to render template:", err) diff --git a/migrations/seed.sql b/migrations/seed.sql index 6d162a4..3c0decb 100644 --- a/migrations/seed.sql +++ b/migrations/seed.sql @@ -1,3 +1,9 @@ +BEGIN; +INSERT OR REPLACE INTO users +(buck_id, discord_id, display_name, name_num, last_seen_timestamp, last_attended_timestamp, added_to_mailinglist, student, alum, employee, faculty, is_admin) +VALUES +(500123456, NULL, 'Brutus Buckeye', 'buckeye.1', NULL, NULL, 1,1,0,0,0,1); + INSERT OR REPLACE INTO users (buck_id, discord_id, display_name, name_num, last_seen_timestamp, last_attended_timestamp, added_to_mailinglist, student, alum, employee, faculty) VALUES @@ -1001,3 +1007,4 @@ VALUES (525119038,NULL,'Rickie Cheetam','cheetam.4576',1684794159,1652435455,0,1,0,1,0), (506436165,6536698969953349102,'Brook Andreu','andreu.3878',1638836524,1651666692,0,1,1,1,0), (533335732,NULL,'Gale Biggins','biggins.3347',1655272710,1663024697,1,1,0,0,1); +COMMIT; diff --git a/templates/index.html.tpl b/templates/index.html.tpl index c4845b2..5e0b087 100644 --- a/templates/index.html.tpl +++ b/templates/index.html.tpl @@ -78,5 +78,20 @@ + {{ if .isAdmin }} +
+
Admin Dashboard
+
+

+ You are an admin. Click + here to go to the admin page. +

+
+
+ {{ end }} {{ end }} From f89b57d58a40e47901dac94aebb35ec63d7073d2 Mon Sep 17 00:00:00 2001 From: Haoling_Zhou Date: Thu, 2 Oct 2025 18:16:03 -0400 Subject: [PATCH 2/3] fixed lint --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 5f6ddd0..0702388 100644 --- a/main.go +++ b/main.go @@ -148,7 +148,7 @@ func (r *Router) index(w http.ResponseWriter, req *http.Request) { var nameNum string var discordId sql.NullString var isOnMailingList bool - var isAdmin bool + var isAdmin bool err := row.Scan(&nameNum, &discordId, &isOnMailingList, &isAdmin) if err != nil { log.Println("Failed to get user:", err, userId) From 8a99e97ed6613484751b284ac6d32b6786e48d53 Mon Sep 17 00:00:00 2001 From: Haoling_Zhou Date: Thu, 2 Oct 2025 18:17:49 -0400 Subject: [PATCH 3/3] fixed lint --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 0702388..fe3ab5f 100644 --- a/main.go +++ b/main.go @@ -191,7 +191,7 @@ func (r *Router) index(w http.ResponseWriter, req *http.Request) { "canAttend": canAttend, "hasLinkedDiscord": discordId.Valid, "isOnMailingList": isOnMailingList, - "isAdmin": isAdmin, + "isAdmin": isAdmin, }) if err != nil { log.Println("Failed to render template:", err)