ultisuite-client/lib/drive/drive-share-permissions.ts
R3D347HR4Y 6ec95262af Add OnlyOffice integration and update project configurations
- Updated .env.example to include configuration for OnlyOffice Document Server.
- Modified the workspace configuration to remove the drive-suite path.
- Adjusted TypeScript environment imports for consistency.
- Enhanced Next.js configuration to disable canvas in Webpack.
- Updated package.json to include new dependencies for OnlyOffice and PDF.js.
- Added global styles for OnlyOffice theme integration in the CSS.
- Created new layout and page components for the Drive feature, including public sharing and editing functionalities.
- Updated metadata handling across various layouts to reflect the new app structure.
2026-06-07 15:49:21 +02:00

74 lines
1.9 KiB
TypeScript

/** Nextcloud OCS share permission bits (files & folders). */
export const NC_SHARE_PERM = {
read: 1,
update: 2,
create: 4,
delete: 8,
} as const
export type FolderSharePermissionId =
| "viewContent"
| "addFiles"
| "modifyFiles"
| "deleteFiles"
export type FolderSharePermissions = Record<FolderSharePermissionId, boolean>
export const FOLDER_SHARE_PERMISSION_OPTIONS: {
id: FolderSharePermissionId
label: string
bit: number
}[] = [
{ id: "viewContent", label: "Voir le contenu", bit: NC_SHARE_PERM.read },
{ id: "addFiles", label: "Ajouter des fichiers", bit: NC_SHARE_PERM.create },
{ id: "modifyFiles", label: "Modifier des fichiers", bit: NC_SHARE_PERM.update },
{ id: "deleteFiles", label: "Supprimer des fichiers", bit: NC_SHARE_PERM.delete },
]
export function folderPermissionsFromRole(
role: "viewer" | "editor"
): FolderSharePermissions {
if (role === "editor") {
return {
viewContent: true,
addFiles: true,
modifyFiles: true,
deleteFiles: true,
}
}
return {
viewContent: true,
addFiles: false,
modifyFiles: false,
deleteFiles: false,
}
}
export function folderPermissionsToBitmask(permissions: FolderSharePermissions): number {
let value = 0
for (const option of FOLDER_SHARE_PERMISSION_OPTIONS) {
if (permissions[option.id]) value |= option.bit
}
return value
}
export function sharePermCanRead(perms: number) {
return (perms & NC_SHARE_PERM.read) !== 0
}
export function sharePermCanUpdate(perms: number) {
return (perms & NC_SHARE_PERM.update) !== 0
}
export function sharePermCanCreate(perms: number) {
return (perms & NC_SHARE_PERM.create) !== 0
}
export function sharePermCanDelete(perms: number) {
return (perms & NC_SHARE_PERM.delete) !== 0
}
export function sharePermCanEdit(perms: number) {
return sharePermCanUpdate(perms) || sharePermCanCreate(perms) || sharePermCanDelete(perms)
}