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.

Improve permission system + default permissions

Smaug6739cf1b68b292a0
diff --git a/backend/controllers/nodes.controller.go b/backend/controllers/nodes.controller.go
index 3bb1b6d6..5ccd1d55 100644
--- a/backend/controllers/nodes.controller.go
+++ b/backend/controllers/nodes.controller.go
@@ -105,7 +105,7 @@ func (ctr *Controller) GetNode(c *gin.Context) (int, any) {
if err != nil {
return http.StatusInternalServerError, err
}
- connectedUserId, err := utils.NodePermission(c, node, ctr.app.Services.Permissions, utils.READ)
+ connectedUserId, _, err := utils.NodePermission(c, node, ctr.app.Services.Permissions, utils.READ)
if err != nil {
return http.StatusUnauthorized, err
}
@@ -153,6 +153,7 @@ func (ctr *Controller) CreateNode(c *gin.Context) (int, any) {
Icon: node.Icon,
Color: node.Color,
Accessibility: node.Accessibility,
+ Access: node.Access,
Display: node.Display,
Order: node.Order,
Content: node.Content,
@@ -186,8 +187,8 @@ func (ctr *Controller) UpdateNode(c *gin.Context) (int, any) {
if err != nil {
return http.StatusInternalServerError, err
}
- connectedUserId, err := utils.NodePermission(c, db_node, ctr.app.Services.Permissions, utils.WRITE)
- if err != nil {
+ connectedUserId, userConnectedLevel, err := utils.NodePermission(c, db_node, ctr.app.Services.Permissions, utils.WRITE)
+ if err != nil && db_node.Access < 2 {
return http.StatusUnauthorized, err
}
node := &models.Node{}
@@ -195,10 +196,11 @@ func (ctr *Controller) UpdateNode(c *gin.Context) (int, any) {
return http.StatusBadRequest, err
}
- if db_node.UserId != connectedUserId {
- // If the user is not the owner of the node, they cannot change the owner or the parent
+ if db_node.UserId != connectedUserId && userConnectedLevel < utils.OWNER {
+ // If the user is not owner or admin of the node he cannot change some fields
node.ParentId = db_node.ParentId
node.UserId = db_node.UserId
+ node.Accessibility = db_node.Accessibility
}
node = &models.Node{
Id: nodeId,
@@ -246,7 +248,7 @@ func (ctr *Controller) DeleteNode(c *gin.Context) (int, any) {
if err != nil {
return http.StatusInternalServerError, err
}
- _, err = utils.NodePermission(c, db_node, ctr.app.Services.Permissions, utils.ADMIN)
+ _, _, err = utils.NodePermission(c, db_node, ctr.app.Services.Permissions, utils.ADMIN)
if err != nil {
return http.StatusUnauthorized, err
}
diff --git a/backend/controllers/permissions.controller.go b/backend/controllers/permissions.controller.go
index 1018abdd..b2130e1d 100644
--- a/backend/controllers/permissions.controller.go
+++ b/backend/controllers/permissions.controller.go
@@ -41,7 +41,7 @@ func (ctr *Controller) GetNodePermissions(c *gin.Context) (int, any) {
if err != nil {
return http.StatusInternalServerError, err
}
- _, err = utils.NodePermission(c, node, ctr.app.Services.Permissions, utils.OWNER)
+ _, _, err = utils.NodePermission(c, node, ctr.app.Services.Permissions, utils.OWNER)
if err != nil {
return http.StatusUnauthorized, err
}
@@ -70,7 +70,7 @@ func (ctr *Controller) CreatePermission(c *gin.Context) (int, any) {
if err != nil {
return http.StatusInternalServerError, err
}
- _, err = utils.NodePermission(c, node, ctr.app.Services.Permissions, utils.OWNER)
+ _, _, err = utils.NodePermission(c, node, ctr.app.Services.Permissions, utils.OWNER)
if err != nil {
return http.StatusUnauthorized, err
}
@@ -111,7 +111,7 @@ func (ctr *Controller) UpdatePermission(c *gin.Context) (int, any) {
if err != nil {
return http.StatusInternalServerError, err
}
- _, err = utils.NodePermission(c, node, ctr.app.Services.Permissions, utils.OWNER)
+ _, _, err = utils.NodePermission(c, node, ctr.app.Services.Permissions, utils.OWNER)
if err != nil {
return http.StatusUnauthorized, err
}
@@ -148,7 +148,7 @@ func (ctr *Controller) DeletePermission(c *gin.Context) (int, any) {
if err != nil {
return http.StatusInternalServerError, err
}
- _, err = utils.NodePermission(c, node, ctr.app.Services.Permissions, utils.OWNER)
+ _, _, err = utils.NodePermission(c, node, ctr.app.Services.Permissions, utils.OWNER)
if err != nil {
return http.StatusUnauthorized, err
}
diff --git a/backend/controllers/users.controller.go b/backend/controllers/users.controller.go
index d2adbd27..5a606334 100644
--- a/backend/controllers/users.controller.go
+++ b/backend/controllers/users.controller.go
@@ -54,15 +54,15 @@ func (ctr *Controller) GetPublicUser(c *gin.Context) (int, any) {
if usernameOrEmail == "" {
return http.StatusBadRequest, errors.New("username or email is required")
}
- user, err := ctr.app.Services.User.GetPublicUser(usernameOrEmail)
+ users, err := ctr.app.Services.User.SearchPublicUsers(usernameOrEmail)
if err != nil {
return http.StatusInternalServerError, err
}
- if user == nil {
+ if len(users) == 0 {
return http.StatusNotFound, errors.New("user not found")
}
- return http.StatusOK, user
+ return http.StatusOK, users
}
// Get User by ID
diff --git a/backend/migrations/000010_nodes.up.sql b/backend/migrations/000010_nodes.up.sql
index 29ce1e51..aa0dfd5d 100644
--- a/backend/migrations/000010_nodes.up.sql
+++ b/backend/migrations/000010_nodes.up.sql
@@ -16,6 +16,7 @@ CREATE TABLE `nodes` (
`thumbnail` TEXT NULL,
`theme` VARCHAR(30) NULL,
`accessibility` tinyint(1) NULL,
+ `access` INT NOT NULL DEFAULT 0,
`display` TINYINT NULL,
`order` INT NULL,
`content` LONGTEXT NULL,
diff --git a/backend/models/node.model.go b/backend/models/node.model.go
index 904ce7b4..b72a22cd 100644
--- a/backend/models/node.model.go
+++ b/backend/models/node.model.go
@@ -16,6 +16,7 @@ type Node struct {
Thumbnail *string `json:"thumbnail" form:"thumbnail" binding:"omitempty"`
Theme *string `json:"theme" form:"theme" binding:"omitempty"`
Accessibility *int `json:"accessibility" form:"accessibility" binding:"omitempty"` // 0: Public; 1: Private; 2: Unlisted;
+ Access int `json:"access" form:"access" binding:"omitempty"` // Bit field for access control (0: restricted, 1 view, 2 edit)
Display *int `json:"display" form:"display" binding:"omitempty"`
Order *int `json:"order" form:"order" binding:"omitempty"` // -1 for pinned and -2 for bookmark
Content *string `json:"content" form:"content"`
diff --git a/backend/services/permissions.service.go b/backend/services/permissions.service.go
index 3a586a71..ad8d7ba3 100644
--- a/backend/services/permissions.service.go
+++ b/backend/services/permissions.service.go
@@ -9,7 +9,7 @@ import (
type PermissionService interface {
GetNodePermission(nodeId types.Snowflake) ([]*models.Permission, error)
GetPermission(id types.Snowflake) (*models.Permission, error)
- HasPermission(userId, nodeId types.Snowflake, required int) bool
+ HasPermission(userId, nodeId types.Snowflake, required int) (bool, int)
CreatePermission(permission *models.Permission) error
UpdatePermission(id types.Snowflake, permission int) error
DeletePermission(id types.Snowflake) error
@@ -52,7 +52,7 @@ func (s *Service) GetNodePermission(nodeId types.Snowflake) ([]*models.Permissio
return permissions, nil
}
-func (s *Service) HasPermission(userId, nodeId types.Snowflake, required int) bool {
+func (s *Service) HasPermission(userId, nodeId types.Snowflake, required int) (bool, int) {
var perm int
err := s.db.QueryRow(`
WITH RECURSIVE ancestors AS (
@@ -76,7 +76,7 @@ func (s *Service) HasPermission(userId, nodeId types.Snowflake, required int) bo
// Case 1 : Explicit permission sufficient
if perm >= required {
- return true
+ return true, perm
}
// Case 2 : Not enough permissions β†’ check if owner of an ancestor
@@ -99,11 +99,11 @@ func (s *Service) HasPermission(userId, nodeId types.Snowflake, required int) bo
LIMIT 1
`, nodeId, userId).Scan(&owns)
if err == nil && owns == 1 {
- return true // Owner of an ancestor = max permission
+ return true, 4
}
// Otherwise no permission
- return false
+ return false, 0
}
func (s *Service) CreatePermission(permission *models.Permission) error {
diff --git a/backend/services/user.service.go b/backend/services/user.service.go
index 92698f76..8e3cc673 100644
--- a/backend/services/user.service.go
+++ b/backend/services/user.service.go
@@ -10,7 +10,7 @@ type UserService interface {
GetAllUsers() ([]*models.User, error)
GetUserById(id types.Snowflake) (*models.User, error)
GetUserByUsername(username string) (*models.User, error)
- GetPublicUser(usernameOrEmailOrId string) (*models.User, error)
+ SearchPublicUsers(usernameOrEmailOrId string) ([]*models.User, error)
CheckUsernameExists(username string) bool
CreateUser(user *models.User) (*models.User, error)
UpdateUser(id types.Snowflake, user *models.User) (*models.User, error)
@@ -75,15 +75,22 @@ func (s *Service) GetUserByUsername(username string) (*models.User, error) {
return &user, nil
}
-func (s *Service) GetPublicUser(usernameOrEmailOrId string) (*models.User, error) {
- var user models.User
- err := s.db.QueryRow("SELECT id, username, avatar, created_timestamp, updated_timestamp FROM users WHERE username = ? OR email = ? OR id = ?", usernameOrEmailOrId, usernameOrEmailOrId, usernameOrEmailOrId).Scan(
- &user.Id, &user.Username, &user.Avatar, &user.CreatedTimestamp, &user.UpdatedTimestamp,
- )
+func (s *Service) SearchPublicUsers(usernameOrEmailOrId string) ([]*models.User, error) {
+ var users []*models.User
+ rows, err := s.db.Query("SELECT id, username, avatar, created_timestamp, updated_timestamp FROM users WHERE username = ? OR email = ? OR id = ? LIMIT 10", usernameOrEmailOrId, usernameOrEmailOrId, usernameOrEmailOrId)
if err != nil {
return nil, err
}
- return &user, nil
+ defer rows.Close()
+
+ for rows.Next() {
+ var user models.User
+ if err := rows.Scan(&user.Id, &user.Username, &user.Avatar, &user.CreatedTimestamp, &user.UpdatedTimestamp); err != nil {
+ return nil, err
+ }
+ users = append(users, &user)
+ }
+ return users, nil
}
func (s *Service) GetUserById(id types.Snowflake) (*models.User, error) {
diff --git a/backend/utils/permissions.go b/backend/utils/permissions.go
index 9dc17bfd..4520d113 100644
--- a/backend/utils/permissions.go
+++ b/backend/utils/permissions.go
@@ -99,7 +99,7 @@ func SelfOrPermission(ctx *gin.Context, allowed int) (types.Snowflake, error) {
return 0, errors.New("unauthorized")
}
-func NodePermission(ctx *gin.Context, node *models.Node, permissionService services.PermissionService, permission int) (types.Snowflake, error) {
+func NodePermission(ctx *gin.Context, node *models.Node, permissionService services.PermissionService, permission int) (connectedId types.Snowflake, level int, err error) {
// Check if the connected user has access to the resource
// Case 1: User is the owner of the node (connectedUserId == targetId) => allow
// Case 2: The user is an app administrator => allow
@@ -109,19 +109,19 @@ func NodePermission(ctx *gin.Context, node *models.Node, permissionService servi
// Check user is correctly authenticated
connectedUserId, err := GetUserIdCtx(ctx)
if err != nil {
- return 0, err
+ return 0, 0, err
}
// Case 1: User is the owner of the resource
if connectedUserId == node.UserId {
- return connectedUserId, nil
+ return connectedUserId, OWNER, nil
}
// Case 2: User is an app administrator
role, exists := ctx.Get("user_role")
if !exists {
- return connectedUserId, errors.New("user role not found in context")
+ return connectedUserId, 0, errors.New("user role not found in context")
}
if CheckPermission(role.(int), ADMINISTRATOR) {
- return connectedUserId, nil
+ return connectedUserId, OWNER, nil
}
//if permission == OWNER {
@@ -129,11 +129,11 @@ func NodePermission(ctx *gin.Context, node *models.Node, permissionService servi
//}
// Case 3: User has the required permission on the resource
- hasPermission := permissionService.HasPermission(connectedUserId, node.Id, permission)
+ hasPermission, level := permissionService.HasPermission(connectedUserId, node.Id, permission)
if hasPermission {
- return connectedUserId, nil
+ return connectedUserId, level, nil
}
- return 0, errors.New("unauthorized")
+ return 0, 0, errors.New("unauthorized")
}
diff --git a/frontend/app/components/AppSelect.vue b/frontend/app/components/AppSelect.vue
index ba0e4d63..c6c176a3 100644
--- a/frontend/app/components/AppSelect.vue
+++ b/frontend/app/components/AppSelect.vue
@@ -11,7 +11,7 @@
@click.stop
/>
<div v-else class="app-select-trigger">
- <button @click.stop="toggleDropdown" style="height: 30px">{{ selected?.label || placeholder }}</button>
+ <button style="height: 30px" @click.stop="toggleDropdown">{{ selected?.label || placeholder }}</button>
<svg :class="{ rotated: !open }" xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24" fill="var(--font-color)">
<path d="M480-345 240-585l56-56 184 184 184-184 56 56-240 240Z" />
</svg>
@@ -20,6 +20,7 @@
<ul v-if="open" ref="portalList" class="dropdown" :style="dropdownStyle">
<AppSelectNode v-if="nullable" :node="{ id: '', label: 'β€” Remove selection β€”' }" :level="0" @select="clearSelection" />
<AppSelectNode v-for="item in filteredItems" :key="item.id" :node="item" :level="0" :disabled="disabled" @select="handleSelect" />
+ <slot name="list-footer"></slot>
</ul>
</Teleport>
</div>
@@ -201,7 +202,7 @@ button,
.dropdown {
max-height: 300px;
margin: 0;
- padding: 0 2px;
+ padding: 2px;
border: 1px solid var(--border-color);
border-radius: 6px;
background: var(--bg-color);
diff --git a/frontend/app/components/Node/NodePermissions.vue b/frontend/app/components/Node/NodePermissions.vue
index 839342b8..bddd7bda 100644
--- a/frontend/app/components/Node/NodePermissions.vue
+++ b/frontend/app/components/Node/NodePermissions.vue
@@ -1,11 +1,11 @@
<template>
- <div class="modal-content" v-if="localNode">
+ <div v-if="node" class="modal-content">
<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" />
+ <label for="accessibility">General access</label>
+ <AppRadio v-model="node.accessibility" :items="DOCUMENT_ACCESSIBILITIES" placeholder="Accessibility" />
<!-- Accessibility 3: Public document -->
- <div v-if="localNode.accessibility === 3" class="public-info">
+ <div v-if="node.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:
@@ -16,39 +16,43 @@
</p>
</div>
<!-- Search + add -->
- <form @submit.prevent="addPermission">
+ <form @submit.prevent>
<label for="user">Search user</label>
<input id="user" v-model="query" placeholder="Username or email" />
- <div v-if="user" class="user-card">
+ <div v-for="user in users" :key="user.id" class="user-card">
<div class="user-info-row">
<span class="user-meta">
<img :src="useAvatar(user)" alt="avatar" class="avatar" />
<span>{{ user.username }}</span>
</span>
- <span class="joined"> Joined on {{ new Date(user.created_timestamp).toLocaleDateString() }} </span>
- </div>
-
- <div class="user-actions">
- <AppSelect v-model="selectedPermission" :items="NODE_PERMISSIONS" :searchable="false" size="200px" />
- <button type="submit">Add</button>
+ <div class="user-actions">
+ <AppSelect v-model="selectedPermission" :items="NODE_PERMISSIONS" :searchable="false" size="200px" />
+ <button @click="addPermission(user)">Add</button>
+ </div>
</div>
</div>
+ <p v-if="searchError" class="info-secondary">{{ searchError }}</p>
</form>
<!-- Current permissions -->
- <label for="permissions">Permissions</label>
+ <label for="permissions">Manage permissions</label>
+ <p v-if="!node?.permissions.length" class="info-secondary">No permissions set</p>
<ul id="permissions" class="permissions-list">
- <li v-for="perm in localNode?.permissions" :key="perm.id" class="permission-item">
+ <li v-for="perm in node.permissions" :key="perm.id" class="permission-item">
<div class="user-info-row">
<span class="user-meta">
- <img :src="useAvatar(userById(perm.user_id))" alt="avatar" class="avatar" />
- <span>{{ userById(perm.user_id)?.username }}</span>
+ <img :src="useAvatar(usersStore.getById(perm.user_id))" alt="avatar" class="avatar" />
+ <span>{{ usersStore.getById(perm.user_id)?.username }}</span>
</span>
<div class="user-actions">
- <AppSelect v-model="perm.permission" :items="NODE_PERMISSIONS" :searchable="false" size="200px" @update:model-value="updatePermission(perm)" />
- <button @click="removePermission(perm)">Remove</button>
+ <AppSelect v-model="perm.permission" :items="NODE_PERMISSIONS" :searchable="false" size="250px" @update:model-value="updatePermission(perm)">
+ <template #list-footer>
+ <hr style="margin: 4px 0" />
+ <AppSelectNode :level="0" :node="{ id: `$rm-${perm.id}`, label: 'Remove permission' }" @select="removePermission(perm)" />
+ </template>
+ </AppSelect>
</div>
</div>
</li>
@@ -59,45 +63,48 @@
<script setup lang="ts">
import type { Node, Permission, PublicUser } from '~/stores';
-const props = defineProps<{
- nodeId: string;
-}>();
+const props = defineProps<{ node: Node }>();
+const node = ref<Node>(props.node);
const usersStore = useUserStore();
const nodesStore = useNodesStore();
const query = ref('');
-const user = ref<PublicUser | null>(null);
+const users = ref<PublicUser[]>([]);
const selectedPermission = ref(1);
-const localNode = ref<Node | null>(null);
-const link = computed(() => `${window.location.origin}/doc/${localNode.value?.id}`);
+const link = computed(() => `${window.location.origin}/doc/${node.value?.id}`);
+const searchError = ref<string | null>(null);
-onMounted(async () => {
- localNode.value = await nodesStore.fetch({ id: props.nodeId });
- for (const perm of localNode.value.permissions) {
- perm.user = await usersStore.fetchPublicUser(perm.user_id);
- }
- console.log(localNode.value);
-});
-
-const userById = computed(() => (id: string) => usersStore.getById(id) || undefined);
+for (const perm of node.value.permissions) {
+ usersStore.fetchPublicUser(perm.user_id);
+}
watch(query, async newQuery => {
if (newQuery) {
- user.value = await usersStore.fetchPublicUser(newQuery);
+ usersStore
+ .searchFetch(newQuery)
+ .then(fetchedUsers => (users.value = fetchedUsers))
+ .catch(() => {
+ users.value = [];
+ searchError.value = 'No results found';
+ });
} else {
- user.value = null;
+ users.value = [];
+ searchError.value = null;
}
});
-
-const addPermission = async () => {
- if (!user.value) return;
+watch(
+ node.value,
+ debounce(() => nodesStore.update(node.value), 500),
+);
+const addPermission = async (user: PublicUser) => {
+ if (!user) return;
await nodesStore.addPermission({
- node_id: props.nodeId,
- user_id: user.value.id,
+ node_id: props.node.id,
+ user_id: user.id,
permission: selectedPermission.value,
});
- user.value = null;
+ users.value = [];
query.value = '';
selectedPermission.value = 1;
};
@@ -107,20 +114,20 @@ const updatePermission = async (perm: Permission) => {
};
const removePermission = async (perm: Permission) => {
- if (!localNode.value) return;
- await nodesStore.removePermission(localNode.value.id, perm.user_id);
- localNode.value.permissions = localNode.value.permissions.filter(p => p.id !== perm.id);
+ if (!node.value) return;
+ await nodesStore.removePermission(node.value.id, perm.user_id);
+ node.value.permissions = node.value.permissions.filter(p => p.id !== perm.id);
};
</script>
-<style scoped>
+<style scoped lang="scss">
.modal-content {
display: flex;
flex-direction: column;
gap: 15px;
}
-.title {
+h2 {
font-size: 20px;
display: flex;
align-items: center;
@@ -134,16 +141,10 @@ form {
gap: 10px;
}
-input {
- padding: 6px 10px;
- border-radius: 6px;
- border: 1px solid var(--border-color, #ccc);
-}
-
.user-card {
background-color: var(--bg-ui);
border-radius: 8px;
- padding: 10px;
+ padding: 6px 10px;
display: flex;
flex-direction: column;
gap: 8px;
@@ -159,29 +160,43 @@ input {
display: flex;
align-items: center;
gap: 10px;
+ .avatar {
+ width: 30px;
+ height: 30px;
+ border-radius: 50%;
+ }
}
-
-.avatar {
- width: 30px;
- height: 30px;
- border-radius: 50%;
-}
-
-.joined {
- color: var(--font-color-light);
- font-size: 12px;
-}
-
.user-actions {
display: flex;
align-items: center;
gap: 8px;
}
-select {
- padding: 4px 8px;
- border-radius: 6px;
- border: 1px solid var(--border-color, #ccc);
+.info-secondary {
+ color: var(--font-color-light);
+ font-size: 14px;
+ text-align: center;
+}
+
+.public-info {
+ padding: 0 5px;
+ border-radius: 7px;
+ margin-bottom: 10px;
+
+ .info-text {
+ margin: 5px 0;
+ font-size: 14px;
+ color: var(--font-color-light);
+ }
+
+ .public-link {
+ display: flex;
+ color: var(--primary);
+ align-items: flex-end;
+ gap: 2px;
+ text-decoration: underline;
+ word-break: break-all;
+ }
}
button {
diff --git a/frontend/app/composables/Preferences.ts b/frontend/app/composables/Preferences.ts
index 480ef8b3..b63d7a65 100644
--- a/frontend/app/composables/Preferences.ts
+++ b/frontend/app/composables/Preferences.ts
@@ -5,6 +5,7 @@ export const DEFAULT_PREFERENCES = {
compactMode: false as boolean,
hideSidebarRessources: false as boolean,
normalizeFileIcons: false as boolean,
+ displayUncategorizedRessources: true as boolean,
datatableItemsCount: 10 as number,
view_dock: true as boolean,
primaryColor: -2 as number, // -2 default primary; -1 unset; >= 0 app color index
diff --git a/frontend/app/composables/Sidebar.ts b/frontend/app/composables/Sidebar.ts
index 05996e3d..c1a1f40a 100644
--- a/frontend/app/composables/Sidebar.ts
+++ b/frontend/app/composables/Sidebar.ts
@@ -11,6 +11,7 @@ const filtered = computed(() => {
const found = tree.value.find(i => i.id === workspaceId.value);
if (found) return found.childrens || [];
if (workspaceId.value === 'shared') return tree.value.filter(i => i.data && i.data.shared);
+ if (!usePreferences().get('displayUncategorizedRessources').value) return tree.value.filter(i => i.data && i.data.role != 4); // hide uncategorized
return tree.value;
});
diff --git a/frontend/app/composables/constants.ts b/frontend/app/composables/constants.ts
index ef65aa0a..1b871bf4 100644
--- a/frontend/app/composables/constants.ts
+++ b/frontend/app/composables/constants.ts
@@ -6,7 +6,6 @@ export const DOCUMENT_THEMES = [
export const DOCUMENT_ACCESSIBILITIES: ANode[] = [
{ id: 1, label: 'Private' },
- { id: 2, label: 'Draft' },
{ id: 3, label: 'Published' },
];
diff --git a/frontend/app/pages/dashboard/docs/_components/DocumentCardHeaderActionRow.vue b/frontend/app/pages/dashboard/docs/_components/DocumentCardHeaderActionRow.vue
index e6dff103..08a69cdd 100644
--- a/frontend/app/pages/dashboard/docs/_components/DocumentCardHeaderActionRow.vue
+++ b/frontend/app/pages/dashboard/docs/_components/DocumentCardHeaderActionRow.vue
@@ -48,7 +48,7 @@ const props = defineProps<{ doc: Node }>();
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: { nodeId: props.doc.id }, size: 'small' }));
+const openPermissionsModal = () => useModal().add(new Modal(shallowRef(NodePermissions), { props: { node: props.doc }, size: 'small' }));
function exportMarkdown() {
const blob = new Blob([props.doc.content || ''], { type: 'text/markdown' });
diff --git a/frontend/app/pages/dashboard/settings/_views/preferences.vue b/frontend/app/pages/dashboard/settings/_views/preferences.vue
index 698a21d7..37c7caae 100644
--- a/frontend/app/pages/dashboard/settings/_views/preferences.vue
+++ b/frontend/app/pages/dashboard/settings/_views/preferences.vue
@@ -126,6 +126,12 @@ const options = ref<{ label: string; options: Option[] }[]>([
{ label: 'Enable Compact Mode', type: 'toggle', key: 'compactMode', value: Boolean(preferencesStore.get('compactMode')) },
{ label: 'View dock', type: 'toggle', key: 'view_dock', value: Boolean(preferencesStore.get('view_dock')) },
{ label: 'Normalize file icons', type: 'toggle', key: 'normalizeFileIcons', value: Boolean(preferencesStore.get('normalizeFileIcons')) },
+ {
+ label: 'Display uncategorized ressources',
+ type: 'toggle',
+ key: 'displayUncategorizedRessources',
+ value: Boolean(preferencesStore.get('displayUncategorizedRessources')),
+ },
{ label: 'Hide ressources', type: 'toggle', key: 'hideSidebarRessources', value: Boolean(preferencesStore.get('hideSidebarRessources')) },
{
label: 'Show items in Sidebar',
diff --git a/frontend/app/stores/db_strustures.d.ts b/frontend/app/stores/db_strustures.d.ts
index f50aa84b..bcae3fb8 100644
--- a/frontend/app/stores/db_strustures.d.ts
+++ b/frontend/app/stores/db_strustures.d.ts
@@ -55,7 +55,6 @@ export interface Permission {
node_id: string;
permission: number; // 1: Read; 2: Write; 3: Admin;
created_timestamp: string;
- user?: PublicUser;
}
export interface Node extends DB_Node {
diff --git a/frontend/app/stores/user.store.ts b/frontend/app/stores/user.store.ts
index 45861567..40922f87 100644
--- a/frontend/app/stores/user.store.ts
+++ b/frontend/app/stores/user.store.ts
@@ -3,12 +3,18 @@ import type { User, PublicUser, ConnectionLog } from './db_strustures';
export const useUserStore = defineStore('user', {
state: () => ({
- user: ref<User>(),
- users: [] as PublicUser[],
+ user: undefined as User | undefined,
+ users: {} as Record<string, PublicUser>, // dictionnaire par id
last_connection: null as ConnectionLog | null,
}),
getters: {
- getById: state => (id: string) => state.users.find(u => u.id === id) || null,
+ getById: state => (id: string) => state.users[id],
+ search: state => (query: string) => {
+ const lowerQuery = query.toLowerCase();
+ return Object.values(state.users).filter(
+ u => u.username?.toLowerCase().includes(lowerQuery) || u.email?.toLowerCase().includes(lowerQuery) || u.id === query,
+ );
+ },
},
actions: {
async login(username: string, password: string) {
@@ -37,16 +43,27 @@ export const useUserStore = defineStore('user', {
return this.user;
} else throw responce.message;
},
- async fetchPublicUser(usernameOrEmailOrId: string): Promise<PublicUser> {
- const existingUser = this.users.find(u => u.id === usernameOrEmailOrId);
- if (existingUser) return existingUser;
- const responce = await makeRequest<PublicUser>(`users/public/${usernameOrEmailOrId}`, 'GET', {});
- if (responce.status === 'success') {
- const user = responce.result as PublicUser;
- if (!this.users.find(u => u.id === user.id)) this.users.push(user);
+ async fetchPublicUser(id: string): Promise<PublicUser> {
+ if (this.users[id]) return this.users[id];
+ const response = await makeRequest<PublicUser[]>(`users/public/${id}`, 'GET', {});
+ if (response.status === 'success' && response.result?.length) {
+ const user = response.result[0] as PublicUser;
+ this.users[user.id] = user;
return user;
}
- throw responce.message;
+ throw response.message;
+ },
+
+ async searchFetch(query: string): Promise<PublicUser[]> {
+ const response = await makeRequest<PublicUser[]>(`users/public/${query}`, 'GET', {});
+ if (response.status === 'success') {
+ const users = response.result as PublicUser[];
+ users.forEach(user => {
+ this.users[user.id] = user;
+ });
+ return users;
+ }
+ throw response.message;
},
async fetchById(id: string): Promise<User | undefined> {
const responce = await makeRequest<{ user: User }>(`users/${id}`, 'GET', {});