Skip to content

Commit

Permalink
Start admin routes (very basic)
Browse files Browse the repository at this point in the history
  • Loading branch information
plexus committed Aug 26, 2024
1 parent 58d46d6 commit 9411791
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/co/gaiwan/compass/http/routes.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
(ns co.gaiwan.compass.http.routes
"Combined HTTP routing table"
(:require
[co.gaiwan.compass.routes.oauth :as oauth]
[co.gaiwan.compass.routes.admin :as admin]
[co.gaiwan.compass.routes.filters :as filters]
[co.gaiwan.compass.routes.meta :as meta]
[co.gaiwan.compass.routes.oauth :as oauth]
[co.gaiwan.compass.routes.profiles :as profiles]
[co.gaiwan.compass.routes.sessions :as sessions]
[co.gaiwan.compass.routes.ticket :as ticket]))
Expand All @@ -15,7 +16,7 @@
(oauth/routes)
(filters/routes)
(ticket/routes)

(admin/routes)
["/fail" {:get {:handler (fn [_] (throw (ex-info "fail" {:fail 1})))}}]])

;; - Sessions
Expand Down
30 changes: 30 additions & 0 deletions src/co/gaiwan/compass/routes/admin.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(ns co.gaiwan.compass.routes.admin
(:require [co.gaiwan.compass.db :as db]
[co.gaiwan.compass.model.user :as user]
[co.gaiwan.compass.util :as util]))

(defn wrap-admin-only [handler]
(fn [req]
(if (user/admin? (:identity req))
(handler req)
{:status 403
:html/body [:p "Admin only! Make sure you have a registered crew ticket."]})))

(defn all-users []
(map db/entity
(db/q '[:find [?e ...]
:where [?e :user/uuid]]
(db/db))))

(defn GET-users [req]
{:html/body
[:pre
(util/pprint-str (for [u (all-users)]
(into (if-let [t (user/assigned-ticket u)]
{:tito/ticket (into {} t)}
{})
u)))]})

(defn routes []
["/admin" {:middleware [wrap-admin-only]}
["/users" {:get {:handler #'GET-users}}]])

0 comments on commit 9411791

Please sign in to comment.