Relocate admin routes to make room for API

Nathan Sobo created

I want to use the top-level /users route for the API that we'll access from the front-end site running on Vercel, and this is the easiest way to make space. Eventually we won't have admin pages, but I want to be additive for now.

Change summary

crates/server/src/admin.rs        |  8 ++++----
crates/server/templates/admin.hbs | 30 ++++++++++++++++++------------
2 files changed, 22 insertions(+), 16 deletions(-)

Detailed changes

crates/server/src/admin.rs 🔗

@@ -30,10 +30,10 @@ impl RequestExt for Request {
 
 pub fn add_routes(app: &mut tide::Server<Arc<AppState>>) {
     app.at("/admin").get(get_admin_page);
-    app.at("/users").post(post_user);
-    app.at("/users/:id").put(put_user);
-    app.at("/users/:id/delete").post(delete_user);
-    app.at("/signups/:id/delete").post(delete_signup);
+    app.at("/admin/users").post(post_user);
+    app.at("/admin/users/:id").put(put_user);
+    app.at("/admin/users/:id/delete").post(delete_user);
+    app.at("/admin/signups/:id/delete").post(delete_signup);
 }
 
 #[derive(Serialize)]

crates/server/templates/admin.hbs 🔗

@@ -24,13 +24,15 @@
     <div class="flex flex-row items-center justify-between p-5 border-b border-white pl-7 pr-7 admin-nav">
         <h1 class="font-display font-extralight">Admin</h1>
         <ul class="flex flex-row">
-            <li><a href="#userlist" class="mr-4 leading-relaxed no-underline lowercase text-main hover:underline">Users</a></li>
-            <li><a href="#signuplist" class="leading-relaxed no-underline lowercase text-main hover:underline">Signups</a></li>
+            <li><a href="#userlist"
+                    class="mr-4 leading-relaxed no-underline lowercase text-main hover:underline">Users</a></li>
+            <li><a href="#signuplist"
+                    class="leading-relaxed no-underline lowercase text-main hover:underline">Signups</a></li>
         </ul>
     </div>
 
     <h2 id="userlist" class="pt-10 mb-5 text-white pl-7 pr-7 font-display font-extralight">Users</h2>
-    
+
     <div class="flex flex-col w-full pb-5 font-mono text-xs" id="users">
         <div class="flex flex-row pl-5 pr-10 font-bold">
             <p class="w-1/3 p-2">Github Username</p>
@@ -38,16 +40,17 @@
             <p class="w-24 p-2"> </p>
         </div>
         <div class="flex flex-col pl-5 pr-10 text-gray-100">
-            <form action="/users" method="post" class="m-0">
+            <form action="/admin/users" method="post" class="m-0">
                 <div class="flex flex-row items-center">
-                    <p class="w-1/3 p-2"><input class="block w-full p-2 text-xs bg-transparent border border-white" type="text" name="github_login" required minlength="4" placeholder="@github_handle"></p>
+                    <p class="w-1/3 p-2"><input class="block w-full p-2 text-xs bg-transparent border border-white"
+                            type="text" name="github_login" required minlength="4" placeholder="@github_handle"></p>
                     <p class="w-32 p-2 text-center"><input type="checkbox" id="admin" name="admin" value="true"></p>
                     <p class="w-24 p-2"><button class="underline hover:no-underline">Add</button></p>
                 </div>
             </form>
         </div>
     </div>
-    
+
     <div class="flex flex-col w-full pb-10 font-mono text-xs border-b border-white">
         <div class="flex flex-row pl-5 pr-10 font-bold">
             <p class="w-1/3 p-2">Github Username</p>
@@ -56,10 +59,11 @@
         </div>
         {{#each users}}
         <div class="flex flex-col pl-5 pr-10 text-gray-100 alternate-bg">
-            <form action="/users/{{id}}/delete" method="post" class="m-0">
+            <form action="/admin/users/{{id}}/delete" method="post" class="m-0">
                 <div class="flex flex-row items-center">
                     <p class="w-1/3 p-2">{{github_login}}</p>
-                    <p class="w-32 p-2 text-center"><input action="/users/{{id}}" type="checkbox" {{#if admin}}checked{{/if}}></p>
+                    <p class="w-32 p-2 text-center"><input action="/admin/users/{{id}}" type="checkbox" {{#if
+                            admin}}checked{{/if}}></p>
                     <p class="w-24 p-2"><button class="underline hover:no-underline">Remove</button></p>
                 </div>
             </form>
@@ -70,7 +74,7 @@
     <h2 class="pt-10 mb-5 text-white pl-7 pr-7 font-display font-extralight">Signups</h2>
 
     <div class="flex flex-col w-full pb-10 font-mono text-xs border-b border-white">
-        
+
         <div class="flex flex-row justify-between pl-5 pr-10 font-bold">
             <p class="w-1/5 p-2">Email</p>
             <p class="w-1/5 p-2">Github</p>
@@ -81,17 +85,19 @@
         </div>
         {{#each signups}}
         <div class="flex flex-col pb-1 pl-5 pr-10 text-gray-100 alternate-bg">
-            <form action="/signups/{{id}}/delete" method="post" class="m-0">
+            <form action="/admin/signups/{{id}}/delete" method="post" class="m-0">
                 <div class="flex flex-row items-center justify-between">
                     <p class="w-1/5 p-2 pb-1">{{email_address}}</p>
                     <p class="w-1/5 p-2 pb-1">{{github_login}}</p>
                     <p class="w-24 p-2 pb-1 text-center">{{#if wants_releases}}[✓]{{else}}[ ]{{/if}}</p>
                     <p class="w-24 p-2 pb-1 text-center">{{#if wants_updates}}[✓]{{else}}[ ]{{/if}}</p>
                     <p class="w-24 p-2 pb-1 text-center">{{#if wants_community}}[✓]{{else}}[ ]{{/if}}</p>
-                    <p class="w-24 p-2 pb-1 text-right"><button class="text-lg text-gray-500 hover:text-white">×</button></p>
+                    <p class="w-24 p-2 pb-1 text-right"><button
+                            class="text-lg text-gray-500 hover:text-white">×</button></p>
                 </div>
             </form>
-            <p class="max-w-full p-2 pt-0 overflow-hidden leading-normal text-gray-400 max-h-5 whitespace-nowrap overflow-ellipsis" title="{{about}}">{{about}}</p>
+            <p class="max-w-full p-2 pt-0 overflow-hidden leading-normal text-gray-400 max-h-5 whitespace-nowrap overflow-ellipsis"
+                title="{{about}}">{{about}}</p>
         </div>
         {{/each}}
     </div>