Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

Setup admin dashboard & fix verfications issues in backend with admin role

Smaug6739789f8966cf85
diff --git a/backend/middlewares/admin.go b/backend/middlewares/admin.go
index 8e5fb509..90f7bd3b 100644
--- a/backend/middlewares/admin.go
+++ b/backend/middlewares/admin.go
@@ -1,6 +1,7 @@
package middlewares
import (
+ "alexandrie/permissions"
"alexandrie/utils"
"github.com/gin-gonic/gin"
@@ -14,7 +15,7 @@ func Admin() gin.HandlerFunc {
c.Abort()
return
}
- if role != 2 {
+ if role != permissions.RoleAdministrator {
c.JSON(401, utils.Error("Unauthorized"))
c.Abort()
return
diff --git a/frontend/app/pages/dashboard/admin/index.vue b/frontend/app/pages/dashboard/admin/index.vue
new file mode 100644
index 00000000..95109708
--- /dev/null
+++ b/frontend/app/pages/dashboard/admin/index.vue
@@ -0,0 +1,6 @@
+<template>
+ <div class="card-component">
+ <h1>Admin dashboard</h1>
+ <AppButton type="primary" @click="useRouter().push('/dashboard/admin/users')">Manage users</AppButton>
+ </div>
+</template>
diff --git a/frontend/app/pages/dashboard/admin/users.vue b/frontend/app/pages/dashboard/admin/users.vue
new file mode 100644
index 00000000..2bb89aa4
--- /dev/null
+++ b/frontend/app/pages/dashboard/admin/users.vue
@@ -0,0 +1,6 @@
+<template>
+ <NuxtPage />
+</template>
+<script setup lang="ts">
+definePageMeta({ breadcrumb: 'Users' });
+</script>
diff --git a/frontend/app/pages/dashboard/admin/users/[id]/documents/[doc_id].vue b/frontend/app/pages/dashboard/admin/users/[id]/documents/[doc_id].vue
new file mode 100644
index 00000000..7ba89e25
--- /dev/null
+++ b/frontend/app/pages/dashboard/admin/users/[id]/documents/[doc_id].vue
@@ -0,0 +1,37 @@
+<template>
+ <div class="card-component" style="height: 100%">
+ <h1>Document view</h1>
+ <div v-if="document" style="display: flex; width: 100%; height: 95%; min-height: 0; flex-direction: column">
+ <h2>{{ document.name }}</h2>
+ <p>{{ document.description }}</p>
+ <div style="display: flex; width: 100%; min-height: 0; flex: 1; gap: 10px; overflow: auto">
+ <textarea v-model="document.content" style="flex: 1"></textarea>
+ <!-- eslint-disable-next-line vue/no-v-html -->
+ <div style="flex: 1" v-html="document.content_compiled" />
+ </div>
+ </div>
+
+ <div v-else>No document found.</div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import type { Node } from '@/stores';
+
+definePageMeta({ breadcrumb: 'Document view' });
+const document = ref<Node | undefined>();
+const route = useRoute();
+const store = useAdminStore();
+
+document.value = await store.fetchUserDocument(route.params.id as string, route.params.doc_id as string);
+</script>
+
+<style scoped lang="scss">
+label {
+ font-weight: bold;
+}
+
+button {
+ margin-top: 1rem;
+}
+</style>
diff --git a/frontend/app/pages/dashboard/admin/users/[id]/documents/index.vue b/frontend/app/pages/dashboard/admin/users/[id]/documents/index.vue
new file mode 100644
index 00000000..b6af3b52
--- /dev/null
+++ b/frontend/app/pages/dashboard/admin/users/[id]/documents/index.vue
@@ -0,0 +1,68 @@
+<template>
+ <div class="card-component">
+ <h2 style="text-align: center">Search documents</h2>
+ <DataTable :headers="headers" :rows="rows">
+ <template #actions="{ cell }">
+ <NuxtLink :to="`/dashboard/admin/users/${route.params.id}/documents/${(cell?.data as Node).id}`"><Icon name="view" /></NuxtLink>
+ </template>
+ </DataTable>
+ </div>
+</template>
+
+<script setup lang="ts">
+import type { Node } from '~/stores';
+definePageMeta({ breadcrumb: 'Documents' });
+
+const documents = ref<Node[]>([]);
+const route = useRoute();
+const store = useAdminStore();
+
+watchEffect(async () => {
+ documents.value = (await store.fetchUserDocuments(route.params.id as string)) || [];
+});
+
+const categoriesStore = useNodesStore();
+const headers = [
+ { label: 'Name', key: 'name' },
+ { label: 'Category', key: 'category' },
+ { label: 'Tags', key: 'tags' },
+ { label: 'Last update', key: 'last_update' },
+ { label: 'Status', key: 'status' },
+ { label: 'Actions', key: 'actions' },
+];
+const rows = computed(() =>
+ documents.value.map(doc => {
+ let badges = '';
+ switch (doc.accessibility) {
+ case 1:
+ badges = '<tag class="green">Document</tag>';
+ break;
+ case 2:
+ badges = '<tag class="teal">Draft</tag>';
+ break;
+ case 3:
+ badges = '<tag class="red">Archived</tag>';
+ }
+ if (doc.parent_id) badges += '<tag class="yellow">Child</tag>';
+ if (documents.value.some(d => d.parent_id === doc.id)) badges += '<tag class="yellow">Parent</tag>';
+ return {
+ name: { content: doc.name, type: 'text' as const },
+ category: { content: categoriesStore.getById(doc.parent_id || '')?.name || '', type: 'text' as const },
+ tags: { content: stringToBadge(doc.tags), type: 'html' as const },
+ last_update: { content: new Date(doc.updated_timestamp).toLocaleDateString(), type: 'text' as const },
+ status: { content: badges, type: 'html' as const },
+ actions: { type: 'slot' as const, data: { id: doc.id } },
+ };
+ }),
+);
+
+function stringToBadge(str?: string): string {
+ if (str?.length)
+ return str
+ .trim()
+ .split(',')
+ .map(t => `<tag class="blue">${t.trim()}</tag>`)
+ .join('');
+ return '';
+}
+</script>
diff --git a/frontend/app/pages/dashboard/admin/users/[id]/index.vue b/frontend/app/pages/dashboard/admin/users/[id]/index.vue
new file mode 100644
index 00000000..5c881f3b
--- /dev/null
+++ b/frontend/app/pages/dashboard/admin/users/[id]/index.vue
@@ -0,0 +1,95 @@
+<template>
+ <div class="card-component">
+ <h2 style="display: flex; align-items: center; justify-content: space-between">
+ User Details <img v-if="user" style="width: 40px; height: 40px; border-radius: 50%" :src="useAvatar(user)" />
+ </h2>
+ <div v-if="user" style="width: 100%">
+ <div class="user-details">
+ <div class="user-detail">
+ <label for="username">Username</label>
+ <input id="username" v-model="user.username" type="text" />
+ </div>
+ <div class="user-detail">
+ <label for="firstname">Firstname</label>
+ <input id="firstname" v-model="user.firstname" type="text" />
+ </div>
+ <div class="user-detail">
+ <label for="lastname">Lastname</label>
+ <input id="lastname" v-model="user.lastname" type="text" />
+ </div>
+ <div class="user-detail">
+ <label for="email">Email</label>
+ <input id="email" v-model="user.email" type="email" />
+ </div>
+ <div class="user-detail">
+ <label for="role">Role</label>
+ <select id="role" v-model="user.role">
+ <option :value="1">User</option>
+ <option :value="2">Admin</option>
+ </select>
+ </div>
+ <div style="display: flex; width: 100%">
+ <div class="user-detail">
+ <label>Created At</label>
+ <div class="value">{{ new Date(user.created_timestamp).toLocaleDateString() }}</div>
+ </div>
+ <div class="user-detail">
+ <label>Updated At</label>
+ <div class="value">{{ new Date(user.updated_timestamp || 0).toLocaleDateString() }}</div>
+ </div>
+ </div>
+ </div>
+
+ <AppButton type="success" @click="saveChanges">Save Changes</AppButton>
+ <AppButton type="primary" @click="useRouter().push(`/dashboard/admin/users/${user.id}/documents`)">View documents</AppButton>
+ </div>
+ <div v-else>No user found.</div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import type { User } from '@/stores';
+
+definePageMeta({ breadcrumb: 'User Details' });
+
+const route = useRoute();
+const user = ref<User | undefined>(undefined);
+const store = useAdminStore();
+watchEffect(async () => {
+ user.value = await store.fetchById(route.params.id as string);
+});
+
+const saveChanges = async () => {
+ if (!user.value) return;
+ store
+ .update(user.value)
+ .then(() => useNotifications().add({ type: 'success', title: 'User updated successfully' }))
+ .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e }));
+};
+</script>
+
+<style scoped lang="scss">
+.user-details {
+ display: flex;
+ width: 100%;
+ align-items: flex-start;
+ flex-direction: column;
+ gap: 1rem;
+}
+
+.user-detail {
+ display: flex;
+ width: 100%;
+ align-items: flex-start;
+ flex-direction: column;
+ gap: 0.5rem;
+}
+
+label {
+ font-weight: bold;
+}
+
+button {
+ margin-top: 1rem;
+}
+</style>
diff --git a/frontend/app/pages/dashboard/admin/users/index.vue b/frontend/app/pages/dashboard/admin/users/index.vue
new file mode 100644
index 00000000..9c03cb86
--- /dev/null
+++ b/frontend/app/pages/dashboard/admin/users/index.vue
@@ -0,0 +1,47 @@
+<template>
+ <div class="card-component">
+ <header>
+ <h1>Users manager</h1>
+ </header>
+ <DataTable v-if="rows?.length" :headers="headers" :rows="rows || []">
+ <template #action="{ cell }">
+ <NuxtLink :to="`/dashboard/admin/users/${(cell?.data as User).id}`"><Icon name="view" /></NuxtLink>
+ </template>
+ </DataTable>
+ <div v-else>No user found.</div>
+ </div>
+</template>
+<script setup lang="ts">
+import { useAdminStore } from '~/stores/admin.store';
+import type { User } from '~/stores';
+
+const adminStore = useAdminStore();
+adminStore.fetchAll();
+
+const headers = [
+ { label: 'Name', key: 'username' },
+ { label: 'Firstname', key: 'firstname' },
+ { label: 'Lastname', key: 'lastname' },
+ { label: 'Email', key: 'email' },
+ { label: 'Role', key: 'role' },
+ { label: 'Created at', key: 'created_at' },
+ { label: 'Action', key: 'action' },
+];
+
+const rows = computed(() =>
+ adminStore.users?.map(u => {
+ return {
+ username: {
+ content: `<img style="border-radius:50%;width:25px;height:25px;" src="${useAvatar(u)}"/>&nbsp;&nbsp;&nbsp;${u.username}`,
+ type: 'html' as const,
+ },
+ firstname: { content: u.firstname, type: 'text' as const },
+ lastname: { content: u.lastname, type: 'text' as const },
+ email: { content: u.email, type: 'text' as const },
+ role: { content: u.role == 2 ? `<tag class="red">Admin</tag>` : `<tag class="blue">User</tag>`, type: 'html' as const },
+ created_at: { content: new Date(u.created_timestamp).toLocaleDateString(), type: 'text' as const },
+ action: { type: 'slot' as const, data: { id: u.id } },
+ };
+ }),
+);
+</script>
diff --git a/frontend/app/stores/admin.store.ts b/frontend/app/stores/admin.store.ts
index 4d3973b0..8c078d62 100644
--- a/frontend/app/stores/admin.store.ts
+++ b/frontend/app/stores/admin.store.ts
@@ -43,9 +43,9 @@ export const useAdminStore = defineStore('admin', {
} else throw responce.message;
},
async fetchUserDocument(userId: string, docId: string): Promise<Node | undefined> {
- const responce = await makeRequest<Node>(`nodes/${userId}/${docId}`, 'GET', {});
+ const responce = await makeRequest<{ node: Node; permissions: [] }>(`nodes/${userId}/${docId}`, 'GET', {});
if (responce.status === 'success') {
- return responce.result;
+ return responce.result?.node;
} else throw responce.message;
},
},