π 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
Allow users to remove shared workspaces
Smaug6739cc7091bedb3b
diff --git a/backend/controllers/permissions.controller.go b/backend/controllers/permissions.controller.goindex e04199a7..fcd4b93b 100644--- a/backend/controllers/permissions.controller.go+++ b/backend/controllers/permissions.controller.go@@ -183,7 +183,7 @@ func (ctr *Controller) DeletePermission(c *gin.Context) (int, any) {return http.StatusInternalServerError, err}allowed, _, err := ctr.authorizer.CanAccessNode(connectedUserId, connectedUserRole, dbNode, permissions.ActionManagePermissions)- if !allowed || err != nil {+ if (!allowed || err != nil) && perm.UserId != connectedUserId {return http.StatusUnauthorized, err}err = ctr.app.Services.Permissions.DeletePermission(permId)diff --git a/frontend/app/components/Node/NodeList.vue b/frontend/app/components/Node/NodeList.vueindex e612e155..ddf3ad58 100644--- a/frontend/app/components/Node/NodeList.vue+++ b/frontend/app/components/Node/NodeList.vue@@ -14,6 +14,9 @@All workspaces</h1><div style="display: flex; align-items: center; gap: 8px">+ <NuxtLink v-if="parent?.shared && parent.user_id != connectedId" @click="openRemoveShareModal"+ ><Icon name="group_off" :big="true" fill="var(--font-color)"+ /></NuxtLink><NuxtLink v-if="parent && nodesStore.hasPermissions(parent, 4)" @click="openPermissionsModal"><Icon name="manage_access" :big="true" fill="var(--font-color)"/></NuxtLink>@@ -44,16 +47,21 @@<script setup lang="ts">import NodePermissions from '@/components/Node/NodePermissions.modal.vue';+import RemoveSharedNode from '@/components/Node/RemoveSharedNode.modal.vue';import type { Node } from '~/stores';const props = defineProps<{ parent?: Node; nodes: Node[]; parentId?: string }>();const nodesStore = useNodesStore();+const connectedId = useUserStore().user?.id;const view: Ref<'table' | 'list'> = ref('list');const openPermissionsModal = () => {if (props.parent) useModal().add(new Modal(shallowRef(NodePermissions), { props: { node: props.parent }, size: 'small' }));};+const openRemoveShareModal = () => {+ if (props.parent) useModal().add(new Modal(shallowRef(RemoveSharedNode), { props: { nodeId: props.parent.id }, size: 'small' }));+};</script><style scoped lang="scss">diff --git a/frontend/app/components/Node/RemoveSharedNode.modal.vue b/frontend/app/components/Node/RemoveSharedNode.modal.vuenew file mode 100644index 00000000..43d04649--- /dev/null+++ b/frontend/app/components/Node/RemoveSharedNode.modal.vue@@ -0,0 +1,35 @@+<template>+ <div class="modal">+ <h3>Remove this document</h3>+ <p>Are you sure you want to remove this document?</p>+ <p style="opacity: 0.7">After this action, you will no longer have access to this document.</p>+ <p v-if="allChildren.length > 0" class="warn">This document has {{ allChildren.length }} child documents. They will be removed too.</p>+ <div class="footer">+ <AppButton type="secondary" @click="emit('close')">Cancel</AppButton>+ <AppButton type="danger" @click="removeDoc">Confirm</AppButton>+ </div>+ </div>+</template>++<script setup lang="ts">+const props = defineProps<{ nodeId: string }>();+const removeDoc = () => {+ useNodesStore()+ .removePermission(props.nodeId, useUserStore().user!.id)+ .then(() => {+ useNotifications().add({ type: 'success', title: 'Document removed' });+ emit('close');+ useRouter().push('/dashboard');+ })+ .catch(e => useNotifications().add({ type: 'error', title: 'Error', message: e }));+};+const emit = defineEmits(['close']);+const allChildren = useSidebarTree().getSubTreeById(props.nodeId);+</script>++<style scoped lang="scss">+.warn {+ color: $red-dark;+ opacity: 0.7;+}+</style>diff --git a/frontend/app/helpers/icons.ts b/frontend/app/helpers/icons.tsindex 705bacfc..f2845e82 100644--- a/frontend/app/helpers/icons.ts+++ b/frontend/app/helpers/icons.ts@@ -31,6 +31,7 @@ const icons = {folder: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" style="fill:var(--yellow)"><path style="fill:var(--yellow)" d="M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h240l80 80h320q33 0 56.5 23.5T880-640H447l-80-80H160v480l96-320h684L837-217q-8 26-29.5 41.5T760-160H160Zm84-80h516l72-240H316l-72 240Zm0 0 72-240-72 240Zm-84-400v-80 80Z"/></svg>`,folder_s: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M160-160q-33 0-56.5-23.5T80-240v-400q0-33 23.5-56.5T160-720h240l80-80h320q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Zm73-280h207v-207L233-440Zm-73-40 160-160H160v160Zm0 120v120h640v-480H520v280q0 33-23.5 56.5T440-360H160Zm280-160Z"/></svg>`,grid: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h133v-133H200v133Zm213 0h134v-133H413v133Zm214 0h133v-133H627v133ZM200-413h133v-134H200v134Zm213 0h134v-134H413v134Zm214 0h133v-134H627v134ZM200-627h133v-133H200v133Zm213 0h134v-133H413v133Zm214 0h133v-133H627v133Z"/></svg>`,+ group_off: `<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M819-28 680-167v7H40v-112q0-34 17.5-62.5T104-378q62-31 126-46.5T360-440q12 0 24.5.5T409-438l-42-42h-7q-66 0-113-47t-47-113v-7L27-820l57-57L876-85l-57 57ZM666-434q51 6 96 20.5t84 35.5q36 20 55 44.5t19 53.5v120h-5L755-320q-9-33-31.5-62.5T666-434Zm-306 74q-56 0-111 13.5T140-306q-9 5-14.5 14t-5.5 20v32h480v-7l-87-87q-38-13-76.5-19.5T360-360Zm202-153q19-28 28.5-60t9.5-67q0-42-14.5-81T544-792q14-5 28-6.5t28-1.5q66 0 113 47t47 113q0 66-49.5 113T595-480l-33-33Zm-58-58-64-64v-5q0-33-23.5-56.5T360-720h-5l-64-64q16-8 33-12t36-4q66 0 113 47t47 113q0 19-4 36t-12 33ZM365-240Zm33-438Z"/></svg>`,help: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M478-240q21 0 35.5-14.5T528-290q0-21-14.5-35.5T478-340q-21 0-35.5 14.5T428-290q0 21 14.5 35.5T478-240Zm-36-154h74q0-33 7.5-52t42.5-52q26-26 41-49.5t15-56.5q0-56-41-86t-97-30q-57 0-92.5 30T342-618l66 26q5-18 22.5-39t53.5-21q32 0 48 17.5t16 38.5q0 20-12 37.5T506-526q-44 39-54 59t-10 73Zm38 314q-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-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>`,image: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path style="fill:var(--green);" d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm40-80h480L570-480 450-320l-90-120-120 160Zm-40 80v-560 560Z"/></svg>`,import: `<svg xmlns="http://www.w3.org/2000/svg"viewBox="0 -960 960 960"><path d="M480-800 243-663l237 137 237-137-237-137ZM120-321v-318q0-22 10.5-40t29.5-29l280-161q10-5 19.5-8t20.5-3q11 0 21 3t19 8l280 161q19 11 29.5 29t10.5 40v119q0 17-11.5 28.5T800-480q-17 0-28.5-11.5T760-520v-76L519-457q-19 11-40 11t-40-11L200-596v274l220 128q9 5 14.5 14t5.5 20q0 23-20 34.5t-40 .5L160-252q-19-11-29.5-29T120-321ZM720 0q-83 0-141.5-58.5T520-200q0-83 58.5-141.5T720-400q83 0 141.5 58.5T920-200q0 83-58.5 141.5T720 0ZM480-491Zm220 335-58-58q-6-6-14-6t-14 6q-6 6-6 14t6 14l78 78q6 6 13 8.5t15 2.5q8 0 15-2.5t13-8.5l78-78q6-6 6-14t-6-14q-6-6-14-6t-14 6l-58 58v-144q0-8-6-14t-14-6q-8 0-14 6t-6 14v144Z"/></svg>`,diff --git a/frontend/app/pages/dashboard/docs/_components/DocumentCardHeaderActionRow.vue b/frontend/app/pages/dashboard/docs/_components/DocumentCardHeaderActionRow.vueindex 4a53baf2..ee045bb1 100644--- a/frontend/app/pages/dashboard/docs/_components/DocumentCardHeaderActionRow.vue+++ b/frontend/app/pages/dashboard/docs/_components/DocumentCardHeaderActionRow.vue@@ -20,6 +20,9 @@/></svg></NuxtLink>+ <NuxtLink v-if="doc.shared" @click="openRemoveShareModal">+ <Icon name="group_off" :big="true" fill="var(--font-color)" />+ </NuxtLink><NuxtLink v-if="nodeStore.hasPermissions(doc, 2)" @click="openEditModal"><Icon name="settings" :big="true" fill="var(--font-color)" /></NuxtLink>@@ -40,6 +43,7 @@import DeleteDocumentModal from '../_modals/DeleteDocumentModal.vue';import DocumentMeta from '@/components/Node/NodeMetadata.modal.vue';import NodePermissions from '@/components/Node/NodePermissions.modal.vue';+import RemoveSharedNode from '@/components/Node/RemoveSharedNode.modal.vue';import type { Node } from '~/stores';const nodeStore = useNodesStore();@@ -49,6 +53,7 @@ const print = () => window.print();const openDeleteModal = () => useModal().add(new Modal(shallowRef(DeleteDocumentModal), { props: { documentId: props.doc.id } }));const openEditModal = () => useModal().add(new Modal(shallowRef(DocumentMeta), { props: { doc: props.doc }, size: 'small' }));const openPermissionsModal = () => useModal().add(new Modal(shallowRef(NodePermissions), { props: { node: props.doc }, size: 'small' }));+const openRemoveShareModal = () => useModal().add(new Modal(shallowRef(RemoveSharedNode), { props: { nodeId: props.doc.id }, size: 'small' }));function exportMarkdown() {const blob = new Blob([props.doc.content || ''], { type: 'text/markdown' });diff --git a/frontend/app/stores/nodes.store.ts b/frontend/app/stores/nodes.store.tsindex 7a51683c..0ace2f37 100644--- a/frontend/app/stores/nodes.store.ts+++ b/frontend/app/stores/nodes.store.ts@@ -42,7 +42,7 @@ export const useNodesStore = defineStore('nodes', {return checkDescendants(node);},getAllChildrens: state => (id: string) => {- const parent = state.nodes.find(d => d.id == id);+ const parent = state.nodes.get(id);if (!parent) return [];const childrens: Node[] = [parent];const getChildrens = (parent: Node) => {@@ -66,7 +66,7 @@ export const useNodesStore = defineStore('nodes', {}});};- const parent = state.nodes.find(d => d.id == id);+ const parent = state.nodes.get(id);if (parent) getChildrens(parent);return childrens;},@@ -118,7 +118,7 @@ export const useNodesStore = defineStore('nodes', {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);+ const parentNode = state.nodes.get(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);@@ -207,7 +207,7 @@ export const useNodesStore = defineStore('nodes', {},async updatePermission(perm: Permission) {console.log(`[store/nodes/permissions] Updating permission for user ${perm.user_id} on node ${perm.node_id}`);- const node = this.nodes.find(n => n.id === perm.node_id);+ const node = this.nodes.get(perm.node_id);if (!node) throw 'Node not found in store, cannot update permission';const request = await makeRequest(`permissions/${perm.id}`, 'PATCH', { permission: perm.permission });if (request.status === 'success') {@@ -217,7 +217,7 @@ export const useNodesStore = defineStore('nodes', {},async removePermission(nodeId: string, userId: string) {console.log(`[store/nodes/permissions] Removing permission for user ${userId} on node ${nodeId}`);- const node = this.nodes.find(n => n.id === nodeId);+ const node = this.nodes.get(nodeId);if (!node) throw 'Node not found in store, cannot remove permission';const perm = node.permissions.find(p => p.user_id === userId);if (!perm) throw 'Permission not found in store, cannot remove permission';