π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Fixes with permission system & improvments
Smaug6739bba57a1da44b
diff --git a/backend/services/permissions.service.go b/backend/services/permissions.service.goindex fbebd964..3a586a71 100644--- a/backend/services/permissions.service.go+++ b/backend/services/permissions.service.go@@ -99,8 +99,7 @@ func (s *Service) HasPermission(userId, nodeId types.Snowflake, required int) boLIMIT 1`, nodeId, userId).Scan(&owns)if err == nil && owns == 1 {- // Owner of an ancestor = max permission- return required <= 3+ return true // Owner of an ancestor = max permission}// Otherwise no permissiondiff --git a/backend/utils/permissions.go b/backend/utils/permissions.goindex 6c3d8b25..9dc17bfd 100644--- a/backend/utils/permissions.go+++ b/backend/utils/permissions.go@@ -19,10 +19,10 @@ const ()const (- OWNER = 0READ = 1WRITE = 2ADMIN = 3+ OWNER = 4)// CheckPermission checks if the user has the required permission.@@ -124,9 +124,9 @@ func NodePermission(ctx *gin.Context, node *models.Node, permissionService servireturn connectedUserId, nil}- if permission == OWNER {- return 0, errors.New("unauthorized")- }+ //if permission == OWNER {+ // return 0, errors.New("unauthorized")+ //}// Case 3: User has the required permission on the resourcehasPermission := permissionService.HasPermission(connectedUserId, node.Id, permission)diff --git a/frontend/app/components/DocumentCard.vue b/frontend/app/components/DocumentCard.vueindex 0e5959e3..92795994 100644--- a/frontend/app/components/DocumentCard.vue+++ b/frontend/app/components/DocumentCard.vue@@ -23,10 +23,10 @@d="m612-292 56-56-148-148v-184h-80v216l172 172ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-400Zm0 320q133 0 226.5-93.5T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 133 93.5 226.5T480-160Z"/></svg>- <span>{{ formatDate(parseInt(document.created_timestamp)) }}</span>+ <span>{{ formatDate(document.created_timestamp) }}</span></div><div class="footer-item">- <span>Updated : {{ formatDate(parseInt(document.updated_timestamp)) }}</span>+ <span>Updated : {{ formatDate(document.updated_timestamp) }}</span></div></footer></div>@@ -39,7 +39,7 @@ import DeleteDocumentModal from '~/pages/dashboard/docs/_modals/DeleteDocumentMoconst props = defineProps<{ document: Node }>();const nodesStore = useNodesStore();const category = computed(() => nodesStore.getById(props.document.parent_id || ''));-const user = useUserStore().user;+const user = await useUserStore().fetchPublicUser(props.document.user_id);const deleteDoc = () => useModal().add(new Modal(shallowRef(DeleteDocumentModal), { props: { documentId: props.document.id } }));</script>diff --git a/frontend/app/components/DocumentDotMenu.vue b/frontend/app/components/DocumentDotMenu.vueindex c87f9836..0a7baaf0 100644--- a/frontend/app/components/DocumentDotMenu.vue+++ b/frontend/app/components/DocumentDotMenu.vue@@ -22,10 +22,10 @@</template><script setup lang="ts">-import type { Node, User } from '~/stores';+import type { Node, PublicUser } from '~/stores';const dotMenu = ref();-const props = defineProps<{ document: Node; user?: User }>();+const props = defineProps<{ document: Node; user?: PublicUser }>();const emit = defineEmits<{(e: 'open' | 'close' | 'edit' | 'rename' | 'delete'): void;}>();diff --git a/frontend/app/components/DocumentLine.vue b/frontend/app/components/DocumentLine.vueindex 0fed55d8..9a9fecf8 100644--- a/frontend/app/components/DocumentLine.vue+++ b/frontend/app/components/DocumentLine.vue@@ -19,7 +19,7 @@d="m612-292 56-56-148-148v-184h-80v216l172 172ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-400Zm0 320q133 0 226.5-93.5T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 133 93.5 226.5T480-160Z"/></svg>- <span class="date">{{ formatDate(parseInt(document.updated_timestamp)) }}</span>+ <span class="date">{{ formatDate(document.updated_timestamp) }}</span></footer></div></template>@@ -30,7 +30,7 @@ import DeleteDocumentModal from '~/pages/dashboard/docs/_modals/DeleteDocumentMoconst props = defineProps<{ document: Node }>();const categoriesStore = useNodesStore();const category = computed(() => categoriesStore.getById(props.document.parent_id || ''));-const user = useUserStore().user;+const user = await useUserStore().fetchPublicUser(props.document.user_id);const deleteDoc = () => useModal().add(new Modal(shallowRef(DeleteDocumentModal), { props: { documentId: props.document.id } }));</script>@@ -38,7 +38,9 @@ const deleteDoc = () => useModal().add(new Modal(shallowRef(DeleteDocumentModal).document-line {display: flex;padding: 12px;- border: 1px solid var(--border-color);+ border-top: 1px solid var(--border-color);+ border-left: 1px solid var(--border-color);+ border-right: 1px solid var(--border-color);flex-direction: column;}diff --git a/frontend/app/pages/dashboard/docs/_modals/NodePermissions.vue b/frontend/app/components/Node/NodePermissions.vuesimilarity index 79%rename from frontend/app/pages/dashboard/docs/_modals/NodePermissions.vuerename to frontend/app/components/Node/NodePermissions.vueindex 531ac814..839342b8 100644--- a/frontend/app/pages/dashboard/docs/_modals/NodePermissions.vue+++ b/frontend/app/components/Node/NodePermissions.vue@@ -1,7 +1,20 @@<template>- <div class="modal-content">- <h2 class="title">Manage permissions <tag red>Alpha</tag></h2>-+ <div class="modal-content" v-if="localNode">+ <h2 class="title"><Icon name="manage_access" :big="true" fill="var(--font-color)" /> Manage permissions <tag red>Alpha</tag></h2>++ <label for="accessibility">Accessibility</label>+ <AppRadio v-model="localNode.accessibility" :items="DOCUMENT_ACCESSIBILITIES" placeholder="Accessibility" />+ <!-- Accessibility 3: Public document -->+ <div v-if="localNode.accessibility === 3" class="public-info">+ <p class="info-text">This document will be publicly accessible via a unique URL.</p>+ <p class="info-text">+ Share this link to allow anyone to view the document without needing an account:+ <br />+ <a :href="link" target="_blank" rel="noopener noreferrer" class="public-link"+ ><Icon name="new_tab" :small="true" fill="var(--font-color-light)" /><span>{{ link }}</span></a+ >+ </p>+ </div><!-- Search + add --><form @submit.prevent="addPermission"><label for="user">Search user</label>@@ -24,8 +37,8 @@</form><!-- Current permissions -->- <h3>Current permissions</h3>- <ul class="permissions-list">+ <label for="permissions">Permissions</label>+ <ul id="permissions" class="permissions-list"><li v-for="perm in localNode?.permissions" :key="perm.id" class="permission-item"><div class="user-info-row"><span class="user-meta">@@ -57,6 +70,7 @@ const query = ref('');const user = ref<PublicUser | null>(null);const selectedPermission = ref(1);const localNode = ref<Node | null>(null);+const link = computed(() => `${window.location.origin}/doc/${localNode.value?.id}`);onMounted(async () => {localNode.value = await nodesStore.fetch({ id: props.nodeId });@@ -114,7 +128,7 @@ const removePermission = async (perm: Permission) => {}form {- padding-bottom: 15px;+ padding: 0 4px;display: flex;flex-direction: column;gap: 10px;diff --git a/frontend/app/composables/useNodesTree.ts b/frontend/app/composables/useNodesTree.tsindex 045a9270..020c6017 100644--- a/frontend/app/composables/useNodesTree.ts+++ b/frontend/app/composables/useNodesTree.ts@@ -108,7 +108,7 @@ function useSidebarTree() {let parent_id: string | undefined | null = parentId;while (parent_id) {const parent = structure.value.itemMap.get(parent_id);- if (parent?.data.role === 2) {+ if (parent?.data.role === 2 || parent?.data.role === 1) {category = parent as Item<Node>;break;}diff --git a/frontend/app/pages/dashboard/categories/[id]/index.vue b/frontend/app/pages/dashboard/categories/[id]/index.vueindex 1aa427de..3ef432eb 100644--- a/frontend/app/pages/dashboard/categories/[id]/index.vue+++ b/frontend/app/pages/dashboard/categories/[id]/index.vue@@ -3,7 +3,7 @@<header><h1 style="font-size: 20px">Documents of category <tag class="blue">New</tag></h1><div style="display: flex; align-items: center; gap: 8px">- <NuxtLink @click="openPermissionsModal"><Icon name="users" :big="true" fill="var(--font-color)" /></NuxtLink>+ <NuxtLink @click="openPermissionsModal"><Icon name="manage_access" :big="true" fill="var(--font-color)" /></NuxtLink><NuxtLink :to="`/dashboard/categories/${categoryId}/edit`"><Icon name="settings" :big="true" fill="var(--font-color)" /></NuxtLink><ViewSelection v-model="view" /></div>@@ -23,7 +23,7 @@</template><script setup lang="ts">-import NodePermissions from '../../docs/_modals/NodePermissions.vue';+import NodePermissions from '@/components/Node/NodePermissions.vue';const route = useRoute();const categoryId = route.params.id as string;const nodesStore = useNodesStore();diff --git a/frontend/app/pages/dashboard/docs/_components/DocumentCardHeader.vue b/frontend/app/pages/dashboard/docs/_components/DocumentCardHeader.vueindex d0cdbcef..cfdf6167 100644--- a/frontend/app/pages/dashboard/docs/_components/DocumentCardHeader.vue+++ b/frontend/app/pages/dashboard/docs/_components/DocumentCardHeader.vue@@ -5,10 +5,14 @@<DocumentCardHeaderSkeleton v-if="!doc" /><!-- Real content --><template v-else>- <p v-if="!public" class="category">- <NuxtLink :to="`/dashboard/categories/${category?.id}`">{{ category?.name || 'Uncategorized' }}</NuxtLink>+ <p v-if="!public" class="top-row">+ <span style="display: flex; align-items: center; gap: 12px"+ ><img v-if="user" :src="useAvatar(user)" class="avatar" />+ <span style="color: var(--font-color-light); font-size: 18px">{{ user?.username }}</span>+ </span><DocumentCardHeaderActionRow :doc="doc" class="no-print" /></p>+ <NuxtLink class="category" :to="`/dashboard/categories/${category?.id}`">{{ category?.name || 'Uncategorized' }}</NuxtLink><h1 class="title" :class="{ public: public }">{{ doc?.name }}</h1><p class="description">{{ doc?.description }}</p><div v-if="doc.tags" class="document-tags">@@ -26,11 +30,16 @@import DocumentCardHeaderActionRow from './DocumentCardHeaderActionRow.vue';import DocumentHeaderIllustration from './DocumentHeaderIllustration.vue';import DocumentCardHeaderSkeleton from './DocumentCardHeaderSkeleton.vue';-import type { Node } from '~/stores';+import type { Node, PublicUser } from '~/stores';const preferences = usePreferences();const props = defineProps<{ doc?: Node; public?: boolean }>();const category = computed(() => useSidebarTree().getCategoryFromNode(props.doc?.parent_id)?.data);+const store = useUserStore();+const user = ref<PublicUser | null>(null);+watchEffect(() => {+ if (props.doc) store.fetchPublicUser(props.doc.user_id).then(u => (user.value = u));+});</script><style lang="scss" scoped>@@ -54,10 +63,15 @@ p {flex: 2;padding-right: 10px;- .category,+ .top-row,.title {font-family: Inter;}+ .top-row {+ display: flex;+ align-items: center;+ justify-content: space-between;+ }.public {margin-top: 30px;@@ -65,20 +79,18 @@ p {.title {font-size: 26px;- font-weight: 600;+ font-weight: 550;+ margin: 6px 0;+ padding: 0;color: var(--font-color-dark);}.category {- display: flex;font-size: 20px;font-weight: 500;color: var(--font-color-light);- align-items: baseline;- justify-content: space-between;}}-.document-tags {display: flex;flex-wrap: wrap;@@ -92,16 +104,24 @@ p {}}+.avatar {+ width: 30px;+ height: 30px;+ padding: 0;+ margin: 0;+ border-radius: 50%;+}@media print {.print-style {- padding: 0.4rem 0.2rem;+ padding: 0;background: none;align-items: center;.icon,.description,.document-tags,- .category {+ .top-row,+ .user {display: none;}diff --git a/frontend/app/pages/dashboard/docs/_components/DocumentCardHeaderActionRow.vue b/frontend/app/pages/dashboard/docs/_components/DocumentCardHeaderActionRow.vueindex 4503dc89..e6dff103 100644--- a/frontend/app/pages/dashboard/docs/_components/DocumentCardHeaderActionRow.vue+++ b/frontend/app/pages/dashboard/docs/_components/DocumentCardHeaderActionRow.vue@@ -23,7 +23,7 @@<NuxtLink v-if="nodeStore.hasPermissions(doc, 2)" @click="openEditModal"><Icon name="settings" :big="true" fill="var(--font-color)" /></NuxtLink>- <NuxtLink v-if="nodeStore.hasPermissions(doc, 0)" @click="openPermissionsModal">+ <NuxtLink v-if="nodeStore.hasPermissions(doc, 4)" @click="openPermissionsModal"><Icon name="manage_access" :big="true" fill="var(--font-color)" /></NuxtLink><NuxtLink v-if="nodeStore.hasPermissions(doc, 3)" @click="openDeleteModal">@@ -39,7 +39,7 @@<script setup lang="ts">import DeleteDocumentModal from '../_modals/DeleteDocumentModal.vue';import DocumentMeta from '../_modals/DocumentMeta.vue';-import NodePermissions from '../_modals/NodePermissions.vue';+import NodePermissions from '@/components/Node/NodePermissions.vue';import type { Node } from '~/stores';const nodeStore = useNodesStore();diff --git a/frontend/app/pages/dashboard/docs/index.vue b/frontend/app/pages/dashboard/docs/index.vueindex 60bd2857..b7835b53 100644--- a/frontend/app/pages/dashboard/docs/index.vue+++ b/frontend/app/pages/dashboard/docs/index.vue@@ -1,7 +1,10 @@<template><div class="card-component"><header>- <h1>Documents <tag blue>New</tag></h1>+ <h1 v-if="category">+ <Icon :name="category.icon || category?.icon || 'files'" :class="`category-icon ${getAppColor(category.color || category?.color as number, true)}`" />+ {{ category.name }}+ </h1><ViewSelection v-model="view" /></header><template v-if="documents.length">@@ -19,7 +22,10 @@<script setup lang="ts">import type { Node } from '~/stores';+const { filtered, workspaceId } = useSidebar();+const nodesStore = useNodesStore();const view: Ref<'table' | 'list'> = ref('list');+const category = computed(() => nodesStore.getById(workspaceId.value || ''));const documents = computed(() => {const result: Node[] = [];const getDocs = (items: Item[]) => {@@ -28,12 +34,25 @@ const documents = computed(() => {if (item.childrens) getDocs(item.childrens);}};- getDocs(useSidebarTree().filtered.value);+ getDocs(filtered.value);return result;});</script><style scoped lang="scss">+h1 {+ display: flex;+ align-items: center;+}++.category-icon {+ width: 30px;+ height: 30px;+ padding: 6px;+ border-radius: 6px;+ margin-right: 10px;+}+.line-container {display: flex;flex-direction: column;@@ -42,10 +61,12 @@ const documents = computed(() => {.line-item:first-child {border-top-left-radius: 12px;border-top-right-radius: 12px;+ border-top: 1px solid var(--border-color);}.line-item:last-child {border-bottom-left-radius: 12px;border-bottom-right-radius: 12px;+ border-bottom: 1px solid var(--border-color);}</style>diff --git a/frontend/app/pages/dashboard/docs/new.vue b/frontend/app/pages/dashboard/docs/new.vueindex 22b2407f..e3a0b2e4 100644--- a/frontend/app/pages/dashboard/docs/new.vue+++ b/frontend/app/pages/dashboard/docs/new.vue@@ -5,9 +5,11 @@import MarkdownEditor from '~/components/MarkdownEditor/LazyMarkdownEditor.vue';import type { Node } from '~/stores';+const defaultParent = (useRoute().query.cat as string | undefined) || useSidebar().workspaceId.value || undefined;+const store = useNodesStore();const document = ref<Partial<Node>>({- parent_id: (useRoute().query.cat as string | undefined) || useSidebar().workspaceId.value || undefined,+ parent_id: ['root', 'shared'].includes(defaultParent || '') ? undefined : defaultParent,accessibility: 1,role: 3,});diff --git a/frontend/app/stores/nodes.store.ts b/frontend/app/stores/nodes.store.tsindex f075cc03..ddab6093 100644--- a/frontend/app/stores/nodes.store.ts+++ b/frontend/app/stores/nodes.store.ts@@ -127,14 +127,12 @@ export const useNodesStore = defineStore('nodes', {// Case 3: A parent node has a permission entry for this node (inherited permissions)const userStore = useUserStore();if (node.user_id === userStore.user?.id) return true;- if (level === 0) return false; // level 0 = only owner- const perm = node.permissions.find(p => p.user_id === userStore.user?.id);- if (perm) return perm.permission >= level;- let permission = -1;+ let permission = node.permissions.find(p => p.user_id === userStore.user?.id)?.permission || 0;let currentNode = node;while (permission < level && currentNode.parent_id) {const parentNode = state.nodes.find(n => n.id === currentNode.parent_id);if (!parentNode) break;+ if (parentNode.user_id === userStore.user?.id) return true; // owner of parent nodeconst parentPerm = parentNode.permissions.find(p => p.user_id === userStore.user?.id);if (parentPerm && parentPerm.permission > permission) permission = parentPerm.permission;currentNode = parentNode;