Let non-admin accounts be granted single services, starting with /receipt/
Access was admin or nothing, so letting a friend print receipts meant making them a full admin. Users now carry a list of permissions (User.Permissions, a JSON column), each a key from the registry in services/permissions.go; admins pass every check. The only key so far is `receipt`. GET /auth/validate/:permission answers like /auth/validate-admin (200/403/401, with the same refresh-token fallback, now shared) plus 404 for an unknown key, and reads the user row rather than the token, so a grant or revoke applies on the next request. On 200 it returns the username in X-Auth-User. nginx gets a permission gate beside the admin gate: a location sets $auth_permission and auth_requests /internal/auth/validate. /receipt/ moves onto it, forwarding X-Remote-User to the receipt server. 403 now goes to /no-access rather than back to the login page. The variable must not be given a server-level default: the subrequest re-runs the server rewrite phase and would blank it. The admin panel's Manage Users tab ticks permissions per user (setUserPermissions, permissionTypes). The login page is no longer admin-only in wording or destination: a non-admin lands on /account, which lists the services they can open; /no-access is the same view with a notice. /auth/validate-admin and every other admin-gated service are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
<script setup>
|
||||
/**
|
||||
* Routes `/account` and `/no-access` (both `meta.requiresSignIn`): the landing
|
||||
* page for a signed-in account that is not an admin, listing the gated
|
||||
* services it has been granted (backend/services/permissions.go) as links.
|
||||
*
|
||||
* `/no-access` is where nginx's permission gate sends a signed-in visitor who
|
||||
* lacks the permission (`@auth_forbidden`, with the refused address in
|
||||
* `?path=`). It is this same page with a notice on top, since "what can I
|
||||
* open instead" is the useful answer to "you can't open that".
|
||||
*
|
||||
* The links are plain <a href>, not RouterLinks: every service lives in
|
||||
* another container behind nginx, so it needs a real page load.
|
||||
*/
|
||||
import { ref, computed, onMounted } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import Button from "@/components/input/Button.vue";
|
||||
|
||||
const auth = useAuthStore();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const permissionTypes = ref([]);
|
||||
const loaded = ref(false);
|
||||
const error = ref("");
|
||||
|
||||
const services = computed(() =>
|
||||
permissionTypes.value.filter((p) => auth.can(p.key)),
|
||||
);
|
||||
|
||||
// Only shown on /no-access, and only as text, so an odd value is harmless.
|
||||
const refused = computed(() =>
|
||||
route.name === "no-access" && typeof route.query.path === "string"
|
||||
? route.query.path
|
||||
: "",
|
||||
);
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
permissionTypes.value = await auth.fetchPermissionTypes();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
error.value = err.message || "Couldn't load your services";
|
||||
} finally {
|
||||
loaded.value = true;
|
||||
}
|
||||
});
|
||||
|
||||
// The guard only runs on navigation, so logging out in place would leave the
|
||||
// page up for a signed-out visitor; leave it instead.
|
||||
async function handleLogout() {
|
||||
await auth.logOut();
|
||||
router.push("/admin/login");
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="account-page">
|
||||
<div class="account-card bdr-1">
|
||||
<p v-if="refused" class="account-refused" role="alert">
|
||||
You don't have access to <code>{{ refused }}</code>.
|
||||
</p>
|
||||
|
||||
<h1>Your services</h1>
|
||||
<small>Signed in as <code>{{ auth.user.username }}</code>.</small>
|
||||
|
||||
<p v-if="error" class="text-tertiary" role="alert">{{ error }}</p>
|
||||
<p v-else-if="!loaded" class="text-muted">Loading…</p>
|
||||
<ul v-else-if="services.length" class="account-services">
|
||||
<li v-for="s in services" :key="s.key">
|
||||
<a :href="s.path">{{ s.label }}</a>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="text-muted">Nothing has been shared with you yet.</p>
|
||||
|
||||
<div class="account-actions">
|
||||
<Button v-if="auth.user.admin" @click="router.push('/admin')">
|
||||
Open Admin
|
||||
</Button>
|
||||
<Button @click="handleLogout">Log Out</Button>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.account-page {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 70vh;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.account-card {
|
||||
width: 100%;
|
||||
max-width: 380px;
|
||||
background-color: var(--color-surface);
|
||||
padding: 18px 20px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.account-refused {
|
||||
color: var(--color-tertiary);
|
||||
border: 1px dashed var(--color-tertiary);
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
.account-services {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding-left: 1.2rem;
|
||||
list-style: square;
|
||||
}
|
||||
|
||||
.account-actions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user