@sync-in/server 1.9.0 → 1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/CHANGELOG.md +13 -8
  2. package/package.json +7 -7
  3. package/server/app.constants.js +3 -3
  4. package/server/app.constants.js.map +1 -1
  5. package/server/app.functions.js +42 -0
  6. package/server/app.functions.js.map +1 -0
  7. package/server/applications/files/services/files-manager.service.js +2 -2
  8. package/server/applications/files/services/files-manager.service.js.map +1 -1
  9. package/server/applications/files/services/files-tasks-manager.service.js +1 -1
  10. package/server/applications/files/services/files-tasks-manager.service.js.map +1 -1
  11. package/server/applications/files/utils/send-file.js +18 -9
  12. package/server/applications/files/utils/send-file.js.map +1 -1
  13. package/server/applications/files/utils/url-file.js +6 -6
  14. package/server/applications/files/utils/url-file.js.map +1 -1
  15. package/server/applications/links/services/links-manager.service.js +1 -1
  16. package/server/applications/links/services/links-manager.service.js.map +1 -1
  17. package/server/applications/shares/interfaces/share-props.interface.js.map +1 -1
  18. package/server/applications/shares/services/shares-manager.service.js +6 -4
  19. package/server/applications/shares/services/shares-manager.service.js.map +1 -1
  20. package/server/applications/spaces/services/spaces-manager.service.js +15 -12
  21. package/server/applications/spaces/services/spaces-manager.service.js.map +1 -1
  22. package/server/applications/users/services/admin-users-manager.service.js +4 -0
  23. package/server/applications/users/services/admin-users-manager.service.js.map +1 -1
  24. package/server/applications/users/users.controller.js +4 -1
  25. package/server/applications/users/users.controller.js.map +1 -1
  26. package/static/assets/pdfjs/build/pdf.mjs +35 -20
  27. package/static/assets/pdfjs/build/pdf.mjs.map +1 -1
  28. package/static/assets/pdfjs/build/pdf.sandbox.mjs +2 -2
  29. package/static/assets/pdfjs/build/pdf.worker.mjs +1488 -52
  30. package/static/assets/pdfjs/build/pdf.worker.mjs.map +1 -1
  31. package/static/assets/pdfjs/version +1 -1
  32. package/static/assets/pdfjs/web/locale/be/viewer.ftl +2 -12
  33. package/static/assets/pdfjs/web/locale/bg/viewer.ftl +4 -0
  34. package/static/assets/pdfjs/web/locale/bs/viewer.ftl +0 -15
  35. package/static/assets/pdfjs/web/locale/ca/viewer.ftl +0 -4
  36. package/static/assets/pdfjs/web/locale/cs/viewer.ftl +4 -14
  37. package/static/assets/pdfjs/web/locale/cy/viewer.ftl +2 -12
  38. package/static/assets/pdfjs/web/locale/da/viewer.ftl +2 -12
  39. package/static/assets/pdfjs/web/locale/de/viewer.ftl +0 -12
  40. package/static/assets/pdfjs/web/locale/dsb/viewer.ftl +0 -12
  41. package/static/assets/pdfjs/web/locale/el/viewer.ftl +2 -12
  42. package/static/assets/pdfjs/web/locale/en-CA/viewer.ftl +0 -12
  43. package/static/assets/pdfjs/web/locale/en-GB/viewer.ftl +0 -12
  44. package/static/assets/pdfjs/web/locale/eo/viewer.ftl +2 -12
  45. package/static/assets/pdfjs/web/locale/es-AR/viewer.ftl +0 -12
  46. package/static/assets/pdfjs/web/locale/es-CL/viewer.ftl +2 -12
  47. package/static/assets/pdfjs/web/locale/es-ES/viewer.ftl +2 -12
  48. package/static/assets/pdfjs/web/locale/es-MX/viewer.ftl +0 -12
  49. package/static/assets/pdfjs/web/locale/eu/viewer.ftl +0 -12
  50. package/static/assets/pdfjs/web/locale/fi/viewer.ftl +0 -12
  51. package/static/assets/pdfjs/web/locale/fr/viewer.ftl +0 -12
  52. package/static/assets/pdfjs/web/locale/fur/viewer.ftl +0 -12
  53. package/static/assets/pdfjs/web/locale/fy-NL/viewer.ftl +0 -12
  54. package/static/assets/pdfjs/web/locale/gn/viewer.ftl +2 -12
  55. package/static/assets/pdfjs/web/locale/he/viewer.ftl +0 -12
  56. package/static/assets/pdfjs/web/locale/hsb/viewer.ftl +0 -12
  57. package/static/assets/pdfjs/web/locale/hu/viewer.ftl +0 -12
  58. package/static/assets/pdfjs/web/locale/hy-AM/viewer.ftl +0 -15
  59. package/static/assets/pdfjs/web/locale/ia/viewer.ftl +0 -12
  60. package/static/assets/pdfjs/web/locale/id/viewer.ftl +0 -15
  61. package/static/assets/pdfjs/web/locale/is/viewer.ftl +0 -15
  62. package/static/assets/pdfjs/web/locale/it/viewer.ftl +2 -14
  63. package/static/assets/pdfjs/web/locale/ja/viewer.ftl +7 -2
  64. package/static/assets/pdfjs/web/locale/ka/viewer.ftl +0 -12
  65. package/static/assets/pdfjs/web/locale/kab/viewer.ftl +0 -12
  66. package/static/assets/pdfjs/web/locale/kk/viewer.ftl +3 -12
  67. package/static/assets/pdfjs/web/locale/ko/viewer.ftl +0 -12
  68. package/static/assets/pdfjs/web/locale/nb-NO/viewer.ftl +2 -12
  69. package/static/assets/pdfjs/web/locale/nl/viewer.ftl +0 -12
  70. package/static/assets/pdfjs/web/locale/nn-NO/viewer.ftl +0 -12
  71. package/static/assets/pdfjs/web/locale/pa-IN/viewer.ftl +4 -12
  72. package/static/assets/pdfjs/web/locale/pl/viewer.ftl +2 -12
  73. package/static/assets/pdfjs/web/locale/pt-BR/viewer.ftl +2 -12
  74. package/static/assets/pdfjs/web/locale/rm/viewer.ftl +0 -12
  75. package/static/assets/pdfjs/web/locale/ro/viewer.ftl +2 -14
  76. package/static/assets/pdfjs/web/locale/ru/viewer.ftl +0 -12
  77. package/static/assets/pdfjs/web/locale/sc/viewer.ftl +0 -1
  78. package/static/assets/pdfjs/web/locale/sk/viewer.ftl +0 -12
  79. package/static/assets/pdfjs/web/locale/sl/viewer.ftl +2 -12
  80. package/static/assets/pdfjs/web/locale/sq/viewer.ftl +2 -12
  81. package/static/assets/pdfjs/web/locale/sv-SE/viewer.ftl +0 -12
  82. package/static/assets/pdfjs/web/locale/tg/viewer.ftl +2 -12
  83. package/static/assets/pdfjs/web/locale/th/viewer.ftl +0 -12
  84. package/static/assets/pdfjs/web/locale/tr/viewer.ftl +2 -12
  85. package/static/assets/pdfjs/web/locale/vi/viewer.ftl +0 -12
  86. package/static/assets/pdfjs/web/locale/zh-CN/viewer.ftl +2 -12
  87. package/static/assets/pdfjs/web/locale/zh-TW/viewer.ftl +0 -12
  88. package/static/assets/pdfjs/web/viewer.css +53 -41
  89. package/static/assets/pdfjs/web/viewer.html +493 -132
  90. package/static/assets/pdfjs/web/viewer.mjs +225 -150
  91. package/static/assets/pdfjs/web/viewer.mjs.map +1 -1
  92. package/static/{chunk-LYZGJZNP.js → chunk-25PWAXTJ.js} +1 -1
  93. package/static/{chunk-EKEGRXCV.js → chunk-27XEAHMV.js} +1 -1
  94. package/static/{chunk-YMAN4LIU.js → chunk-2CAAJBRO.js} +1 -1
  95. package/static/{chunk-MNNCSSHN.js → chunk-2LHHXDD5.js} +1 -1
  96. package/static/{chunk-YCTCESL4.js → chunk-2XY4PMI5.js} +1 -1
  97. package/static/{chunk-ERDZ7IVF.js → chunk-33WFRCUP.js} +1 -1
  98. package/static/chunk-3LVFDMTN.js +1 -0
  99. package/static/{chunk-4FJUCMEG.js → chunk-4DF2SQD4.js} +1 -1
  100. package/static/{chunk-Q556XB3S.js → chunk-4EUHBTWV.js} +1 -1
  101. package/static/{chunk-AADK5D2H.js → chunk-4KXJ6C4N.js} +1 -1
  102. package/static/{chunk-BHZEPHRI.js → chunk-4OV3SAUS.js} +1 -1
  103. package/static/{chunk-T74SMT7I.js → chunk-5HCVWZMA.js} +1 -1
  104. package/static/{chunk-ZCOWBVOT.js → chunk-5HYSNQR4.js} +1 -1
  105. package/static/{chunk-XOTKK2NJ.js → chunk-5NHB7SV3.js} +1 -1
  106. package/static/chunk-6VJI4X2A.js +1 -0
  107. package/static/{chunk-XCLK7NJL.js → chunk-7H5O4BLV.js} +1 -1
  108. package/static/{chunk-ACUF7IKP.js → chunk-7NI353LS.js} +1 -1
  109. package/static/{chunk-Y44XDRM5.js → chunk-A6J6SOM6.js} +1 -1
  110. package/static/{chunk-XOF4UW3S.js → chunk-A7DSX7VP.js} +1 -1
  111. package/static/chunk-A7R246NW.js +1 -0
  112. package/static/{chunk-EL6QL4TP.js → chunk-ASBPYTLT.js} +1 -1
  113. package/static/chunk-BJARRIS6.js +562 -0
  114. package/static/{chunk-RT3K6DZR.js → chunk-CAZSNVMS.js} +1 -1
  115. package/static/{chunk-EIYRBM4J.js → chunk-CURVLK7L.js} +1 -1
  116. package/static/{chunk-7CFSJ4BO.js → chunk-DDRGLHOP.js} +1 -1
  117. package/static/{chunk-2XPHUNYN.js → chunk-FLPZB3OX.js} +1 -1
  118. package/static/{chunk-23UUFZSR.js → chunk-FRBTL2ER.js} +1 -1
  119. package/static/{chunk-MRF3CNLZ.js → chunk-FXM7XXWA.js} +1 -1
  120. package/static/{chunk-7CKHC72R.js → chunk-GDPJRUVU.js} +1 -1
  121. package/static/{chunk-QMHUIHSR.js → chunk-GENTF6JM.js} +1 -1
  122. package/static/{chunk-XX7JXKA6.js → chunk-H4RLHI3Y.js} +1 -1
  123. package/static/{chunk-KNZ3AQPR.js → chunk-HE6EDXWI.js} +1 -1
  124. package/static/{chunk-LXQGVNU2.js → chunk-IUJ4IK26.js} +1 -1
  125. package/static/{chunk-MVZJSG5R.js → chunk-JEVBUJQ4.js} +1 -1
  126. package/static/{chunk-2FOWUJQF.js → chunk-K3MOXDU5.js} +1 -1
  127. package/static/{chunk-PG54TWBO.js → chunk-KBWK65KM.js} +1 -1
  128. package/static/{chunk-5HNQLBSW.js → chunk-L3PDWJZ3.js} +2 -2
  129. package/static/{chunk-KDEEERWZ.js → chunk-LBXOAKBD.js} +1 -1
  130. package/static/{chunk-Y5RLD72B.js → chunk-LFAQLJZK.js} +1 -1
  131. package/static/{chunk-M4XL3JN5.js → chunk-MBFMTBVJ.js} +1 -1
  132. package/static/{chunk-FTSIPHMG.js → chunk-MZBO5PAR.js} +1 -1
  133. package/static/{chunk-DJDRX53V.js → chunk-NFIES7BC.js} +1 -1
  134. package/static/{chunk-24Q7OUU2.js → chunk-NK2NMAJI.js} +1 -1
  135. package/static/{chunk-BYWSTP3P.js → chunk-O7UXVNR2.js} +1 -1
  136. package/static/{chunk-3IISSX63.js → chunk-PKU4IIIR.js} +1 -1
  137. package/static/{chunk-NN4ONTOT.js → chunk-QUSS6SUC.js} +1 -1
  138. package/static/{chunk-Y2I36A4K.js → chunk-R6VB3INJ.js} +1 -1
  139. package/static/{chunk-CCGGCHGN.js → chunk-RJOHDAPM.js} +1 -1
  140. package/static/{chunk-N3P6P6GW.js → chunk-S6YKBWJE.js} +1 -1
  141. package/static/{chunk-AZ5TF5Y3.js → chunk-SDR3UG2F.js} +1 -1
  142. package/static/{chunk-C3AAEQKW.js → chunk-TGHBDJZA.js} +1 -1
  143. package/static/{chunk-HNMGPG72.js → chunk-TVJQXN73.js} +1 -1
  144. package/static/{chunk-KHRF67SG.js → chunk-U75PLYIJ.js} +1 -1
  145. package/static/chunk-UUX3M6DC.js +1 -0
  146. package/static/{chunk-S6EVLDHA.js → chunk-VJ2HWQRJ.js} +2 -2
  147. package/static/{chunk-QNFNXDSX.js → chunk-VO4WVT6K.js} +1 -1
  148. package/static/{chunk-5XUIPWOH.js → chunk-W72JYHOH.js} +1 -1
  149. package/static/{chunk-OJCAIKUK.js → chunk-WJYVS27M.js} +1 -1
  150. package/static/{chunk-HKRGIRKB.js → chunk-XAIOGRBO.js} +1 -1
  151. package/static/{chunk-BQZWSZNN.js → chunk-XHQEF2IX.js} +1 -1
  152. package/static/{chunk-RX3YQ67K.js → chunk-XXYMVRSH.js} +1 -1
  153. package/static/{chunk-HHWXIK2M.js → chunk-YTBSB2GE.js} +1 -1
  154. package/static/{chunk-LJSVNPPQ.js → chunk-YXWF2DGF.js} +1 -1
  155. package/static/{chunk-JMYAD7E2.js → chunk-Z6RJZIDG.js} +1 -1
  156. package/static/{chunk-F7TXTNZC.js → chunk-ZC5ZDCDC.js} +1 -1
  157. package/static/{chunk-EDJAISWO.js → chunk-ZERBTNFW.js} +8 -8
  158. package/static/{chunk-MRMSMTWD.js → chunk-ZPI7RQ2S.js} +1 -1
  159. package/static/{chunk-NOPACN4F.js → chunk-ZRBLCAOK.js} +1 -1
  160. package/static/index.html +2 -2
  161. package/static/{main-3PLRDZTO.js → main-FE6GWZXU.js} +4 -4
  162. package/static/{styles-Q4OZOSSK.css → styles-S5HVK4H5.css} +1 -1
  163. package/static/chunk-H6WOTGQ5.js +0 -1
  164. package/static/chunk-HC7F57NA.js +0 -1
  165. package/static/chunk-IOIBQGHN.js +0 -562
  166. package/static/chunk-J6YSFHLZ.js +0 -1
  167. package/static/chunk-QVFPHTOH.js +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../backend/src/applications/spaces/services/spaces-manager.service.ts"],"sourcesContent":["/*\n * Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com>\n * This file is part of Sync-in | The open source file sync and share solution\n * See the LICENSE file for licensing details\n */\n\nimport { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common'\nimport { eq, isNotNull, lte } from 'drizzle-orm'\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\nimport { ACTION } from '../../../common/constants'\nimport { convertDiffUpdate, diffCollection, differencePermissions } from '../../../common/functions'\nimport type { Entries, StorageQuota } from '../../../common/interfaces'\nimport { createSlug, regExpNumberSuffix } from '../../../common/shared'\nimport { configuration } from '../../../configuration/config.environment'\nimport { ContextManager } from '../../../infrastructure/context/services/context-manager.service'\nimport { FileError } from '../../files/models/file-error'\nimport { dirListFileNames, dirSize, getProps, isPathExists, moveFiles, removeFiles } from '../../files/utils/files'\nimport { LINK_TYPE } from '../../links/constants/links'\nimport { NOTIFICATION_APP, NOTIFICATION_APP_EVENT } from '../../notifications/constants/notifications'\nimport { NotificationContent } from '../../notifications/interfaces/notification-properties.interface'\nimport { NotificationsManager } from '../../notifications/services/notifications-manager.service'\nimport { CreateOrUpdateShareDto } from '../../shares/dto/create-or-update-share.dto'\nimport type { ShareLink } from '../../shares/interfaces/share-link.interface'\nimport type { ShareProps } from '../../shares/interfaces/share-props.interface'\nimport type { ShareChild } from '../../shares/models/share-child.model'\nimport { SharesManager } from '../../shares/services/shares-manager.service'\nimport { MEMBER_TYPE } from '../../users/constants/member'\nimport { USER_ROLE } from '../../users/constants/user'\nimport { UserModel } from '../../users/models/user.model'\nimport type { User } from '../../users/schemas/user.interface'\nimport { users } from '../../users/schemas/users.schema'\nimport { UsersQueries } from '../../users/services/users-queries.service'\nimport { CACHE_QUOTA_SPACE_PREFIX, CACHE_QUOTA_TTL, CACHE_QUOTA_USER_PREFIX } from '../constants/cache'\nimport {\n SPACE_ALIAS,\n SPACE_ALL_OPERATIONS,\n SPACE_MAX_DISABLED_DAYS,\n SPACE_OPERATION,\n SPACE_PERSONAL,\n SPACE_REPOSITORY,\n SPACE_ROLE,\n SPACE_SHARES\n} from '../constants/spaces'\nimport { CreateOrUpdateSpaceDto, SpaceMemberDto } from '../dto/create-or-update-space.dto'\nimport { DeleteSpaceDto } from '../dto/delete-space.dto'\nimport { SearchSpaceDto } from '../dto/search-space.dto'\nimport { SpaceTrash } from '../interfaces/space-trash.interface'\nimport { SpaceEnv } from '../models/space-env.model'\nimport { SpaceProps } from '../models/space-props.model'\nimport type { SpaceRootProps } from '../models/space-root-props.model'\nimport { SpaceModel } from '../models/space.model'\nimport type { SpaceRoot } from '../schemas/space-root.interface'\nimport type { Space } from '../schemas/space.interface'\nimport { spaces } from '../schemas/spaces.schema'\nimport { quotaKeyFromSpace } from '../utils/paths'\nimport { haveSpacePermission } from '../utils/permissions'\nimport { SpacesQueries } from './spaces-queries.service'\n\n@Injectable()\nexport class SpacesManager {\n private readonly logger = new Logger(SpacesManager.name)\n\n constructor(\n private readonly contextManager: ContextManager,\n private readonly spacesQueries: SpacesQueries,\n private readonly usersQueries: UsersQueries,\n private readonly sharesManager: SharesManager,\n private readonly notificationsManager: NotificationsManager\n ) {}\n\n listSpaces(userId: number): Promise<Partial<SpaceProps>[]> {\n return this.spacesQueries.spaces(userId)\n }\n\n spacesWithDetails(userId: number): Promise<SpaceProps[]> {\n return this.spacesQueries.spacesWithDetails(userId)\n }\n\n uniqueRootName(name: string, names: string[]) {\n if (names.find((fName: string) => name.toLowerCase() === fName.toLowerCase())) {\n const nameExtension = path.extname(name)\n const nameWithoutExtension = path.basename(name, nameExtension)\n const originalName = nameWithoutExtension.replace(regExpNumberSuffix, '')\n let count = 1\n let newName = `${originalName}-${count}${nameExtension}`\n while (names.find((fName: string) => newName.toLowerCase() === fName.toLowerCase())) {\n count += 1\n newName = `${originalName}-${count}${nameExtension}`\n }\n return newName\n }\n return null\n }\n\n async spaceEnv(user: UserModel, urlSegments: string[], skipEndpointProtection = false): Promise<SpaceEnv> {\n /* SpaceEnv builder */\n let [repository, spaceAlias, rootAlias, ...paths] = urlSegments\n\n if (\n !repository ||\n (!spaceAlias && repository !== SPACE_REPOSITORY.SHARES) ||\n Object.values(SPACE_REPOSITORY).indexOf(repository as SPACE_REPOSITORY) === -1\n ) {\n throw new Error(`Space path is not valid : ${urlSegments}`)\n }\n\n let space: SpaceEnv\n if (spaceAlias === SPACE_ALIAS.PERSONAL) {\n /* Personal Space (static) */\n if (rootAlias) {\n // there is no root in a personal space\n paths.unshift(rootAlias)\n rootAlias = null\n }\n space = new SpaceEnv(SPACE_PERSONAL, rootAlias, false)\n } else if (repository === SPACE_REPOSITORY.SHARES) {\n if (spaceAlias) {\n /* Share */\n const spacePermissions: Partial<SpaceEnv> = await this.sharesManager.permissions(user, spaceAlias)\n if (spacePermissions) {\n space = new SpaceEnv(spacePermissions, null, false)\n }\n } else {\n /* Shares List (static) */\n space = new SpaceEnv(SPACE_SHARES, null, false)\n }\n } else {\n /* Space */\n if (repository === SPACE_REPOSITORY.TRASH && rootAlias) {\n // there is no root in a trash space\n paths.unshift(rootAlias)\n rootAlias = null\n }\n const spacePermissions: Partial<SpaceEnv> = await this.spacesQueries.permissions(user.id, spaceAlias, rootAlias)\n if (spacePermissions) {\n space = new SpaceEnv(spacePermissions, rootAlias || '')\n }\n }\n if (!space) return null\n try {\n space.setup(user, repository as SPACE_REPOSITORY, rootAlias, paths, urlSegments, skipEndpointProtection)\n await this.setQuotaExceeded(user, space)\n return space\n } catch (e) {\n this.logger.warn(`${this.spaceEnv.name} - *${space.alias}* : ${e}`)\n throw new HttpException(e.message, e instanceof FileError ? e.httpCode : HttpStatus.BAD_REQUEST)\n }\n }\n\n async searchSpaces(userId: number, searchSpaceDto: SearchSpaceDto): Promise<SpaceProps[]> {\n const sps: SpaceProps[] = []\n for (const s of await this.spacesQueries.spaces(userId, true)) {\n if (searchSpaceDto.shareInsidePermission && !haveSpacePermission(s, SPACE_OPERATION.SHARE_INSIDE)) {\n continue\n }\n if (!searchSpaceDto.search || `${s.name} ${s.alias} ${s.description || ''}`.toLowerCase().indexOf(searchSpaceDto.search) > -1) {\n sps.push(s)\n }\n if (sps.length >= searchSpaceDto.limit) {\n break\n }\n }\n return sps\n }\n\n async listSpacesWithPermissions(user: UserModel): Promise<SpaceEnv[]> {\n return Promise.all(\n (await this.spacesQueries.spaces(user.id, true)).map(async (s) => {\n const space = new SpaceEnv(s)\n await this.setQuotaExceeded(user, space)\n return space\n })\n )\n }\n\n async listTrashes(user: UserModel): Promise<SpaceTrash[]> {\n const trashes: SpaceTrash[] = []\n // todo: store 'Personal files' as const somewhere (used in frontend too)\n const personalTrash: SpaceTrash = { id: 0, name: 'Personal files', alias: SPACE_ALIAS.PERSONAL, nb: 0, mtime: 0, ctime: 0 }\n for (const space of [...(await this.listSpaces(user.id)), personalTrash] as SpaceTrash[]) {\n const rPath = space.alias === SPACE_ALIAS.PERSONAL ? user.trashPath : SpaceModel.getTrashPath(space.alias)\n try {\n space.nb = (await fs.readdir(rPath)).filter((f) => configuration.applications.files.showHiddenFiles || f[0] !== '.').length\n if (space.nb) {\n const stats = await fs.stat(rPath)\n space.mtime = stats.mtime.getTime()\n space.ctime = stats.birthtime.getTime()\n trashes.push(space)\n }\n } catch (e) {\n this.logger.error(`${this.listTrashes.name} - ${e}`)\n }\n }\n return trashes\n }\n\n async getSpace(user: UserModel, spaceId: number): Promise<SpaceProps> {\n const space: SpaceProps = await this.userCanAccessSpace(user.id, spaceId, true)\n if (space.roots?.length && !user.isAdmin) {\n // remove external path if the current user is not an administrator\n for (const root of space.roots) {\n root.externalPath = null\n }\n }\n return space\n }\n\n async createSpace(user: UserModel, createOrUpdateSpaceDto: CreateOrUpdateSpaceDto): Promise<SpaceProps> {\n /* only users with admin space role can create a space */\n // create space\n const space: SpaceProps = new SpaceProps({\n name: createOrUpdateSpaceDto.name,\n alias: await this.uniqueSpaceAlias(createOrUpdateSpaceDto.name, true),\n description: createOrUpdateSpaceDto.description,\n enabled: createOrUpdateSpaceDto.enabled,\n storageQuota: createOrUpdateSpaceDto.storageQuota,\n storageIndexing: createOrUpdateSpaceDto.storageIndexing,\n disabledAt: createOrUpdateSpaceDto.enabled ? null : new Date()\n })\n try {\n space.id = await this.spacesQueries.createSpace(space)\n } catch (e) {\n this.logger.error(`${this.createSpace.name} - unable to create space *${space.alias}* : ${e}`)\n throw new HttpException('Unable to create space', e)\n }\n // create space paths\n await SpaceModel.makePaths(space.alias)\n // add roots\n await this.updateRoots(user, space, space.roots, createOrUpdateSpaceDto.roots, [], [])\n // add members\n await this.updateMembers(user, space, createOrUpdateSpaceDto.members.concat(createOrUpdateSpaceDto.managers))\n // create links after members, user must be a space manager to create links\n await this.sharesManager.createOrUpdateLinksAsMembers(user, space, LINK_TYPE.SPACE, createOrUpdateSpaceDto.links)\n return this.spacesQueries.getSpaceAsManager(user.id, space.id)\n }\n\n async updateSpace(user: UserModel, spaceId: number, createOrUpdateSpaceDto: CreateOrUpdateSpaceDto): Promise<SpaceProps> {\n /* only managers of the space can update it */\n const space: SpaceProps = await this.userCanAccessSpace(user.id, spaceId, true)\n // check and update space info\n const spaceDiffProps: Partial<SpaceProps> = { modifiedAt: new Date() }\n const props: (keyof CreateOrUpdateSpaceDto)[] = ['name', 'description', 'enabled', 'storageQuota', 'storageIndexing']\n for (const prop of props) {\n if (createOrUpdateSpaceDto[prop] !== space[prop]) {\n spaceDiffProps[prop] = createOrUpdateSpaceDto[prop]\n if (prop === 'name') {\n spaceDiffProps.alias = await this.uniqueSpaceAlias(spaceDiffProps.name, true)\n if (space.alias !== spaceDiffProps.alias) {\n // must move the space to match the new alias\n const spaceLocationWasRenamed: boolean = await this.renameSpaceLocation(space.alias, spaceDiffProps.alias)\n if (!spaceLocationWasRenamed) {\n throw new HttpException('Unable to rename space', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n space.alias = spaceDiffProps.alias\n }\n } else if (prop === 'enabled') {\n spaceDiffProps.disabledAt = spaceDiffProps[prop] ? null : new Date()\n }\n }\n }\n // updates in db\n this.spacesQueries.updateSpace(spaceId, spaceDiffProps).catch((e: Error) => this.logger.error(`${this.updateSpace.name} - ${e}`))\n // checks & updates members\n const linkMembers: SpaceMemberDto[] = await this.sharesManager.createOrUpdateLinksAsMembers(\n user,\n space,\n LINK_TYPE.SPACE,\n createOrUpdateSpaceDto.links\n )\n const rootOwnerIds: number[] = await this.updateMembers(user, space, [\n ...createOrUpdateSpaceDto.members,\n ...createOrUpdateSpaceDto.managers,\n ...linkMembers\n ])\n if (rootOwnerIds.length) {\n // removes the roots of removed members or those no longer having the `share inside` permission\n createOrUpdateSpaceDto.roots = createOrUpdateSpaceDto.roots.filter((r) => rootOwnerIds.indexOf(r.owner.id) === -1)\n }\n // checks & updates roots\n const aliases: string[] = space.roots.map((r) => r.alias)\n const names: string[] = [...(await dirListFileNames(SpaceModel.getFilesPath(space.alias))), ...space.roots.map((r) => r.name)]\n await this.updateRoots(user, space, space.roots, createOrUpdateSpaceDto.roots, aliases, names)\n if (rootOwnerIds.indexOf(user.id) > -1) {\n // current manager was removed\n return null\n } else {\n return this.spacesQueries.getSpaceAsManager(user.id, spaceId)\n }\n }\n\n async deleteSpace(user: UserModel, spaceId: number, deleteSpaceDto?: DeleteSpaceDto) {\n /* only managers of the space can disable it */\n const space: SpaceProps = await this.userCanAccessSpace(user.id, spaceId, true)\n // only admin can delete the space data, managers can only disable the space for 30 days\n const deleteNow: boolean = user.isAdmin && !!deleteSpaceDto?.deleteNow\n try {\n if (deleteNow) {\n await this.sharesManager.deleteAllLinkMembers(spaceId, LINK_TYPE.SPACE)\n }\n await this.deleteOrDisableSpace(space, deleteNow)\n this.logger.log(`${this.deleteSpace.name} - *${space.alias}* (${space.id}) was ${deleteNow ? 'deleted' : 'disabled'}`)\n } catch (e) {\n this.logger.error(`${this.deleteSpace.name} - *${space.alias}* (${space.id}) was not ${deleteNow ? 'deleted' : 'disabled'} : ${e}`)\n throw new HttpException('Unable to delete space', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n async getUserRoots(user: UserModel, spaceId: number): Promise<SpaceRootProps[]> {\n /* if user has no permissions on the space an empty array will be returned */\n return this.spacesQueries.getSpaceRoots(spaceId, user.id)\n }\n\n async updateUserRoots(user: UserModel, spaceId: number, userRoots: SpaceRootProps[], addOnly: boolean = false): Promise<SpaceRootProps[]> {\n const space: Partial<SpaceProps> = await this.userCanAccessSpace(user.id, spaceId)\n if (space.role !== SPACE_ROLE.IS_MANAGER && !haveSpacePermission(space, SPACE_OPERATION.SHARE_INSIDE)) {\n this.logger.warn(`is not allowed to share inside on this space : *${space.alias}* (${space.id})`)\n throw new HttpException('You are not allowed to do this action', HttpStatus.FORBIDDEN)\n }\n // current states\n const spaceRoots: SpaceRootProps[] = await this.spacesQueries.getSpaceRoots(spaceId)\n const aliases = spaceRoots.map((r) => r.alias)\n const names = [...(await dirListFileNames(SpaceModel.getFilesPath(space.alias))), ...spaceRoots.map((r) => r.name)]\n // force owner.id on new user roots (owner is optional and required for the next steps)\n userRoots.forEach((r: SpaceRootProps) => (r.owner = { id: user.id }))\n if (addOnly) {\n // short circuit the `updateRoots` function\n // we need to provide all space roots to avoid collisions on aliases and names for new user roots\n const toAdd: SpaceRootProps[] = await this.validateNewRoots(user, space, spaceRoots, userRoots, aliases, names)\n const status: Record<Exclude<ACTION, ACTION.DELETE_PERMANENTLY>, SpaceRootProps[]> = await this.spacesQueries.updateSpaceRoots(\n user.id,\n space.id,\n toAdd,\n [],\n []\n )\n Object.entries(status).forEach(([action, roots]: [ACTION, SpaceRootProps[]]) =>\n this.clearCachePermissionsAndOrNotify(space, action, user, null, roots).catch((e: Error) =>\n this.logger.error(`${this.updateUserRoots.name} - ${e}`)\n )\n )\n return this.getUserRoots(user, spaceId)\n } else {\n const currentUserRoots: SpaceRootProps[] = spaceRoots.filter((r) => r.owner?.id === user.id)\n await this.updateRoots(user, space, currentUserRoots, userRoots, aliases, names)\n return this.spacesQueries.getSpaceRoots(spaceId, user.id)\n }\n }\n\n async uniqueRootAlias(spaceId: number, alias: string, aliasesAndNames: string[], replaceCount = false): Promise<string> {\n /* for some webdav clients the root alias is displayed instead of the file name.\n * This is why a root alias must be unique for files too */\n if (aliasesAndNames.find((fName: string) => alias.toLowerCase() === fName.toLowerCase())) {\n const aliasExtension = path.extname(alias)\n const aliasWithoutExtension = path.basename(alias, aliasExtension)\n const originalAlias = createSlug(aliasWithoutExtension, replaceCount)\n let count = 1\n let newAlias = `${originalAlias}-${count}${aliasExtension}`\n while (await this.spacesQueries.spaceRootExistsForAlias(spaceId, newAlias)) {\n count += 1\n newAlias = `${originalAlias}-${count}${aliasExtension}`\n }\n return newAlias\n }\n return null\n }\n\n async updatePersonalSpacesQuota(forUser?: UserModel) {\n const props: (keyof User)[] = ['id', 'login', 'storageUsage', 'storageQuota']\n for (const user of await this.usersQueries.selectUsers(props, [\n lte(users.role, USER_ROLE.USER),\n ...(forUser ? [eq(users.id, forUser.id)] : [])\n ])) {\n const userPath = UserModel.getHomePath(user.login)\n if (!(await isPathExists(userPath))) {\n this.logger.warn(`${this.updatePersonalSpacesQuota.name} - *${user.login}* home path does not exist`)\n continue\n }\n const [size, errors] = await dirSize(userPath)\n for (const [path, error] of Object.entries(errors)) {\n this.logger.warn(`${this.updatePersonalSpacesQuota.name} - unable to get size for *${user.login}* on ${path} : ${error}`)\n }\n const spaceQuota: StorageQuota = { storageUsage: size, storageQuota: user.storageQuota }\n this.spacesQueries.cache\n .set(`${CACHE_QUOTA_USER_PREFIX}-${user.id}`, spaceQuota, CACHE_QUOTA_TTL)\n .catch((e: Error) => this.logger.error(`${this.updatePersonalSpacesQuota.name} - ${e}`))\n if (user.storageUsage !== spaceQuota.storageUsage) {\n this.logger.log(\n `${this.updatePersonalSpacesQuota.name} - user *${user.login}* (${user.id}) : storage usage updated : ${spaceQuota.storageUsage}`\n )\n await this.usersQueries.updateUserOrGuest(user.id, { storageUsage: spaceQuota.storageUsage })\n }\n }\n }\n\n async updateSpacesQuota(spaceId?: number) {\n for (const space of await this.spacesQueries.spacesQuotaPaths(spaceId)) {\n const spacePath = SpaceModel.getHomePath(space.alias)\n if (!(await isPathExists(spacePath))) {\n this.logger.warn(`${this.updateSpacesQuota.name} - *${space.alias}* home path does not exist`)\n continue\n }\n let size = 0\n for (const rPath of [spacePath, ...space.externalPaths.filter(Boolean)]) {\n const [rPathSize, errors] = await dirSize(rPath)\n size += rPathSize\n for (const [path, error] of Object.entries(errors)) {\n this.logger.warn(`${this.updateSpacesQuota.name} - unable to get size for *${space.alias}* on ${path} : ${error}`)\n }\n }\n const spaceQuota: StorageQuota = { storageUsage: size, storageQuota: space.storageQuota }\n this.spacesQueries.cache\n .set(`${CACHE_QUOTA_SPACE_PREFIX}-${space.id}`, spaceQuota, CACHE_QUOTA_TTL)\n .catch((e: Error) => this.logger.error(`${this.updateSpacesQuota.name} - ${e}`))\n if (space.storageUsage !== spaceQuota.storageUsage) {\n this.logger.log(`${this.updateSpacesQuota.name} - space *${space.alias}* (${space.id}) : storage usage updated : ${spaceQuota.storageUsage}`)\n await this.spacesQueries.updateSpace(space.id, { storageUsage: spaceQuota.storageUsage })\n }\n }\n }\n\n async deleteExpiredSpaces() {\n /* Removes spaces that have been disabled for more than 30 days */\n const props: (keyof Space)[] = ['id', 'name', 'alias', 'disabledAt']\n for (const space of await this.spacesQueries.selectSpaces(props, [eq(spaces.enabled, false), isNotNull(spaces.disabledAt)])) {\n const disabled = new Date(space.disabledAt)\n disabled.setDate(disabled.getDate() + SPACE_MAX_DISABLED_DAYS)\n if (new Date() > disabled) {\n try {\n await this.sharesManager.deleteAllLinkMembers(space.id, LINK_TYPE.SPACE)\n await this.deleteOrDisableSpace(space, true)\n this.logger.log(`${this.deleteExpiredSpaces.name} - space *${space.alias}* (${space.id}) was deleted`)\n } catch (e) {\n this.logger.error(`${this.deleteExpiredSpaces.name} - space *${space.alias}* (${space.id}) was not deleted : ${e}`)\n }\n }\n }\n }\n\n async listSpaceShares(user: UserModel, spaceId: number): Promise<ShareChild[]> {\n if (await this.userIsSpaceManager(user, spaceId)) {\n return this.sharesManager.listSpaceShares(spaceId)\n }\n }\n\n async getSpaceShare(user: UserModel, spaceId: number, shareId: number): Promise<ShareProps> {\n if (await this.userIsSpaceManager(user, spaceId, shareId)) {\n return this.sharesManager.getShareWithMembers(user, shareId, true)\n }\n }\n\n async updateSpaceShare(user: UserModel, spaceId: number, shareId: number, createOrUpdateShareDto: CreateOrUpdateShareDto): Promise<ShareProps> {\n if (await this.userIsSpaceManager(user, spaceId, shareId)) {\n return this.sharesManager.updateShare(user, shareId, createOrUpdateShareDto, true)\n }\n }\n\n async deleteSpaceShare(user: UserModel, spaceId: number, shareId: number): Promise<void> {\n if (await this.userIsSpaceManager(user, spaceId, shareId)) {\n return this.sharesManager.deleteShare(user, shareId, true)\n }\n }\n\n async getSpaceShareLink(user: UserModel, spaceId: number, shareId: number): Promise<ShareLink> {\n if (await this.userIsSpaceManager(user, spaceId, shareId)) {\n return this.sharesManager.getShareLink(user, shareId, true)\n }\n }\n\n private async updateMembers(user: UserModel, space: SpaceProps, currentMembers: SpaceMemberDto[]): Promise<number[]> {\n if (space.members.length === 0 && currentMembers.length === 0) {\n return\n }\n // diff\n const [add, update, remove]: [SpaceMemberDto[], Record<string | 'object', { old: any; new: any } | SpaceMemberDto>[], SpaceMemberDto[]] =\n diffCollection(space.members, currentMembers, ['permissions', 'spaceRole'], ['id', 'type'])\n\n // check members whitelists\n let toAdd: SpaceMemberDto[] = []\n if (add.length) {\n const [userIdsWhitelist, groupIdsWhitelist] = await Promise.all([\n this.usersQueries.usersWhitelist(user.id),\n this.usersQueries.groupsWhitelist(user.id)\n ])\n toAdd = add.filter((m) => {\n if (\n ((m.type === MEMBER_TYPE.USER || m.type === MEMBER_TYPE.GUEST) && !m.linkId && userIdsWhitelist.indexOf(m.id) === -1) ||\n ((m.type === MEMBER_TYPE.GROUP || m.type === MEMBER_TYPE.PGROUP) && groupIdsWhitelist.indexOf(m.id) === -1)\n ) {\n this.logger.warn(\n `${this.updateMembers.name} - cannot add ${m.type} (${m.id}) to space *${space.alias}* (${space.id}) : not in the members whitelist`\n )\n return false\n }\n return true\n })\n }\n\n // filter links\n const toRemove: SpaceMemberDto[] = remove.filter((m) => !m.linkId)\n // do remove links\n this.sharesManager.deleteLinkMembers(remove.filter((m) => !!m.linkId)).catch((e: Error) => this.logger.error(`${this.updateMembers.name} - ${e}`))\n // do update members\n const status: Record<\n Exclude<ACTION, ACTION.DELETE_PERMANENTLY>,\n {\n groupIds: number[]\n userIds: number[]\n }\n > = await this.spacesQueries.updateMembers(space.id, toAdd, convertDiffUpdate(update), toRemove)\n\n // lists deleted and updated members as potential share or space roots owners\n const [rmShareOwners, upShareOwners, rmRootOwners]: [\n SpaceMemberDto[],\n {\n object: SpaceMemberDto\n rmPermissions: SPACE_OPERATION[]\n }[],\n number[]\n ] = [[], [], []]\n\n for (const [action, members] of Object.entries(status) as Entries<typeof status>) {\n if (!members.userIds.length && !members.groupIds.length) continue\n if (action === ACTION.DELETE) {\n // stores the removed members who might own shares created from the current space\n rmShareOwners.push(\n ...toRemove.filter(\n (m) =>\n ((m.type === MEMBER_TYPE.USER || m.type === MEMBER_TYPE.GUEST) && members.userIds.indexOf(m.id) > -1) ||\n ((m.type === MEMBER_TYPE.GROUP || m.type === MEMBER_TYPE.PGROUP) && members.groupIds.indexOf(m.id) > -1)\n )\n )\n // stores ids of removed members that might have space roots\n rmRootOwners.push(...members.userIds)\n } else if (action === ACTION.UPDATE) {\n // stores permissions updates and members who might own shares created from the current space\n // ignore space managers (they have all permissions)\n for (const m of update as {\n object: SpaceMemberDto\n permissions?: { old: string; new: string }\n spaceRole?: { old: number; new: number }\n }[]) {\n if (\n ((m.object.type === MEMBER_TYPE.USER || m.object.type === MEMBER_TYPE.GUEST) &&\n m.object.spaceRole !== SPACE_ROLE.IS_MANAGER &&\n members.userIds.indexOf(m.object.id) > -1) ||\n ((m.object.type === MEMBER_TYPE.GROUP || m.object.type === MEMBER_TYPE.PGROUP) && members.groupIds.indexOf(m.object.id) > -1)\n ) {\n // special case, the manager was moved to members without permissions change\n if (!m.permissions && m.spaceRole.new === SPACE_ROLE.IS_MEMBER) {\n m.permissions = { old: SPACE_ALL_OPERATIONS, new: m.object.permissions }\n }\n // `share inside` permission is only used for spaces\n const diffPermissions = differencePermissions(m.permissions.old, m.permissions.new).filter((p) => p !== SPACE_OPERATION.SHARE_INSIDE)\n if (diffPermissions.length) {\n upShareOwners.push({ object: m.object, rmPermissions: diffPermissions as SPACE_OPERATION[] })\n }\n }\n }\n }\n // clear cache &|| notify\n this.onSpaceActionForMembers(space, action, members, user).catch((e: Error) => this.logger.error(`${this.updateMembers.name} - ${e}`))\n }\n // do updates\n // remove or update potential shares\n this.sharesManager\n .updateSharesFromSpace(space.id, currentMembers, rmShareOwners, upShareOwners)\n .catch((e: Error) => this.logger.error(`${this.updateMembers.name} - ${e}`))\n // return potential root owner ids\n return rmRootOwners\n }\n\n private async updateRoots(\n user: UserModel,\n space: Partial<SpaceProps>,\n curRoots: SpaceRootProps[],\n newRoots: SpaceRootProps[],\n aliases: string[],\n names: string[]\n ) {\n // diff\n const [add, toUpdate, toRemove]: [\n SpaceRootProps[],\n Record<\n string | 'object',\n | {\n old: any\n new: any\n }\n | SpaceRootProps\n | any\n >[],\n SpaceRootProps[]\n ] = diffCollection(curRoots, newRoots, ['name', 'alias', 'permissions'])\n\n // update\n for (const props of toUpdate) {\n if ('alias' in props) {\n props.alias.new = (await this.uniqueRootAlias(space.id, props.alias.new, aliases.concat(names), true)) || props.alias.new\n // remove from space cache permissions\n this.spacesQueries\n .clearCachePermissions(space.alias, [props.alias.old, props.alias.new])\n .catch((e: Error) => this.logger.error(`${this.updateRoots.name} - ${e}`))\n // update aliases list for next roots\n aliases.push(props.alias.new)\n }\n if ('name' in props) {\n props.name.new = this.uniqueRootName(props.name.new, names) || props.name.new\n // update names list for next roots\n names.push(props.name.new)\n }\n }\n\n // format actions\n const toAdd = await this.validateNewRoots(user, space, curRoots, add, aliases, names)\n\n // remove a root implies that all shares with a reference to root.id will be deleted in cascade\n // however, it is \"cleaner\" to warn users about the deletion of these shares and to clear the permission caches before the cascade deletion\n // it must be assumed that the deletion and modifications of space roots will be successful\n const [rmRoots, rmRootPermissions]: [\n SpaceRoot['id'][],\n {\n id: SpaceRoot['id']\n rmPermissions: SPACE_OPERATION[]\n }[]\n ] = [\n toRemove.map((r) => r.id),\n (toUpdate as any).reduce((acc: typeof rmRootPermissions, r: any): typeof rmRootPermissions => {\n if (r.permissions !== undefined) {\n const diffPermissions = differencePermissions(r.permissions.old, r.permissions.new) as SPACE_OPERATION[]\n if (diffPermissions.length) {\n acc.push({ id: r.object.id, rmPermissions: diffPermissions })\n }\n }\n return acc\n }, [])\n ]\n // do share updates\n await this.sharesManager.updateSharesFromSpaceRoots(space.id, rmRoots, rmRootPermissions)\n\n // do root updates\n const status: Record<Exclude<ACTION, ACTION.DELETE_PERMANENTLY>, SpaceRootProps[]> = await this.spacesQueries.updateSpaceRoots(\n user.id,\n space.id,\n toAdd,\n convertDiffUpdate(toUpdate),\n toRemove\n )\n Object.entries(status).forEach(([action, roots]: [ACTION, SpaceRootProps[]]) =>\n this.clearCachePermissionsAndOrNotify(space, action, user, null, roots).catch((e: Error) =>\n this.logger.error(`${this.updateRoots.name} - ${e}`)\n )\n )\n }\n\n private async validateNewRoots(\n user: UserModel,\n space: Partial<SpaceProps>,\n curRoots: SpaceRootProps[],\n newRoots: SpaceRootProps[],\n aliases: string[],\n names: string[]\n ): Promise<SpaceRootProps[]> {\n const toAdd: SpaceRootProps[] = []\n for (const r of newRoots) {\n if (r.externalPath && !user.isAdmin) {\n this.logger.warn(`ignore new root *${r.alias}* (${r.externalPath}) : adding an external path requires the admin role`)\n continue\n }\n const rPath = r.externalPath || path.join(user.filesPath, r.file.path)\n if (!(await isPathExists(rPath))) {\n this.logger.warn(`ignore new root *${r.alias}* (${r.file.path}) : *${rPath}* does not exist`)\n continue\n }\n // check if a parent exists for an externalPath or if the file (or parent) is already anchored\n let rExists: SpaceRootProps\n if (r.externalPath) {\n rExists = curRoots.find((cr) => cr.externalPath && r.externalPath.startsWith(cr.externalPath))\n } else {\n rExists = curRoots.find(\n (cr) => cr.file?.id === r.file.id || (cr.owner?.id === r.owner.id && cr.file?.path && r.file.path.startsWith(cr.file.path))\n )\n }\n if (rExists) {\n this.logger.warn(`ignore new root *${r.alias}* (${r.externalPath || r.file.path}) (${r.file?.id}) : parent or file already exists in roots`)\n continue\n }\n // keep the file id (maybe already in db)\n if (!r.externalPath) {\n r.file = { ...(await getProps(rPath, r.file.path)), id: r.file.id }\n }\n r.alias = (await this.uniqueRootAlias(space.id, r.alias, aliases.concat(names), true)) || r.alias\n // update aliases list for next roots\n aliases.push(r.alias)\n r.name = this.uniqueRootName(r.name, names) || r.name\n // update names list for next roots\n names.push(r.name)\n // reset id\n r.id = 0\n toAdd.push(r)\n }\n return toAdd\n }\n\n private async deleteOrDisableSpace(space: Partial<SpaceProps>, deleteNow: boolean = false) {\n if (deleteNow) {\n // clear cache &|| notify\n const memberIds: { groupIds: number[]; userIds: number[] } = await this.spacesQueries.getSpaceMemberIds(space.id)\n this.onSpaceActionForMembers(space, ACTION.DELETE_PERMANENTLY, memberIds).catch((e: Error) =>\n this.logger.error(`${this.deleteOrDisableSpace.name} - ${e}`)\n )\n // remove all shares related to the space\n await this.sharesManager.removeSharesFromSpace(space.id)\n }\n await this.spacesQueries.deleteSpace(space.id, deleteNow)\n if (deleteNow) {\n this.spacesQueries.cache\n .del(`${CACHE_QUOTA_SPACE_PREFIX}-${space.id}`)\n .catch((e: Error) => this.logger.error(`${this.deleteOrDisableSpace.name} - ${e}`))\n await this.deleteSpaceLocation(space.alias)\n }\n }\n\n private async deleteSpaceLocation(spaceAlias: string) {\n const spaceLocation = SpaceModel.getHomePath(spaceAlias)\n if (await isPathExists(spaceLocation)) {\n await removeFiles(spaceLocation)\n this.logger.warn(`${this.deleteSpaceLocation.name} - space *${spaceAlias}* location was deleted`)\n } else {\n this.logger.warn(`${this.deleteSpaceLocation.name} - space *${spaceAlias}* location does not exist : ${spaceLocation}`)\n }\n }\n\n private async renameSpaceLocation(oldSpaceAlias: string, newSpaceAlias: string): Promise<boolean> {\n const currentSpaceLocation: string = SpaceModel.getHomePath(oldSpaceAlias)\n if (await isPathExists(currentSpaceLocation)) {\n const newSpaceLocation: string = SpaceModel.getHomePath(newSpaceAlias)\n if (await isPathExists(newSpaceLocation)) {\n this.logger.warn(`${this.renameSpaceLocation.name} - *${newSpaceAlias}* home path already exists : ${newSpaceLocation}`)\n return false\n } else {\n try {\n await moveFiles(currentSpaceLocation, newSpaceLocation)\n return true\n } catch (e) {\n // try to restore\n await moveFiles(newSpaceLocation, currentSpaceLocation, true)\n this.logger.error(\n `${this.renameSpaceLocation.name} - unable to rename space location from *${currentSpaceLocation}* to *${newSpaceLocation}* : ${e}`\n )\n return false\n }\n }\n } else {\n this.logger.warn(`${this.renameSpaceLocation.name} - *${oldSpaceAlias}* space location does not exist : ${currentSpaceLocation}`)\n return false\n }\n }\n\n private async uniqueSpaceAlias(name: string, replaceCount = false): Promise<string> {\n let alias = createSlug(name, replaceCount)\n let count = 0\n // Personal space name is reserved\n if (alias === SPACE_ALIAS.PERSONAL) {\n count += 1\n alias = `${name}-${count}`\n }\n while (await this.spacesQueries.spaceExistsForAlias(alias)) {\n count += 1\n alias = `${name}-${count}`\n }\n return alias\n }\n\n private async userCanAccessSpace(userId: number, spaceId: number, asManager: true): Promise<SpaceProps>\n private async userCanAccessSpace(userId: number, spaceId: number, asManager?: false): Promise<Partial<SpaceProps>>\n private async userCanAccessSpace(userId: number, spaceId: number, asManager: boolean = false): Promise<Partial<SpaceProps>> {\n if (asManager) {\n // Get all space details if user is a manager\n const space: SpaceProps = await this.spacesQueries.getSpaceAsManager(userId, spaceId)\n if (!space) {\n this.logger.warn(`space (${spaceId}) not found or not authorized for user (${userId})`)\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n return space\n } else {\n const [space]: SpaceProps[] = await this.spacesQueries.spaces(userId, true, spaceId)\n if (!space) {\n this.logger.warn(`space (${spaceId}) not found or not authorized for user (${userId})`)\n throw new HttpException('Space not found', HttpStatus.NOT_FOUND)\n }\n return space\n }\n }\n\n private async userIsSpaceManager(user: UserModel, spaceId: number, shareId?: number): Promise<boolean> {\n if (!(await this.spacesQueries.userIsSpaceManager(user.id, spaceId, shareId))) {\n this.logger.warn(`space (${spaceId}) not found or not authorized for user (${user.id})`)\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n return true\n }\n\n private async setQuotaExceeded(user: UserModel, space: SpaceEnv) {\n /* extract quota from spaces|shares|roots */\n if (space.inSharesList) {\n return\n }\n const cacheQuotaKey = quotaKeyFromSpace(user.id, space)\n if (!cacheQuotaKey) {\n this.logger.verbose(`${this.setQuotaExceeded.name} - quota was ignored for space : *${space.alias}* (${space.id})`)\n return\n }\n let quota: StorageQuota = await this.spacesQueries.cache.get(cacheQuotaKey)\n if (!quota) {\n // the quota scheduler has not started yet or the cache has been cleared\n if (space.inPersonalSpace) {\n await this.updatePersonalSpacesQuota(user)\n } else if (space.inSharesRepository) {\n // Shares with external paths\n await this.sharesManager.updateSharesExternalPathQuota(space.id)\n } else {\n await this.updateSpacesQuota(space.id)\n }\n quota = await this.spacesQueries.cache.get(cacheQuotaKey)\n }\n if (quota) {\n space.storageUsage = quota.storageUsage\n space.storageQuota = quota.storageQuota\n space.quotaIsExceeded = quota.storageQuota !== null && quota.storageUsage >= quota.storageQuota\n } else {\n this.logger.verbose(`${this.setQuotaExceeded.name} - quota not found for space : *${space.alias}* (${space.id})`)\n }\n }\n\n private async onSpaceActionForMembers(\n space: Partial<SpaceProps>,\n action: ACTION,\n members: {\n groupIds: number[]\n userIds: number[]\n },\n user?: UserModel\n ) {\n this.clearCachePermissionsAndOrNotify(\n space,\n action,\n user,\n Array.from(new Set([...(await this.usersQueries.allUserIdsFromGroupsAndSubGroups(members.groupIds)), ...members.userIds])).filter(\n (uid) => uid !== user?.id\n )\n ).catch((e: Error) => this.logger.error(`${this.onSpaceActionForMembers.name} - ${e}`))\n }\n\n private async clearCachePermissionsAndOrNotify(\n space: Partial<SpaceProps>,\n action: ACTION,\n user?: UserModel,\n memberIds?: number[],\n roots?: SpaceRootProps[]\n ): Promise<void> {\n if (memberIds?.length) {\n // clear permissions for space members\n if (action === ACTION.DELETE_PERMANENTLY) {\n this.logger.verbose(`${this.clearCachePermissionsAndOrNotify.name} - space:${space.alias} ${action}`)\n this.spacesQueries\n .clearCachePermissions(space.alias)\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n } else {\n // update space members cache\n this.logger.verbose(`${this.clearCachePermissionsAndOrNotify.name} - space:${space.alias} ${action} members:${JSON.stringify(memberIds)}`)\n this.spacesQueries\n .clearCachePermissions(space.alias, undefined, memberIds)\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n }\n // notify\n if (action !== ACTION.UPDATE) {\n // notify the members who have joined or left the space\n const notification: NotificationContent = {\n app: NOTIFICATION_APP.SPACES,\n event: NOTIFICATION_APP_EVENT.SPACES[action],\n element: space.name,\n url: ''\n }\n this.notificationsManager\n .create(memberIds, notification, {\n currentUrl: this.contextManager.headerOriginUrl(),\n action: action\n })\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n }\n } else if (roots?.length) {\n // clear permissions for space roots\n const rootAliases: string[] = roots.map((r) => r.alias)\n this.logger.verbose(`${this.clearCachePermissionsAndOrNotify.name} - space:${space.alias} ${action} roots:${JSON.stringify(rootAliases)}`)\n if (action !== ACTION.ADD) {\n this.spacesQueries\n .clearCachePermissions(space.alias, rootAliases)\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n }\n // notify\n if (action !== ACTION.UPDATE) {\n // notify the space members that a new root was anchored / unanchored\n const spaceMembers = await this.spacesQueries.getSpaceMemberIds(space.id)\n const spaceUserIds = Array.from(\n new Set([...(await this.usersQueries.allUserIdsFromGroupsAndSubGroups(spaceMembers.groupIds)), ...spaceMembers.userIds])\n ).filter((uid) => uid !== user?.id)\n if (!spaceUserIds.length) {\n return\n }\n for (const r of roots) {\n const notification: NotificationContent = {\n app: NOTIFICATION_APP.SPACE_ROOTS,\n event: NOTIFICATION_APP_EVENT.SPACE_ROOTS[action],\n element: r.name,\n url: `${SPACE_REPOSITORY.FILES}/${space.name}`\n }\n this.notificationsManager\n .create(spaceUserIds, notification, {\n currentUrl: this.contextManager.headerOriginUrl(),\n author: user,\n action: action\n })\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n }\n }\n }\n }\n}\n"],"names":["SpacesManager","listSpaces","userId","spacesQueries","spaces","spacesWithDetails","uniqueRootName","name","names","find","fName","toLowerCase","nameExtension","path","extname","nameWithoutExtension","basename","originalName","replace","regExpNumberSuffix","count","newName","spaceEnv","user","urlSegments","skipEndpointProtection","repository","spaceAlias","rootAlias","paths","SPACE_REPOSITORY","SHARES","Object","values","indexOf","Error","space","SPACE_ALIAS","PERSONAL","unshift","SpaceEnv","SPACE_PERSONAL","spacePermissions","sharesManager","permissions","SPACE_SHARES","TRASH","id","setup","setQuotaExceeded","e","logger","warn","alias","HttpException","message","FileError","httpCode","HttpStatus","BAD_REQUEST","searchSpaces","searchSpaceDto","sps","s","shareInsidePermission","haveSpacePermission","SPACE_OPERATION","SHARE_INSIDE","search","description","push","length","limit","listSpacesWithPermissions","Promise","all","map","listTrashes","trashes","personalTrash","nb","mtime","ctime","rPath","trashPath","SpaceModel","getTrashPath","fs","readdir","filter","f","configuration","applications","files","showHiddenFiles","stats","stat","getTime","birthtime","error","getSpace","spaceId","userCanAccessSpace","roots","isAdmin","root","externalPath","createSpace","createOrUpdateSpaceDto","SpaceProps","uniqueSpaceAlias","enabled","storageQuota","storageIndexing","disabledAt","Date","makePaths","updateRoots","updateMembers","members","concat","managers","createOrUpdateLinksAsMembers","LINK_TYPE","SPACE","links","getSpaceAsManager","updateSpace","spaceDiffProps","modifiedAt","props","prop","spaceLocationWasRenamed","renameSpaceLocation","INTERNAL_SERVER_ERROR","catch","linkMembers","rootOwnerIds","r","owner","aliases","dirListFileNames","getFilesPath","deleteSpace","deleteSpaceDto","deleteNow","deleteAllLinkMembers","deleteOrDisableSpace","log","getUserRoots","getSpaceRoots","updateUserRoots","userRoots","addOnly","role","SPACE_ROLE","IS_MANAGER","FORBIDDEN","spaceRoots","forEach","toAdd","validateNewRoots","status","updateSpaceRoots","entries","action","clearCachePermissionsAndOrNotify","currentUserRoots","uniqueRootAlias","aliasesAndNames","replaceCount","aliasExtension","aliasWithoutExtension","originalAlias","createSlug","newAlias","spaceRootExistsForAlias","updatePersonalSpacesQuota","forUser","usersQueries","selectUsers","lte","users","USER_ROLE","USER","eq","userPath","UserModel","getHomePath","login","isPathExists","size","errors","dirSize","spaceQuota","storageUsage","cache","set","CACHE_QUOTA_USER_PREFIX","CACHE_QUOTA_TTL","updateUserOrGuest","updateSpacesQuota","spacesQuotaPaths","spacePath","externalPaths","Boolean","rPathSize","CACHE_QUOTA_SPACE_PREFIX","deleteExpiredSpaces","selectSpaces","isNotNull","disabled","setDate","getDate","SPACE_MAX_DISABLED_DAYS","listSpaceShares","userIsSpaceManager","getSpaceShare","shareId","getShareWithMembers","updateSpaceShare","createOrUpdateShareDto","updateShare","deleteSpaceShare","deleteShare","getSpaceShareLink","getShareLink","currentMembers","add","update","remove","diffCollection","userIdsWhitelist","groupIdsWhitelist","usersWhitelist","groupsWhitelist","m","type","MEMBER_TYPE","GUEST","linkId","GROUP","PGROUP","toRemove","deleteLinkMembers","convertDiffUpdate","rmShareOwners","upShareOwners","rmRootOwners","userIds","groupIds","ACTION","DELETE","UPDATE","object","spaceRole","new","IS_MEMBER","old","SPACE_ALL_OPERATIONS","diffPermissions","differencePermissions","p","rmPermissions","onSpaceActionForMembers","updateSharesFromSpace","curRoots","newRoots","toUpdate","clearCachePermissions","rmRoots","rmRootPermissions","reduce","acc","undefined","updateSharesFromSpaceRoots","join","filesPath","file","rExists","cr","startsWith","getProps","memberIds","getSpaceMemberIds","DELETE_PERMANENTLY","removeSharesFromSpace","del","deleteSpaceLocation","spaceLocation","removeFiles","oldSpaceAlias","newSpaceAlias","currentSpaceLocation","newSpaceLocation","moveFiles","spaceExistsForAlias","asManager","NOT_FOUND","inSharesList","cacheQuotaKey","quotaKeyFromSpace","verbose","quota","get","inPersonalSpace","inSharesRepository","updateSharesExternalPathQuota","quotaIsExceeded","Array","from","Set","allUserIdsFromGroupsAndSubGroups","uid","JSON","stringify","notification","app","NOTIFICATION_APP","SPACES","event","NOTIFICATION_APP_EVENT","element","url","notificationsManager","create","currentUrl","contextManager","headerOriginUrl","rootAliases","ADD","spaceMembers","spaceUserIds","SPACE_ROOTS","FILES","author","Logger"],"mappings":"AAAA;;;;CAIC;;;;+BAwDYA;;;eAAAA;;;wBAtDiD;4BAC3B;iEACpB;iEACE;2BACM;2BACkD;wBAE1B;mCACjB;uCACC;2BACL;uBACgE;uBAChE;+BAC+B;6CAEpB;sCAKP;wBACF;sBACF;2BACA;6BAEJ;qCACO;uBACsD;wBAU5E;+BAKkB;iCACE;4BAEA;8BAGJ;uBACW;6BACE;sCACN;;;;;;;;;;;;;;;AAGvB,IAAA,AAAMA,gBAAN,MAAMA;IAWXC,WAAWC,MAAc,EAAkC;QACzD,OAAO,IAAI,CAACC,aAAa,CAACC,MAAM,CAACF;IACnC;IAEAG,kBAAkBH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ACV,GACC9B,KAAK,CAAC,CAACrF,IAAa,IAAI,CAACC,MAAM,CAACgD,KAAK,CAAC,GAAG,IAAI,CAACmE,gCAAgC,CAAC/J,IAAI,CAAC,GAAG,EAAE2C,GAAG;gBACjG;YACF;QACF;IACF;IAh2BA,YACE,AAAiBqR,cAA8B,EAC/C,AAAiBpU,aAA4B,EAC7C,AAAiBgL,YAA0B,EAC3C,AAAiBxI,aAA4B,EAC7C,AAAiByR,oBAA0C,CAC3D;aALiBG,iBAAAA;aACApU,gBAAAA;aACAgL,eAAAA;aACAxI,gBAAAA;aACAyR,uBAAAA;aAPFjR,SAAS,IAAI6R,cAAM,CAAChV,cAAcO,IAAI;IAQpD;AA21BL"}
1
+ {"version":3,"sources":["../../../../../backend/src/applications/spaces/services/spaces-manager.service.ts"],"sourcesContent":["/*\n * Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com>\n * This file is part of Sync-in | The open source file sync and share solution\n * See the LICENSE file for licensing details\n */\n\nimport { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common'\nimport { eq, isNotNull, lte } from 'drizzle-orm'\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\nimport { ACTION } from '../../../common/constants'\nimport { convertDiffUpdate, diffCollection, differencePermissions } from '../../../common/functions'\nimport type { Entries, StorageQuota } from '../../../common/interfaces'\nimport { createSlug, regExpNumberSuffix } from '../../../common/shared'\nimport { configuration } from '../../../configuration/config.environment'\nimport { ContextManager } from '../../../infrastructure/context/services/context-manager.service'\nimport { FileError } from '../../files/models/file-error'\nimport { dirListFileNames, dirSize, getProps, isPathExists, moveFiles, removeFiles } from '../../files/utils/files'\nimport { LINK_TYPE } from '../../links/constants/links'\nimport { NOTIFICATION_APP, NOTIFICATION_APP_EVENT } from '../../notifications/constants/notifications'\nimport { NotificationContent } from '../../notifications/interfaces/notification-properties.interface'\nimport { NotificationsManager } from '../../notifications/services/notifications-manager.service'\nimport { CreateOrUpdateShareDto } from '../../shares/dto/create-or-update-share.dto'\nimport type { ShareLink } from '../../shares/interfaces/share-link.interface'\nimport type { ShareProps } from '../../shares/interfaces/share-props.interface'\nimport type { ShareChild } from '../../shares/models/share-child.model'\nimport { SharesManager } from '../../shares/services/shares-manager.service'\nimport { MEMBER_TYPE } from '../../users/constants/member'\nimport { USER_ROLE } from '../../users/constants/user'\nimport { UserModel } from '../../users/models/user.model'\nimport type { User } from '../../users/schemas/user.interface'\nimport { users } from '../../users/schemas/users.schema'\nimport { UsersQueries } from '../../users/services/users-queries.service'\nimport { CACHE_QUOTA_SPACE_PREFIX, CACHE_QUOTA_TTL, CACHE_QUOTA_USER_PREFIX } from '../constants/cache'\nimport {\n SPACE_ALIAS,\n SPACE_ALL_OPERATIONS,\n SPACE_MAX_DISABLED_DAYS,\n SPACE_OPERATION,\n SPACE_PERSONAL,\n SPACE_REPOSITORY,\n SPACE_ROLE,\n SPACE_SHARES\n} from '../constants/spaces'\nimport { CreateOrUpdateSpaceDto, SpaceMemberDto } from '../dto/create-or-update-space.dto'\nimport { DeleteSpaceDto } from '../dto/delete-space.dto'\nimport { SearchSpaceDto } from '../dto/search-space.dto'\nimport { SpaceTrash } from '../interfaces/space-trash.interface'\nimport { SpaceEnv } from '../models/space-env.model'\nimport { SpaceProps } from '../models/space-props.model'\nimport type { SpaceRootProps } from '../models/space-root-props.model'\nimport { SpaceModel } from '../models/space.model'\nimport type { SpaceRoot } from '../schemas/space-root.interface'\nimport type { Space } from '../schemas/space.interface'\nimport { spaces } from '../schemas/spaces.schema'\nimport { quotaKeyFromSpace } from '../utils/paths'\nimport { haveSpacePermission } from '../utils/permissions'\nimport { SpacesQueries } from './spaces-queries.service'\n\n@Injectable()\nexport class SpacesManager {\n private readonly logger = new Logger(SpacesManager.name)\n\n constructor(\n private readonly contextManager: ContextManager,\n private readonly spacesQueries: SpacesQueries,\n private readonly usersQueries: UsersQueries,\n private readonly sharesManager: SharesManager,\n private readonly notificationsManager: NotificationsManager\n ) {}\n\n listSpaces(userId: number): Promise<Partial<SpaceProps>[]> {\n return this.spacesQueries.spaces(userId)\n }\n\n spacesWithDetails(userId: number): Promise<SpaceProps[]> {\n return this.spacesQueries.spacesWithDetails(userId)\n }\n\n uniqueRootName(name: string, names: string[]) {\n if (names.find((fName: string) => name.toLowerCase() === fName.toLowerCase())) {\n const nameExtension = path.extname(name)\n const nameWithoutExtension = path.basename(name, nameExtension)\n const originalName = nameWithoutExtension.replace(regExpNumberSuffix, '')\n let count = 1\n let newName = `${originalName}-${count}${nameExtension}`\n while (names.find((fName: string) => newName.toLowerCase() === fName.toLowerCase())) {\n count += 1\n newName = `${originalName}-${count}${nameExtension}`\n }\n return newName\n }\n return null\n }\n\n async spaceEnv(user: UserModel, urlSegments: string[], skipEndpointProtection = false): Promise<SpaceEnv> {\n /* SpaceEnv builder */\n let [repository, spaceAlias, rootAlias, ...paths] = urlSegments\n\n if (\n !repository ||\n (!spaceAlias && repository !== SPACE_REPOSITORY.SHARES) ||\n Object.values(SPACE_REPOSITORY).indexOf(repository as SPACE_REPOSITORY) === -1\n ) {\n throw new Error(`Space path is not valid : ${urlSegments}`)\n }\n\n let space: SpaceEnv\n if (spaceAlias === SPACE_ALIAS.PERSONAL) {\n /* Personal Space (static) */\n if (rootAlias) {\n // there is no root in a personal space\n paths.unshift(rootAlias)\n rootAlias = null\n }\n space = new SpaceEnv(SPACE_PERSONAL, rootAlias, false)\n } else if (repository === SPACE_REPOSITORY.SHARES) {\n if (spaceAlias) {\n /* Share */\n const spacePermissions: Partial<SpaceEnv> = await this.sharesManager.permissions(user, spaceAlias)\n if (spacePermissions) {\n space = new SpaceEnv(spacePermissions, null, false)\n }\n } else {\n /* Shares List (static) */\n space = new SpaceEnv(SPACE_SHARES, null, false)\n }\n } else {\n /* Space */\n if (repository === SPACE_REPOSITORY.TRASH && rootAlias) {\n // there is no root in a trash space\n paths.unshift(rootAlias)\n rootAlias = null\n }\n const spacePermissions: Partial<SpaceEnv> = await this.spacesQueries.permissions(user.id, spaceAlias, rootAlias)\n if (spacePermissions) {\n space = new SpaceEnv(spacePermissions, rootAlias || '')\n }\n }\n if (!space) return null\n try {\n space.setup(user, repository as SPACE_REPOSITORY, rootAlias, paths, urlSegments, skipEndpointProtection)\n await this.setQuotaExceeded(user, space)\n return space\n } catch (e) {\n this.logger.warn(`${this.spaceEnv.name} - *${space.alias}* : ${e}`)\n throw new HttpException(e.message, e instanceof FileError ? e.httpCode : HttpStatus.BAD_REQUEST)\n }\n }\n\n async searchSpaces(userId: number, searchSpaceDto: SearchSpaceDto): Promise<SpaceProps[]> {\n const sps: SpaceProps[] = []\n for (const s of await this.spacesQueries.spaces(userId, true)) {\n if (searchSpaceDto.shareInsidePermission && !haveSpacePermission(s, SPACE_OPERATION.SHARE_INSIDE)) {\n continue\n }\n if (!searchSpaceDto.search || `${s.name} ${s.alias} ${s.description || ''}`.toLowerCase().indexOf(searchSpaceDto.search) > -1) {\n sps.push(s)\n }\n if (sps.length >= searchSpaceDto.limit) {\n break\n }\n }\n return sps\n }\n\n async listSpacesWithPermissions(user: UserModel): Promise<SpaceEnv[]> {\n return Promise.all(\n (await this.spacesQueries.spaces(user.id, true)).map(async (s) => {\n const space = new SpaceEnv(s)\n await this.setQuotaExceeded(user, space)\n return space\n })\n )\n }\n\n async listTrashes(user: UserModel): Promise<SpaceTrash[]> {\n const trashes: SpaceTrash[] = []\n // todo: store 'Personal files' as const somewhere (used in frontend too)\n const personalTrash: SpaceTrash = { id: 0, name: 'Personal files', alias: SPACE_ALIAS.PERSONAL, nb: 0, mtime: 0, ctime: 0 }\n for (const space of [...(await this.listSpaces(user.id)), personalTrash] as SpaceTrash[]) {\n const rPath = space.alias === SPACE_ALIAS.PERSONAL ? user.trashPath : SpaceModel.getTrashPath(space.alias)\n try {\n space.nb = (await fs.readdir(rPath)).filter((f) => configuration.applications.files.showHiddenFiles || f[0] !== '.').length\n if (space.nb) {\n const stats = await fs.stat(rPath)\n space.mtime = stats.mtime.getTime()\n space.ctime = stats.birthtime.getTime()\n trashes.push(space)\n }\n } catch (e) {\n this.logger.error(`${this.listTrashes.name} - ${e}`)\n }\n }\n return trashes\n }\n\n async getSpace(user: UserModel, spaceId: number): Promise<SpaceProps> {\n const space: SpaceProps = await this.userCanAccessSpace(user.id, spaceId, true)\n if (space.roots?.length && !user.isAdmin) {\n // remove external path if the current user is not an administrator\n for (const root of space.roots) {\n root.externalPath = null\n }\n }\n return space\n }\n\n async createSpace(user: UserModel, createOrUpdateSpaceDto: CreateOrUpdateSpaceDto): Promise<SpaceProps> {\n /* only users with admin space role can create a space */\n // create space\n const space: SpaceProps = new SpaceProps({\n name: createOrUpdateSpaceDto.name,\n alias: await this.uniqueSpaceAlias(createOrUpdateSpaceDto.name, true),\n description: createOrUpdateSpaceDto.description,\n enabled: createOrUpdateSpaceDto.enabled,\n storageQuota: createOrUpdateSpaceDto.storageQuota,\n storageIndexing: createOrUpdateSpaceDto.storageIndexing,\n disabledAt: createOrUpdateSpaceDto.enabled ? null : new Date()\n })\n try {\n space.id = await this.spacesQueries.createSpace(space)\n } catch (e) {\n this.logger.error(`${this.createSpace.name} - unable to create space *${space.alias}* : ${e}`)\n throw new HttpException('Unable to create space', e)\n }\n // create space paths\n await SpaceModel.makePaths(space.alias)\n // add roots\n await this.updateRoots(user, space, space.roots, createOrUpdateSpaceDto.roots, [], [])\n // add members\n await this.updateMembers(user, space, createOrUpdateSpaceDto.members.concat(createOrUpdateSpaceDto.managers))\n // create links after members, user must be a space manager to create links\n await this.sharesManager.createOrUpdateLinksAsMembers(user, space, LINK_TYPE.SPACE, createOrUpdateSpaceDto.links)\n return this.spacesQueries.getSpaceAsManager(user.id, space.id)\n }\n\n async updateSpace(user: UserModel, spaceId: number, createOrUpdateSpaceDto: CreateOrUpdateSpaceDto): Promise<SpaceProps> {\n /* only managers of the space can update it */\n const space: SpaceProps = await this.userCanAccessSpace(user.id, spaceId, true)\n // check and update space info\n const spaceDiffProps: Partial<SpaceProps> = { modifiedAt: new Date() }\n const props: (keyof CreateOrUpdateSpaceDto)[] = ['name', 'description', 'enabled', 'storageQuota', 'storageIndexing']\n for (const prop of props) {\n if (createOrUpdateSpaceDto[prop] !== space[prop]) {\n spaceDiffProps[prop] = createOrUpdateSpaceDto[prop]\n if (prop === 'name') {\n spaceDiffProps.alias = await this.uniqueSpaceAlias(spaceDiffProps.name, true)\n if (space.alias !== spaceDiffProps.alias) {\n // must move the space to match the new alias\n const spaceLocationWasRenamed: boolean = await this.renameSpaceLocation(space.alias, spaceDiffProps.alias)\n if (!spaceLocationWasRenamed) {\n throw new HttpException('Unable to rename space', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n space.alias = spaceDiffProps.alias\n }\n } else if (prop === 'enabled') {\n spaceDiffProps.disabledAt = spaceDiffProps[prop] ? null : new Date()\n }\n }\n }\n // updates in db\n this.spacesQueries.updateSpace(spaceId, spaceDiffProps).catch((e: Error) => this.logger.error(`${this.updateSpace.name} - ${e}`))\n // checks & updates members\n const linkMembers: SpaceMemberDto[] = await this.sharesManager.createOrUpdateLinksAsMembers(\n user,\n space,\n LINK_TYPE.SPACE,\n createOrUpdateSpaceDto.links\n )\n const rootOwnerIds: number[] = await this.updateMembers(user, space, [\n ...createOrUpdateSpaceDto.members,\n ...createOrUpdateSpaceDto.managers,\n ...linkMembers\n ])\n if (rootOwnerIds.length) {\n // removes the roots of removed members or those no longer having the `share inside` permission\n createOrUpdateSpaceDto.roots = createOrUpdateSpaceDto.roots.filter((r) => rootOwnerIds.indexOf(r.owner.id) === -1)\n }\n // checks & updates roots\n const aliases: string[] = space.roots.map((r) => r.alias)\n const names: string[] = [...(await dirListFileNames(SpaceModel.getFilesPath(space.alias))), ...space.roots.map((r) => r.name)]\n await this.updateRoots(user, space, space.roots, createOrUpdateSpaceDto.roots, aliases, names)\n if (rootOwnerIds.indexOf(user.id) > -1) {\n // current manager was removed\n return null\n } else {\n return this.spacesQueries.getSpaceAsManager(user.id, spaceId)\n }\n }\n\n async deleteSpace(user: UserModel, spaceId: number, deleteSpaceDto?: DeleteSpaceDto) {\n /* only managers of the space can disable it */\n const space: SpaceProps = await this.userCanAccessSpace(user.id, spaceId, true)\n // only admin can delete the space data, managers can only disable the space for 30 days\n const deleteNow: boolean = user.isAdmin && !!deleteSpaceDto?.deleteNow\n try {\n if (deleteNow) {\n await this.sharesManager.deleteAllLinkMembers(spaceId, LINK_TYPE.SPACE)\n }\n await this.deleteOrDisableSpace(space, deleteNow)\n this.logger.log(`${this.deleteSpace.name} - *${space.alias}* (${space.id}) was ${deleteNow ? 'deleted' : 'disabled'}`)\n } catch (e) {\n this.logger.error(`${this.deleteSpace.name} - *${space.alias}* (${space.id}) was not ${deleteNow ? 'deleted' : 'disabled'} : ${e}`)\n throw new HttpException('Unable to delete space', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n async getUserRoots(user: UserModel, spaceId: number): Promise<SpaceRootProps[]> {\n /* if user has no permissions on the space an empty array will be returned */\n return this.spacesQueries.getSpaceRoots(spaceId, user.id)\n }\n\n async updateUserRoots(user: UserModel, spaceId: number, userRoots: SpaceRootProps[], addOnly: boolean = false): Promise<SpaceRootProps[]> {\n const space: Partial<SpaceProps> = await this.userCanAccessSpace(user.id, spaceId)\n if (space.role !== SPACE_ROLE.IS_MANAGER && !haveSpacePermission(space, SPACE_OPERATION.SHARE_INSIDE)) {\n this.logger.warn(`is not allowed to share inside on this space : *${space.alias}* (${space.id})`)\n throw new HttpException('You are not allowed to do this action', HttpStatus.FORBIDDEN)\n }\n // current states\n const spaceRoots: SpaceRootProps[] = await this.spacesQueries.getSpaceRoots(spaceId)\n const aliases = spaceRoots.map((r) => r.alias)\n const names = [...(await dirListFileNames(SpaceModel.getFilesPath(space.alias))), ...spaceRoots.map((r) => r.name)]\n // force owner.id on new user roots (owner is optional and required for the next steps)\n userRoots.forEach((r: SpaceRootProps) => (r.owner = { id: user.id }))\n if (addOnly) {\n // short circuit the `updateRoots` function\n // we need to provide all space roots to avoid collisions on aliases and names for new user roots\n const toAdd: SpaceRootProps[] = await this.validateNewRoots(user, space, spaceRoots, userRoots, aliases, names)\n const status: Record<Exclude<ACTION, ACTION.DELETE_PERMANENTLY>, SpaceRootProps[]> = await this.spacesQueries.updateSpaceRoots(\n user.id,\n space.id,\n toAdd,\n [],\n []\n )\n Object.entries(status).forEach(([action, roots]: [ACTION, SpaceRootProps[]]) =>\n this.clearCachePermissionsAndOrNotify(space, action, user, null, roots).catch((e: Error) =>\n this.logger.error(`${this.updateUserRoots.name} - ${e}`)\n )\n )\n return this.getUserRoots(user, spaceId)\n } else {\n const currentUserRoots: SpaceRootProps[] = spaceRoots.filter((r) => r.owner?.id === user.id)\n await this.updateRoots(user, space, currentUserRoots, userRoots, aliases, names)\n return this.spacesQueries.getSpaceRoots(spaceId, user.id)\n }\n }\n\n async uniqueRootAlias(spaceId: number, alias: string, aliasesAndNames: string[], replaceCount = false): Promise<string> {\n /* for some webdav clients the root alias is displayed instead of the file name.\n * This is why a root alias must be unique for files too */\n if (aliasesAndNames.find((fName: string) => alias.toLowerCase() === fName.toLowerCase())) {\n const aliasExtension = path.extname(alias)\n const aliasWithoutExtension = path.basename(alias, aliasExtension)\n const originalAlias = createSlug(aliasWithoutExtension, replaceCount)\n let count = 1\n let newAlias = `${originalAlias}-${count}${aliasExtension}`\n while (await this.spacesQueries.spaceRootExistsForAlias(spaceId, newAlias)) {\n count += 1\n newAlias = `${originalAlias}-${count}${aliasExtension}`\n }\n return newAlias\n }\n return null\n }\n\n async updatePersonalSpacesQuota(): Promise<void>\n async updatePersonalSpacesQuota(forUser: UserModel): Promise<StorageQuota>\n async updatePersonalSpacesQuota(forUser?: UserModel): Promise<void | StorageQuota> {\n const props: (keyof User)[] = ['id', 'login', 'storageUsage', 'storageQuota']\n for (const user of await this.usersQueries.selectUsers(props, [\n lte(users.role, USER_ROLE.USER),\n ...(forUser ? [eq(users.id, forUser.id)] : [])\n ])) {\n const userPath = UserModel.getHomePath(user.login)\n if (!(await isPathExists(userPath))) {\n this.logger.warn(`${this.updatePersonalSpacesQuota.name} - *${user.login}* home path does not exist`)\n continue\n }\n const [size, errors] = await dirSize(userPath)\n for (const [path, error] of Object.entries(errors)) {\n this.logger.warn(`${this.updatePersonalSpacesQuota.name} - unable to get size for *${user.login}* on ${path} : ${error}`)\n }\n const spaceQuota: StorageQuota = { storageUsage: size, storageQuota: user.storageQuota }\n this.spacesQueries.cache\n .set(`${CACHE_QUOTA_USER_PREFIX}-${user.id}`, spaceQuota, CACHE_QUOTA_TTL)\n .catch((e: Error) => this.logger.error(`${this.updatePersonalSpacesQuota.name} - user *${user.login}* (${user.id}) : ${e}`))\n if (user.storageUsage !== spaceQuota.storageUsage) {\n this.usersQueries\n .updateUserOrGuest(user.id, { storageUsage: spaceQuota.storageUsage })\n .then(\n (updated: boolean) =>\n updated &&\n this.logger.log(\n `${this.updatePersonalSpacesQuota.name} - user *${user.login}* (${user.id}) - storage usage updated: ${spaceQuota.storageUsage}`\n )\n )\n }\n if (forUser) {\n return spaceQuota\n }\n }\n }\n\n async updateSpacesQuota(): Promise<void>\n async updateSpacesQuota(spaceId: number): Promise<StorageQuota>\n async updateSpacesQuota(spaceId?: number): Promise<void | StorageQuota> {\n for (const space of await this.spacesQueries.spacesQuotaPaths(spaceId)) {\n const spacePath = SpaceModel.getHomePath(space.alias)\n if (!(await isPathExists(spacePath))) {\n this.logger.warn(`${this.updateSpacesQuota.name} - *${space.alias}* home path does not exist`)\n continue\n }\n let size = 0\n for (const rPath of [spacePath, ...space.externalPaths.filter(Boolean)]) {\n const [rPathSize, errors] = await dirSize(rPath)\n size += rPathSize\n for (const [path, error] of Object.entries(errors)) {\n this.logger.warn(`${this.updateSpacesQuota.name} - unable to get size for *${space.alias}* on ${path} : ${error}`)\n }\n }\n const spaceQuota: StorageQuota = { storageUsage: size, storageQuota: space.storageQuota }\n this.spacesQueries.cache\n .set(`${CACHE_QUOTA_SPACE_PREFIX}-${space.id}`, spaceQuota, CACHE_QUOTA_TTL)\n .catch((e: Error) => this.logger.error(`${this.updateSpacesQuota.name} - space *${space.alias}* (${space.id}) : ${e}`))\n if (space.storageUsage !== spaceQuota.storageUsage) {\n this.spacesQueries\n .updateSpace(space.id, { storageUsage: spaceQuota.storageUsage })\n .then(\n (updated: boolean) =>\n updated &&\n this.logger.log(\n `${this.updateSpacesQuota.name} - space *${space.alias}* (${space.id}) - storage usage updated : ${spaceQuota.storageUsage}`\n )\n )\n }\n if (spaceId) {\n return spaceQuota\n }\n }\n }\n\n async deleteExpiredSpaces() {\n /* Removes spaces that have been disabled for more than 30 days */\n const props: (keyof Space)[] = ['id', 'name', 'alias', 'disabledAt']\n for (const space of await this.spacesQueries.selectSpaces(props, [eq(spaces.enabled, false), isNotNull(spaces.disabledAt)])) {\n const disabled = new Date(space.disabledAt)\n disabled.setDate(disabled.getDate() + SPACE_MAX_DISABLED_DAYS)\n if (new Date() > disabled) {\n try {\n await this.sharesManager.deleteAllLinkMembers(space.id, LINK_TYPE.SPACE)\n await this.deleteOrDisableSpace(space, true)\n this.logger.log(`${this.deleteExpiredSpaces.name} - space *${space.alias}* (${space.id}) was deleted`)\n } catch (e) {\n this.logger.error(`${this.deleteExpiredSpaces.name} - space *${space.alias}* (${space.id}) was not deleted : ${e}`)\n }\n }\n }\n }\n\n async listSpaceShares(user: UserModel, spaceId: number): Promise<ShareChild[]> {\n if (await this.userIsSpaceManager(user, spaceId)) {\n return this.sharesManager.listSpaceShares(spaceId)\n }\n }\n\n async getSpaceShare(user: UserModel, spaceId: number, shareId: number): Promise<ShareProps> {\n if (await this.userIsSpaceManager(user, spaceId, shareId)) {\n return this.sharesManager.getShareWithMembers(user, shareId, true)\n }\n }\n\n async updateSpaceShare(user: UserModel, spaceId: number, shareId: number, createOrUpdateShareDto: CreateOrUpdateShareDto): Promise<ShareProps> {\n if (await this.userIsSpaceManager(user, spaceId, shareId)) {\n return this.sharesManager.updateShare(user, shareId, createOrUpdateShareDto, true)\n }\n }\n\n async deleteSpaceShare(user: UserModel, spaceId: number, shareId: number): Promise<void> {\n if (await this.userIsSpaceManager(user, spaceId, shareId)) {\n return this.sharesManager.deleteShare(user, shareId, true)\n }\n }\n\n async getSpaceShareLink(user: UserModel, spaceId: number, shareId: number): Promise<ShareLink> {\n if (await this.userIsSpaceManager(user, spaceId, shareId)) {\n return this.sharesManager.getShareLink(user, shareId, true)\n }\n }\n\n private async updateMembers(user: UserModel, space: SpaceProps, currentMembers: SpaceMemberDto[]): Promise<number[]> {\n if (space.members.length === 0 && currentMembers.length === 0) {\n return\n }\n // diff\n const [add, update, remove]: [SpaceMemberDto[], Record<string | 'object', { old: any; new: any } | SpaceMemberDto>[], SpaceMemberDto[]] =\n diffCollection(space.members, currentMembers, ['permissions', 'spaceRole'], ['id', 'type'])\n\n // check members whitelists\n let toAdd: SpaceMemberDto[] = []\n if (add.length) {\n const [userIdsWhitelist, groupIdsWhitelist] = await Promise.all([\n this.usersQueries.usersWhitelist(user.id),\n this.usersQueries.groupsWhitelist(user.id)\n ])\n toAdd = add.filter((m) => {\n if (\n ((m.type === MEMBER_TYPE.USER || m.type === MEMBER_TYPE.GUEST) && !m.linkId && userIdsWhitelist.indexOf(m.id) === -1) ||\n ((m.type === MEMBER_TYPE.GROUP || m.type === MEMBER_TYPE.PGROUP) && groupIdsWhitelist.indexOf(m.id) === -1)\n ) {\n this.logger.warn(\n `${this.updateMembers.name} - cannot add ${m.type} (${m.id}) to space *${space.alias}* (${space.id}) : not in the members whitelist`\n )\n return false\n }\n return true\n })\n }\n\n // filter links\n const toRemove: SpaceMemberDto[] = remove.filter((m) => !m.linkId)\n // do remove links\n this.sharesManager.deleteLinkMembers(remove.filter((m) => !!m.linkId)).catch((e: Error) => this.logger.error(`${this.updateMembers.name} - ${e}`))\n // do update members\n const status: Record<\n Exclude<ACTION, ACTION.DELETE_PERMANENTLY>,\n {\n groupIds: number[]\n userIds: number[]\n }\n > = await this.spacesQueries.updateMembers(space.id, toAdd, convertDiffUpdate(update), toRemove)\n\n // lists deleted and updated members as potential share or space roots owners\n const [rmShareOwners, upShareOwners, rmRootOwners]: [\n SpaceMemberDto[],\n {\n object: SpaceMemberDto\n rmPermissions: SPACE_OPERATION[]\n }[],\n number[]\n ] = [[], [], []]\n\n for (const [action, members] of Object.entries(status) as Entries<typeof status>) {\n if (!members.userIds.length && !members.groupIds.length) continue\n if (action === ACTION.DELETE) {\n // stores the removed members who might own shares created from the current space\n rmShareOwners.push(\n ...toRemove.filter(\n (m) =>\n ((m.type === MEMBER_TYPE.USER || m.type === MEMBER_TYPE.GUEST) && members.userIds.indexOf(m.id) > -1) ||\n ((m.type === MEMBER_TYPE.GROUP || m.type === MEMBER_TYPE.PGROUP) && members.groupIds.indexOf(m.id) > -1)\n )\n )\n // stores ids of removed members that might have space roots\n rmRootOwners.push(...members.userIds)\n } else if (action === ACTION.UPDATE) {\n // stores permissions updates and members who might own shares created from the current space\n // ignore space managers (they have all permissions)\n for (const m of update as {\n object: SpaceMemberDto\n permissions?: { old: string; new: string }\n spaceRole?: { old: number; new: number }\n }[]) {\n if (\n ((m.object.type === MEMBER_TYPE.USER || m.object.type === MEMBER_TYPE.GUEST) &&\n m.object.spaceRole !== SPACE_ROLE.IS_MANAGER &&\n members.userIds.indexOf(m.object.id) > -1) ||\n ((m.object.type === MEMBER_TYPE.GROUP || m.object.type === MEMBER_TYPE.PGROUP) && members.groupIds.indexOf(m.object.id) > -1)\n ) {\n // special case, the manager was moved to members without permissions change\n if (!m.permissions && m.spaceRole.new === SPACE_ROLE.IS_MEMBER) {\n m.permissions = { old: SPACE_ALL_OPERATIONS, new: m.object.permissions }\n }\n // `share inside` permission is only used for spaces\n const diffPermissions = differencePermissions(m.permissions.old, m.permissions.new).filter((p) => p !== SPACE_OPERATION.SHARE_INSIDE)\n if (diffPermissions.length) {\n upShareOwners.push({ object: m.object, rmPermissions: diffPermissions as SPACE_OPERATION[] })\n }\n }\n }\n }\n // clear cache &|| notify\n this.onSpaceActionForMembers(space, action, members, user).catch((e: Error) => this.logger.error(`${this.updateMembers.name} - ${e}`))\n }\n // do updates\n // remove or update potential shares\n this.sharesManager\n .updateSharesFromSpace(space.id, currentMembers, rmShareOwners, upShareOwners)\n .catch((e: Error) => this.logger.error(`${this.updateMembers.name} - ${e}`))\n // return potential root owner ids\n return rmRootOwners\n }\n\n private async updateRoots(\n user: UserModel,\n space: Partial<SpaceProps>,\n curRoots: SpaceRootProps[],\n newRoots: SpaceRootProps[],\n aliases: string[],\n names: string[]\n ) {\n // diff\n const [add, toUpdate, toRemove]: [\n SpaceRootProps[],\n Record<\n string | 'object',\n | {\n old: any\n new: any\n }\n | SpaceRootProps\n | any\n >[],\n SpaceRootProps[]\n ] = diffCollection(curRoots, newRoots, ['name', 'alias', 'permissions'])\n\n // update\n for (const props of toUpdate) {\n if ('alias' in props) {\n props.alias.new = (await this.uniqueRootAlias(space.id, props.alias.new, aliases.concat(names), true)) || props.alias.new\n // remove from space cache permissions\n this.spacesQueries\n .clearCachePermissions(space.alias, [props.alias.old, props.alias.new])\n .catch((e: Error) => this.logger.error(`${this.updateRoots.name} - ${e}`))\n // update aliases list for next roots\n aliases.push(props.alias.new)\n }\n if ('name' in props) {\n props.name.new = this.uniqueRootName(props.name.new, names) || props.name.new\n // update names list for next roots\n names.push(props.name.new)\n }\n }\n\n // format actions\n const toAdd = await this.validateNewRoots(user, space, curRoots, add, aliases, names)\n\n // remove a root implies that all shares with a reference to root.id will be deleted in cascade\n // however, it is \"cleaner\" to warn users about the deletion of these shares and to clear the permission caches before the cascade deletion\n // it must be assumed that the deletion and modifications of space roots will be successful\n const [rmRoots, rmRootPermissions]: [\n SpaceRoot['id'][],\n {\n id: SpaceRoot['id']\n rmPermissions: SPACE_OPERATION[]\n }[]\n ] = [\n toRemove.map((r) => r.id),\n (toUpdate as any).reduce((acc: typeof rmRootPermissions, r: any): typeof rmRootPermissions => {\n if (r.permissions !== undefined) {\n const diffPermissions = differencePermissions(r.permissions.old, r.permissions.new) as SPACE_OPERATION[]\n if (diffPermissions.length) {\n acc.push({ id: r.object.id, rmPermissions: diffPermissions })\n }\n }\n return acc\n }, [])\n ]\n // do share updates\n await this.sharesManager.updateSharesFromSpaceRoots(space.id, rmRoots, rmRootPermissions)\n\n // do root updates\n const status: Record<Exclude<ACTION, ACTION.DELETE_PERMANENTLY>, SpaceRootProps[]> = await this.spacesQueries.updateSpaceRoots(\n user.id,\n space.id,\n toAdd,\n convertDiffUpdate(toUpdate),\n toRemove\n )\n Object.entries(status).forEach(([action, roots]: [ACTION, SpaceRootProps[]]) =>\n this.clearCachePermissionsAndOrNotify(space, action, user, null, roots).catch((e: Error) =>\n this.logger.error(`${this.updateRoots.name} - ${e}`)\n )\n )\n }\n\n private async validateNewRoots(\n user: UserModel,\n space: Partial<SpaceProps>,\n curRoots: SpaceRootProps[],\n newRoots: SpaceRootProps[],\n aliases: string[],\n names: string[]\n ): Promise<SpaceRootProps[]> {\n const toAdd: SpaceRootProps[] = []\n for (const r of newRoots) {\n if (r.externalPath && !user.isAdmin) {\n this.logger.warn(`ignore new root *${r.alias}* (${r.externalPath}) : adding an external path requires the admin role`)\n continue\n }\n const rPath = r.externalPath || path.join(user.filesPath, r.file.path)\n if (!(await isPathExists(rPath))) {\n this.logger.warn(`ignore new root *${r.alias}* (${r.file.path}) : *${rPath}* does not exist`)\n continue\n }\n // check if a parent exists for an externalPath or if the file (or parent) is already anchored\n let rExists: SpaceRootProps\n if (r.externalPath) {\n rExists = curRoots.find((cr) => cr.externalPath && r.externalPath.startsWith(cr.externalPath))\n } else {\n rExists = curRoots.find(\n (cr) => cr.file?.id === r.file.id || (cr.owner?.id === r.owner.id && cr.file?.path && r.file.path.startsWith(cr.file.path))\n )\n }\n if (rExists) {\n this.logger.warn(`ignore new root *${r.alias}* (${r.externalPath || r.file.path}) (${r.file?.id}) : parent or file already exists in roots`)\n continue\n }\n // keep the file id (maybe already in db)\n if (!r.externalPath) {\n r.file = { ...(await getProps(rPath, r.file.path)), id: r.file.id }\n }\n r.alias = (await this.uniqueRootAlias(space.id, r.alias, aliases.concat(names), true)) || r.alias\n // update aliases list for next roots\n aliases.push(r.alias)\n r.name = this.uniqueRootName(r.name, names) || r.name\n // update names list for next roots\n names.push(r.name)\n // reset id\n r.id = 0\n toAdd.push(r)\n }\n return toAdd\n }\n\n private async deleteOrDisableSpace(space: Partial<SpaceProps>, deleteNow: boolean = false) {\n if (deleteNow) {\n // clear cache &|| notify\n const memberIds: { groupIds: number[]; userIds: number[] } = await this.spacesQueries.getSpaceMemberIds(space.id)\n this.onSpaceActionForMembers(space, ACTION.DELETE_PERMANENTLY, memberIds).catch((e: Error) =>\n this.logger.error(`${this.deleteOrDisableSpace.name} - ${e}`)\n )\n // remove all shares related to the space\n await this.sharesManager.removeSharesFromSpace(space.id)\n }\n await this.spacesQueries.deleteSpace(space.id, deleteNow)\n if (deleteNow) {\n this.spacesQueries.cache\n .del(`${CACHE_QUOTA_SPACE_PREFIX}-${space.id}`)\n .catch((e: Error) => this.logger.error(`${this.deleteOrDisableSpace.name} - ${e}`))\n await this.deleteSpaceLocation(space.alias)\n }\n }\n\n private async deleteSpaceLocation(spaceAlias: string) {\n const spaceLocation = SpaceModel.getHomePath(spaceAlias)\n if (await isPathExists(spaceLocation)) {\n await removeFiles(spaceLocation)\n this.logger.warn(`${this.deleteSpaceLocation.name} - space *${spaceAlias}* location was deleted`)\n } else {\n this.logger.warn(`${this.deleteSpaceLocation.name} - space *${spaceAlias}* location does not exist : ${spaceLocation}`)\n }\n }\n\n private async renameSpaceLocation(oldSpaceAlias: string, newSpaceAlias: string): Promise<boolean> {\n const currentSpaceLocation: string = SpaceModel.getHomePath(oldSpaceAlias)\n if (await isPathExists(currentSpaceLocation)) {\n const newSpaceLocation: string = SpaceModel.getHomePath(newSpaceAlias)\n if (await isPathExists(newSpaceLocation)) {\n this.logger.warn(`${this.renameSpaceLocation.name} - *${newSpaceAlias}* home path already exists : ${newSpaceLocation}`)\n return false\n } else {\n try {\n await moveFiles(currentSpaceLocation, newSpaceLocation)\n return true\n } catch (e) {\n // try to restore\n await moveFiles(newSpaceLocation, currentSpaceLocation, true)\n this.logger.error(\n `${this.renameSpaceLocation.name} - unable to rename space location from *${currentSpaceLocation}* to *${newSpaceLocation}* : ${e}`\n )\n return false\n }\n }\n } else {\n this.logger.warn(`${this.renameSpaceLocation.name} - *${oldSpaceAlias}* space location does not exist : ${currentSpaceLocation}`)\n return false\n }\n }\n\n private async uniqueSpaceAlias(name: string, replaceCount = false): Promise<string> {\n let alias = createSlug(name, replaceCount)\n let count = 0\n // Personal space name is reserved\n if (alias === SPACE_ALIAS.PERSONAL) {\n count += 1\n alias = `${name}-${count}`\n }\n while (await this.spacesQueries.spaceExistsForAlias(alias)) {\n count += 1\n alias = `${name}-${count}`\n }\n return alias\n }\n\n private async userCanAccessSpace(userId: number, spaceId: number, asManager: true): Promise<SpaceProps>\n private async userCanAccessSpace(userId: number, spaceId: number, asManager?: false): Promise<Partial<SpaceProps>>\n private async userCanAccessSpace(userId: number, spaceId: number, asManager: boolean = false): Promise<Partial<SpaceProps>> {\n if (asManager) {\n // Get all space details if user is a manager\n const space: SpaceProps = await this.spacesQueries.getSpaceAsManager(userId, spaceId)\n if (!space) {\n this.logger.warn(`space (${spaceId}) not found or not authorized for user (${userId})`)\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n return space\n } else {\n const [space]: SpaceProps[] = await this.spacesQueries.spaces(userId, true, spaceId)\n if (!space) {\n this.logger.warn(`space (${spaceId}) not found or not authorized for user (${userId})`)\n throw new HttpException('Space not found', HttpStatus.NOT_FOUND)\n }\n return space\n }\n }\n\n private async userIsSpaceManager(user: UserModel, spaceId: number, shareId?: number): Promise<boolean> {\n if (!(await this.spacesQueries.userIsSpaceManager(user.id, spaceId, shareId))) {\n this.logger.warn(`space (${spaceId}) not found or not authorized for user (${user.id})`)\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n return true\n }\n\n private async setQuotaExceeded(user: UserModel, space: SpaceEnv) {\n /* extract quota from spaces|shares|roots */\n if (space.inSharesList) {\n return\n }\n const cacheQuotaKey = quotaKeyFromSpace(user.id, space)\n if (!cacheQuotaKey) {\n this.logger.verbose(`${this.setQuotaExceeded.name} - quota was ignored for space : *${space.alias}* (${space.id})`)\n return\n }\n let quota: StorageQuota = await this.spacesQueries.cache.get(cacheQuotaKey)\n if (!quota) {\n // the quota scheduler has not started yet or the cache has been cleared\n if (space.inPersonalSpace) {\n quota = await this.updatePersonalSpacesQuota(user)\n } else if (space.inSharesRepository) {\n // Shares with external paths\n quota = await this.sharesManager.updateSharesExternalPathQuota(space.id)\n } else {\n quota = await this.updateSpacesQuota(space.id)\n }\n }\n if (quota) {\n space.storageUsage = quota.storageUsage\n space.storageQuota = quota.storageQuota\n space.quotaIsExceeded = quota.storageQuota !== null && quota.storageUsage >= quota.storageQuota\n } else {\n this.logger.verbose(`${this.setQuotaExceeded.name} - quota not found for space : *${space.alias}* (${space.id})`)\n }\n }\n\n private async onSpaceActionForMembers(\n space: Partial<SpaceProps>,\n action: ACTION,\n members: {\n groupIds: number[]\n userIds: number[]\n },\n user?: UserModel\n ) {\n this.clearCachePermissionsAndOrNotify(\n space,\n action,\n user,\n Array.from(new Set([...(await this.usersQueries.allUserIdsFromGroupsAndSubGroups(members.groupIds)), ...members.userIds])).filter(\n (uid) => uid !== user?.id\n )\n ).catch((e: Error) => this.logger.error(`${this.onSpaceActionForMembers.name} - ${e}`))\n }\n\n private async clearCachePermissionsAndOrNotify(\n space: Partial<SpaceProps>,\n action: ACTION,\n user?: UserModel,\n memberIds?: number[],\n roots?: SpaceRootProps[]\n ): Promise<void> {\n if (memberIds?.length) {\n // clear permissions for space members\n if (action === ACTION.DELETE_PERMANENTLY) {\n this.logger.verbose(`${this.clearCachePermissionsAndOrNotify.name} - space:${space.alias} ${action}`)\n this.spacesQueries\n .clearCachePermissions(space.alias)\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n } else {\n // update space members cache\n this.logger.verbose(`${this.clearCachePermissionsAndOrNotify.name} - space:${space.alias} ${action} members:${JSON.stringify(memberIds)}`)\n this.spacesQueries\n .clearCachePermissions(space.alias, undefined, memberIds)\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n }\n // notify\n if (action !== ACTION.UPDATE) {\n // notify the members who have joined or left the space\n const notification: NotificationContent = {\n app: NOTIFICATION_APP.SPACES,\n event: NOTIFICATION_APP_EVENT.SPACES[action],\n element: space.name,\n url: ''\n }\n this.notificationsManager\n .create(memberIds, notification, {\n currentUrl: this.contextManager.headerOriginUrl(),\n action: action\n })\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n }\n } else if (roots?.length) {\n // clear permissions for space roots\n const rootAliases: string[] = roots.map((r) => r.alias)\n this.logger.verbose(`${this.clearCachePermissionsAndOrNotify.name} - space:${space.alias} ${action} roots:${JSON.stringify(rootAliases)}`)\n if (action !== ACTION.ADD) {\n this.spacesQueries\n .clearCachePermissions(space.alias, rootAliases)\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n }\n // notify\n if (action !== ACTION.UPDATE) {\n // notify the space members that a new root was anchored / unanchored\n const spaceMembers = await this.spacesQueries.getSpaceMemberIds(space.id)\n const spaceUserIds = Array.from(\n new Set([...(await this.usersQueries.allUserIdsFromGroupsAndSubGroups(spaceMembers.groupIds)), ...spaceMembers.userIds])\n ).filter((uid) => uid !== user?.id)\n if (!spaceUserIds.length) {\n return\n }\n for (const r of roots) {\n const notification: NotificationContent = {\n app: NOTIFICATION_APP.SPACE_ROOTS,\n event: NOTIFICATION_APP_EVENT.SPACE_ROOTS[action],\n element: r.name,\n url: `${SPACE_REPOSITORY.FILES}/${space.name}`\n }\n this.notificationsManager\n .create(spaceUserIds, notification, {\n currentUrl: this.contextManager.headerOriginUrl(),\n author: user,\n action: action\n })\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n }\n }\n }\n }\n}\n"],"names":["SpacesManager","listSpaces","userId","spacesQueries","spaces","spacesWithDetails","uniqueRootName","name","names","find","fName","toLowerCase","nameExtension","path","extname","nameWithoutExtension","basename","originalName","replace","regExpNumberSuffix","count","newName","spaceEnv","user","urlSegments","skipEndpointProtection","repository","spaceAlias","rootAlias","paths","SPACE_REPOSITORY","SHARES","Object","values","indexOf","Error","space","SPACE_ALIAS","PERSONAL","unshift","SpaceEnv","SPACE_PERSONAL","spacePermissions","sharesManager","permissions","SPACE_SHARES","TRASH","id","setup","setQuotaExceeded","e","logger","warn","alias","HttpException","message","FileError","httpCode","HttpStatus","BAD_REQUEST","searchSpaces","searchSpaceDto","sps","s","shareInsidePermission","haveSpacePermission","SPACE_OPERATION","SHARE_INSIDE","search","description","push","length","limit","listSpacesWithPermissions","Promise","all","map","listTrashes","trashes","personalTrash","nb","mtime","ctime","rPath","trashPath","SpaceModel","getTrashPath","fs","readdir","filter","f","configuration","applications","files","showHiddenFiles","stats","stat","getTime","birthtime","error","getSpace","spaceId","userCanAccessSpace","roots","isAdmin","root","externalPath","createSpace","createOrUpdateSpaceDto","SpaceProps","uniqueSpaceAlias","enabled","storageQuota","storageIndexing","disabledAt","Date","makePaths","updateRoots","updateMembers","members","concat","managers","createOrUpdateLinksAsMembers","LINK_TYPE","SPACE","links","getSpaceAsManager","updateSpace","spaceDiffProps","modifiedAt","props","prop","spaceLocationWasRenamed","renameSpaceLocation","INTERNAL_SERVER_ERROR","catch","linkMembers","rootOwnerIds","r","owner","aliases","dirListFileNames","getFilesPath","deleteSpace","deleteSpaceDto","deleteNow","deleteAllLinkMembers","deleteOrDisableSpace","log","getUserRoots","getSpaceRoots","updateUserRoots","userRoots","addOnly","role","SPACE_ROLE","IS_MANAGER","FORBIDDEN","spaceRoots","forEach","toAdd","validateNewRoots","status","updateSpaceRoots","entries","action","clearCachePermissionsAndOrNotify","currentUserRoots","uniqueRootAlias","aliasesAndNames","replaceCount","aliasExtension","aliasWithoutExtension","originalAlias","createSlug","newAlias","spaceRootExistsForAlias","updatePersonalSpacesQuota","forUser","usersQueries","selectUsers","lte","users","USER_ROLE","USER","eq","userPath","UserModel","getHomePath","login","isPathExists","size","errors","dirSize","spaceQuota","storageUsage","cache","set","CACHE_QUOTA_USER_PREFIX","CACHE_QUOTA_TTL","updateUserOrGuest","then","updated","updateSpacesQuota","spacesQuotaPaths","spacePath","externalPaths","Boolean","rPathSize","CACHE_QUOTA_SPACE_PREFIX","deleteExpiredSpaces","selectSpaces","isNotNull","disabled","setDate","getDate","SPACE_MAX_DISABLED_DAYS","listSpaceShares","userIsSpaceManager","getSpaceShare","shareId","getShareWithMembers","updateSpaceShare","createOrUpdateShareDto","updateShare","deleteSpaceShare","deleteShare","getSpaceShareLink","getShareLink","currentMembers","add","update","remove","diffCollection","userIdsWhitelist","groupIdsWhitelist","usersWhitelist","groupsWhitelist","m","type","MEMBER_TYPE","GUEST","linkId","GROUP","PGROUP","toRemove","deleteLinkMembers","convertDiffUpdate","rmShareOwners","upShareOwners","rmRootOwners","userIds","groupIds","ACTION","DELETE","UPDATE","object","spaceRole","new","IS_MEMBER","old","SPACE_ALL_OPERATIONS","diffPermissions","differencePermissions","p","rmPermissions","onSpaceActionForMembers","updateSharesFromSpace","curRoots","newRoots","toUpdate","clearCachePermissions","rmRoots","rmRootPermissions","reduce","acc","undefined","updateSharesFromSpaceRoots","join","filesPath","file","rExists","cr","startsWith","getProps","memberIds","getSpaceMemberIds","DELETE_PERMANENTLY","removeSharesFromSpace","del","deleteSpaceLocation","spaceLocation","removeFiles","oldSpaceAlias","newSpaceAlias","currentSpaceLocation","newSpaceLocation","moveFiles","spaceExistsForAlias","asManager","NOT_FOUND","inSharesList","cacheQuotaKey","quotaKeyFromSpace","verbose","quota","get","inPersonalSpace","inSharesRepository","updateSharesExternalPathQuota","quotaIsExceeded","Array","from","Set","allUserIdsFromGroupsAndSubGroups","uid","JSON","stringify","notification","app","NOTIFICATION_APP","SPACES","event","NOTIFICATION_APP_EVENT","element","url","notificationsManager","create","currentUrl","contextManager","headerOriginUrl","rootAliases","ADD","spaceMembers","spaceUserIds","SPACE_ROOTS","FILES","author","Logger"],"mappings":"AAAA;;;;CAIC;;;;+BAwDYA;;;eAAAA;;;wBAtDiD;4BAC3B;iEACpB;iEACE;2BACM;2BACkD;wBAE1B;mCACjB;uCACC;2BACL;uBACgE;uBAChE;+BAC+B;6CAEpB;sCAKP;wBACF;sBACF;2BACA;6BAEJ;qCACO;uBACsD;wBAU5E;+BAKkB;iCACE;4BAEA;8BAGJ;uBACW;6BACE;sCACN;;;;;;;;;;;;;;;AAGvB,IAAA,AAAMA,gBAAN,MAAMA;IAWXC,WAAWC,MAAc,EAAkC;QACzD,OAAO,IAAI,CAACC,aAAa,CAACC,MAAM,CAACF;IACnC;IAEAG,kBAAkBH,MAAc,EAAyB;QACvD,OAAO,IAAI,CAACC,aAAa,CAACE,iBAAiB,CAACH;IAC9C;IAEAI,eAAeC,IAAY,EAAEC,KAAe,EAAE;QAC5C,IAAIA,MAAMC,IAAI,CAAC,CAACC,QAAkBH,KAAKI,WAAW,OAAOD,MAAMC,WAAW,KAAK;YAC7E,MAAMC,gBAAgBC,iBAAI,CAACC,OAAO,CAACP;YACnC,MAAMQ,uBAAuBF,iBAAI,CAACG,QAAQ,CAACT,MAAMK;YACjD,MAAMK,eAAeF,qBAAqBG,OAAO,CAACC,0BAAkB,EAAE;YACtE,IAAIC,QAAQ;YACZ,IAAIC,UAAU,GAAGJ,aAAa,CAAC,EAAEG,QAAQR,eAAe;YACxD,MAAOJ,MAAMC,IAAI,CAAC,CAACC,QAAkBW,QAAQV,WAAW,OAAOD,MAAMC,WAAW,IAAK;gBACnFS,SAAS;gBACTC,UAAU,GAAGJ,aAAa,CAAC,EAAEG,QAAQR,eAAe;YACtD;YACA,OAAOS;QACT;QACA,OAAO;IACT;IAEA,MAAMC,SAASC,IAAe,EAAEC,WAAqB,EAAEC,yBAAyB,KAAK,EAAqB;QACxG,oBAAoB,GACpB,IAA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this.adminQueries.updateGroup(groupId, updateGroupDto)) {
243
243
  throw new _common.HttpException('Unable to update group', _common.HttpStatus.INTERNAL_SERVER_ERROR);
244
244
  }
245
+ // Clear whitelist caches when the group’s visibility is changed
246
+ if (updateGroupDto.visibility !== undefined) {
247
+ this.adminQueries.usersQueries.clearWhiteListCaches('*');
248
+ }
245
249
  return this.adminQueries.groupFromId(groupId);
246
250
  }
247
251
  async deleteGroup(groupId) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../backend/src/applications/users/services/admin-users-manager.service.ts"],"sourcesContent":["/*\n * Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com>\n * This file is part of Sync-in | The open source file sync and share solution\n * See the LICENSE file for licensing details\n */\n\nimport { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common'\nimport { FastifyReply } from 'fastify'\nimport { LoginResponseDto } from '../../../authentication/dto/login-response.dto'\nimport { AuthManager } from '../../../authentication/services/auth-manager.service'\nimport { anonymizePassword, hashPassword } from '../../../common/functions'\nimport { isPathExists, moveFiles, removeFiles } from '../../files/utils/files'\nimport { GROUP_TYPE } from '../constants/group'\nimport { USER_ROLE } from '../constants/user'\nimport type { CreateOrUpdateGroupDto } from '../dto/create-or-update-group.dto'\nimport type { CreateUserDto, UpdateUserDto, UpdateUserFromGroupDto } from '../dto/create-or-update-user.dto'\nimport type { DeleteUserDto } from '../dto/delete-user.dto'\nimport type { SearchMembersDto } from '../dto/search-members.dto'\nimport type { AdminGroup } from '../interfaces/admin-group.interface'\nimport type { AdminUser } from '../interfaces/admin-user.interface'\nimport type { GroupBrowse } from '../interfaces/group-browse.interface'\nimport type { GuestUser } from '../interfaces/guest-user.interface'\nimport type { Member } from '../interfaces/member.interface'\nimport { UserModel } from '../models/user.model'\nimport type { Group } from '../schemas/group.interface'\nimport type { User } from '../schemas/user.interface'\nimport { AdminUsersQueries } from './admin-users-queries.service'\n\n@Injectable()\nexport class AdminUsersManager {\n private readonly logger = new Logger(AdminUsersManager.name)\n\n constructor(\n private readonly authManager: AuthManager,\n private readonly adminQueries: AdminUsersQueries\n ) {}\n\n listUsers(): Promise<AdminUser[]> {\n return this.adminQueries.listUsers()\n }\n\n async getUser(userId: number): Promise<AdminUser> {\n const user: AdminUser = await this.adminQueries.listUsers(userId)\n this.checkUser(user, true)\n return user\n }\n\n async getGuest(guestId: number): Promise<GuestUser> {\n const user: GuestUser = await this.adminQueries.usersQueries.listGuests(guestId, 0, true)\n this.checkUser(user, true)\n return user\n }\n\n async createUserOrGuest(createUserDto: CreateUserDto, userRole: USER_ROLE.GUEST, asAdmin: boolean): Promise<GuestUser>\n async createUserOrGuest(createUserDto: CreateUserDto, userRole: USER_ROLE, asAdmin: true): Promise<AdminUser | GuestUser>\n async createUserOrGuest(createUserDto: CreateUserDto, userRole: USER_ROLE, asAdmin?: false): Promise<UserModel>\n async createUserOrGuest(\n createUserDto: CreateUserDto,\n userRole: USER_ROLE = USER_ROLE.USER,\n asAdmin = false\n ): Promise<UserModel | AdminUser | GuestUser> {\n await this.loginOrEmailAlreadyUsed(createUserDto.login, createUserDto.email)\n try {\n createUserDto.password = await hashPassword(createUserDto.password)\n const userId: number = await this.adminQueries.usersQueries.createUserOrGuest(createUserDto, userRole)\n const user = new UserModel({ ...createUserDto, id: userId, role: userRole })\n this.logger.log(\n `${this.createUserOrGuest.name} - ${USER_ROLE[userRole]} (${userId}) was created : ${JSON.stringify(anonymizePassword(createUserDto))}`\n )\n this.adminQueries.usersQueries.clearWhiteListCaches('*')\n await user.makePaths()\n if (userRole <= USER_ROLE.USER) {\n return asAdmin ? this.getUser(user.id) : user\n } else {\n return asAdmin ? this.getGuest(user.id) : user\n }\n } catch (e) {\n this.logger.error(`${this.createUserOrGuest.name} - unable to create user *${createUserDto.login}* : ${e}`)\n throw new HttpException('Unable to create user', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n async updateUserOrGuest(userId: number, updateUserDto: UpdateUserDto): Promise<AdminUser>\n async updateUserOrGuest(userId: number, updateUserDto: UpdateUserDto, userRole: USER_ROLE.GUEST): Promise<GuestUser>\n async updateUserOrGuest(\n userId: number,\n updateUserDto: UpdateUserDto,\n userRole: USER_ROLE.USER | USER_ROLE.GUEST = USER_ROLE.USER\n ): Promise<AdminUser | GuestUser> {\n const user: AdminUser & GuestUser = userRole === USER_ROLE.USER ? await this.getUser(userId) : await this.getGuest(userId)\n const updateUser: Partial<User> = {}\n const updateUserGroups: { add: number[]; delete: number[] } = { add: [], delete: [] }\n const updateGuestManagers: { add: number[]; delete: number[] } = { add: [], delete: [] }\n for (const [k, v] of Object.entries(updateUserDto)) {\n switch (k as keyof UpdateUserDto) {\n case 'login':\n if (user.login === v) {\n break\n }\n if (await this.adminQueries.usersQueries.checkUserExists(v)) {\n throw new HttpException('Login already used', HttpStatus.FORBIDDEN)\n }\n if (!(await this.renameUserSpace(user.login, v))) {\n throw new HttpException('Unable to rename user space', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n updateUser.login = v\n break\n case 'email':\n if (user.email === v) {\n break\n }\n if (await this.adminQueries.usersQueries.checkUserExists(null, v)) {\n throw new HttpException('Email already used', HttpStatus.FORBIDDEN)\n }\n updateUser.email = v\n break\n case 'isActive':\n updateUser.isActive = v\n if (v) {\n updateUser.passwordAttempts = 0\n }\n break\n case 'password':\n updateUser.password = await hashPassword(updateUserDto.password)\n break\n case 'groups':\n if (userRole === USER_ROLE.USER) {\n const currentGroups: number[] = user.groups?.length ? user.groups.map((g) => g.id) : []\n updateUserGroups.add = v.filter((id: number) => currentGroups.indexOf(id) === -1)\n updateUserGroups.delete = currentGroups.filter((id: number) => v.indexOf(id) === -1)\n }\n break\n case 'managers':\n if (userRole === USER_ROLE.GUEST) {\n const currentManagers: number[] = user.managers?.length ? user.managers.map((m) => m.id) : []\n updateGuestManagers.add = v.filter((id: number) => currentManagers.indexOf(id) === -1)\n updateGuestManagers.delete = currentManagers.filter((id: number) => v.indexOf(id) === -1)\n }\n break\n default:\n updateUser[k] = v\n }\n }\n if (Object.keys(updateUser).length) {\n // force the type for security reason\n const forceRole = userRole === USER_ROLE.GUEST ? USER_ROLE.GUEST : undefined\n if (!(await this.adminQueries.usersQueries.updateUserOrGuest(user.id, updateUser, forceRole))) {\n throw new HttpException('Unable to update user', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n if (userRole === USER_ROLE.USER) {\n if (updateUserGroups.add.length || updateUserGroups.delete.length) {\n try {\n await this.adminQueries.updateUserGroups(user.id, updateUserGroups)\n } catch {\n throw new HttpException('Unable to update user groups', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n return this.getUser(userId)\n } else {\n if (updateGuestManagers.add.length || updateGuestManagers.delete.length) {\n try {\n await this.adminQueries.updateGuestManagers(user.id, updateGuestManagers)\n } catch {\n throw new HttpException('Unable to update guest managers', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n return this.getGuest(userId)\n }\n }\n\n async deleteUserOrGuest(userId: number, userLogin: string, deleteUserDto: DeleteUserDto): Promise<void> {\n try {\n if (await this.adminQueries.deleteUser(userId, userLogin)) {\n this.logger.log(`${this.deleteUserOrGuest.name} - *${userLogin}* (${userId}) was deleted`)\n } else {\n this.logger.error(`${this.deleteUserOrGuest.name} - *${userLogin}* (${userId}) was not deleted : not found`)\n }\n if (deleteUserDto.deleteSpace) {\n await this.deleteUserSpace(userLogin, deleteUserDto.isGuest)\n }\n } catch (e) {\n this.logger.error(`${this.deleteUserOrGuest.name} - unable to delete *${userLogin}* (${userId}) : ${e}`)\n throw new HttpException('Unable to delete user', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n async deleteUserOrGuestFromAdmin(userId: number, deleteUserDto: DeleteUserDto): Promise<void> {\n const userToDelete: UserModel = this.checkUser(await this.adminQueries.usersQueries.from(userId))\n if (userToDelete.isGuest !== deleteUserDto.isGuest) {\n throw new HttpException('User mismatch', HttpStatus.BAD_REQUEST)\n }\n await this.deleteUserOrGuest(userToDelete.id, userToDelete.login, {\n deleteSpace: deleteUserDto.isGuest ? true : deleteUserDto.deleteSpace,\n isGuest: deleteUserDto.isGuest\n } satisfies DeleteUserDto)\n }\n\n listGuests(): Promise<AdminUser[]> {\n return this.adminQueries.usersQueries.listGuests(null, null, true)\n }\n\n createGuest(user: UserModel, createGuestDto: CreateUserDto): Promise<GuestUser> {\n if (!createGuestDto.managers.length) {\n createGuestDto.managers.push(user.id)\n }\n return this.createUserOrGuest(createGuestDto, USER_ROLE.GUEST, true)\n }\n\n updateGuest(guestId: number, updateGuestDto: UpdateUserDto): Promise<GuestUser> {\n if (!Object.keys(updateGuestDto).length) {\n throw new HttpException('No changes to update', HttpStatus.BAD_REQUEST)\n }\n if (updateGuestDto.managers && !updateGuestDto.managers.length) {\n throw new HttpException('Guest must have at least one manager', HttpStatus.BAD_REQUEST)\n }\n return this.updateUserOrGuest(guestId, updateGuestDto, USER_ROLE.GUEST)\n }\n\n async browseGroups(name?: string, type: GROUP_TYPE = GROUP_TYPE.USER): Promise<GroupBrowse> {\n if (name) {\n const group: Pick<Group, 'id' | 'name' | 'type'> = await this.adminQueries.groupFromName(name)\n if (!group) {\n throw new HttpException('Group not found', HttpStatus.NOT_FOUND)\n }\n return { parentGroup: group, members: await this.adminQueries.browseGroupMembers(group.id, type) }\n }\n return { parentGroup: undefined, members: await this.adminQueries.browseRootGroupMembers(type) }\n }\n\n async getGroup(groupId: number): Promise<AdminGroup> {\n const group = await this.adminQueries.groupFromId(groupId)\n if (!group) {\n throw new HttpException('Group not found', HttpStatus.NOT_FOUND)\n }\n return group\n }\n\n async createGroup(createGroupDto: CreateOrUpdateGroupDto): Promise<AdminGroup> {\n if (!createGroupDto.name) {\n this.logger.error(`${this.createGroup.name} - missing group name : ${JSON.stringify(createGroupDto)}`)\n throw new HttpException('Group name is missing', HttpStatus.BAD_REQUEST)\n }\n await this.checkGroupNameExists(createGroupDto.name)\n try {\n const groupId: number = await this.adminQueries.createGroup(createGroupDto)\n this.logger.log(`${this.createGroup.name} - group (${groupId}) was created : ${JSON.stringify(createGroupDto)}`)\n return this.adminQueries.groupFromId(groupId)\n } catch (e) {\n this.logger.error(`${this.createGroup.name} - group was not created : ${JSON.stringify(createGroupDto)} : ${e}`)\n throw new HttpException('Unable to create group', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n async updateGroup(groupId: number, updateGroupDto: CreateOrUpdateGroupDto): Promise<AdminGroup> {\n if (updateGroupDto.name) {\n await this.checkGroupNameExists(updateGroupDto.name)\n }\n if (!(await this.adminQueries.updateGroup(groupId, updateGroupDto))) {\n throw new HttpException('Unable to update group', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n return this.adminQueries.groupFromId(groupId)\n }\n\n async deleteGroup(groupId: number): Promise<void> {\n if (await this.adminQueries.deleteGroup(groupId)) {\n this.logger.log(`${this.deleteGroup.name} - group (${groupId}) was deleted`)\n } else {\n this.logger.warn(`${this.deleteGroup.name} - group (${groupId}) does not exist`)\n throw new HttpException('Unable to delete group', HttpStatus.BAD_REQUEST)\n }\n }\n\n async addUsersToGroup(groupId: number, userIds: number[]): Promise<void> {\n const group: AdminGroup = await this.adminQueries.groupFromId(groupId)\n if (!group) {\n throw new HttpException('Group not found', HttpStatus.NOT_FOUND)\n }\n try {\n await this.adminQueries.addUsersToGroup(groupId, userIds, group.type === GROUP_TYPE.USER ? USER_ROLE.USER : undefined)\n } catch (e) {\n throw new HttpException(e.message, HttpStatus.BAD_REQUEST)\n }\n }\n\n async updateUserFromGroup(groupId: number, userId: number, updateUserFromGroupDto: UpdateUserFromGroupDto): Promise<void> {\n try {\n await this.adminQueries.updateUserFromGroup(groupId, userId, updateUserFromGroupDto.role)\n } catch (e) {\n throw new HttpException(e.message, HttpStatus.BAD_REQUEST)\n }\n }\n\n async removeUserFromGroup(groupId: number, userId: number): Promise<void> {\n try {\n await this.adminQueries.removeUserFromGroup(groupId, userId)\n } catch (e) {\n throw new HttpException(e.message, HttpStatus.BAD_REQUEST)\n }\n }\n\n searchMembers(searchMembersDto: SearchMembersDto): Promise<Member[]> {\n return this.adminQueries.usersQueries.searchUsersOrGroups(searchMembersDto)\n }\n\n async impersonateUser(admin: UserModel, userId: number, res: FastifyReply): Promise<LoginResponseDto> {\n if (admin.id === userId) {\n throw new HttpException('You are already logged in', HttpStatus.BAD_REQUEST)\n }\n const user: UserModel = this.checkUser(await this.adminQueries.usersQueries.from(userId))\n user.impersonatedFromId = admin.id\n user.impersonatedClientId = admin.clientId\n return this.authManager.setCookies(user, res)\n }\n\n async logoutImpersonateUser(user: UserModel, res: FastifyReply): Promise<LoginResponseDto> {\n if (!user.impersonatedFromId) {\n throw new HttpException('You are not allowed to do this action', HttpStatus.FORBIDDEN)\n }\n const admin: UserModel = this.checkUser(await this.adminQueries.usersQueries.from(user.impersonatedFromId))\n if (!admin.isAdmin) {\n throw new HttpException('You are not allowed to do this action', HttpStatus.FORBIDDEN)\n }\n admin.clientId = user.impersonatedClientId\n return this.authManager.setCookies(admin, res)\n }\n\n async deleteUserSpace(userLogin: string, isGuest = false): Promise<void> {\n const userSpace: string = UserModel.getHomePath(userLogin, isGuest)\n try {\n if (await isPathExists(userSpace)) {\n await removeFiles(userSpace)\n this.logger.log(`${this.deleteUserSpace.name} - user space *${userLogin}* was deleted`)\n } else {\n this.logger.warn(`${this.deleteUserSpace.name} - user space *${userLogin}* does not exist : ${userSpace}`)\n }\n } catch (e) {\n this.logger.warn(`${this.deleteUserSpace.name} - user space *${userLogin}* (${userSpace}) was not deleted : ${e}`)\n throw new HttpException('Unable to delete user space', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n checkUser(user: User | AdminUser | GuestUser, checkOnly: true): void\n checkUser(user: User | AdminUser | GuestUser, checkOnly?: false): UserModel\n checkUser(user: User | AdminUser | GuestUser, checkOnly = false): UserModel | void {\n if (!user) {\n throw new HttpException('User not found', HttpStatus.NOT_FOUND)\n }\n if (!checkOnly) {\n return new UserModel(user, true)\n }\n }\n\n private async renameUserSpace(oldLogin: string, newLogin: string): Promise<boolean> {\n const currentUserSpace: string = UserModel.getHomePath(oldLogin)\n if (!(await isPathExists(currentUserSpace))) {\n this.logger.warn(`${this.renameUserSpace.name} - user space *${oldLogin}* does not exist : ${currentUserSpace}`)\n return false\n }\n const newUserSpace: string = UserModel.getHomePath(newLogin)\n if (await isPathExists(newUserSpace)) {\n this.logger.warn(`${this.renameUserSpace.name} - user space *${newLogin}* already exists : ${newUserSpace}`)\n return false\n }\n try {\n await moveFiles(currentUserSpace, newUserSpace)\n return true\n } catch (e) {\n // try to restore\n await moveFiles(newUserSpace, currentUserSpace, true)\n this.logger.error(`${this.renameUserSpace.name} - unable to rename user space from *${currentUserSpace}* to *${newUserSpace}* : ${e}`)\n return false\n }\n }\n\n private async checkGroupNameExists(groupName: string): Promise<void> {\n if (await this.adminQueries.usersQueries.checkGroupNameExists(groupName)) {\n throw new HttpException('Name already used', HttpStatus.BAD_REQUEST)\n }\n }\n\n private async loginOrEmailAlreadyUsed(login: string, email: string) {\n const exists = await this.adminQueries.usersQueries.checkUserExists(login, email)\n if (exists) {\n throw new HttpException(`${exists.login === login ? 'Login' : 'Email'} already used`, HttpStatus.BAD_REQUEST)\n }\n }\n}\n"],"names":["AdminUsersManager","listUsers","adminQueries","getUser","userId","user","checkUser","getGuest","guestId","usersQueries","listGuests","createUserOrGuest","createUserDto","userRole","USER_ROLE","USER","asAdmin","loginOrEmailAlreadyUsed","login","email","password","hashPassword","UserModel","id","role","logger","log","name","JSON","stringify","anonymizePassword","clearWhiteListCaches","makePaths","e","error","HttpException","HttpStatus","INTERNAL_SERVER_ERROR","updateUserOrGuest","updateUserDto","updateUser","updateUserGroups","add","delete","updateGuestManagers","k","v","Object","entries","checkUserExists","FORBIDDEN","renameUserSpace","isActive","passwordAttempts","currentGroups","groups","length","map","g","filter","indexOf","GUEST","currentManagers","managers","m","keys","forceRole","undefined","deleteUserOrGuest","userLogin","deleteUserDto","deleteUser","deleteSpace","deleteUserSpace","isGuest","deleteUserOrGuestFromAdmin","userToDelete","from","BAD_REQUEST","createGuest","createGuestDto","push","updateGuest","updateGuestDto","browseGroups","type","GROUP_TYPE","group","groupFromName","NOT_FOUND","parentGroup","members","browseGroupMembers","browseRootGroupMembers","getGroup","groupId","groupFromId","createGroup","createGroupDto","checkGroupNameExists","updateGroup","updateGroupDto","deleteGroup","warn","addUsersToGroup","userIds","message","updateUserFromGroup","updateUserFromGroupDto","removeUserFromGroup","searchMembers","searchMembersDto","searchUsersOrGroups","impersonateUser","admin","res","impersonatedFromId","impersonatedClientId","clientId","authManager","setCookies","logoutImpersonateUser","isAdmin","userSpace","getHomePath","isPathExists","removeFiles","checkOnly","oldLogin","newLogin","currentUserSpace","newUserSpace","moveFiles","groupName","exists","Logger"],"mappings":"AAAA;;;;CAIC;;;;+BAyBYA;;;eAAAA;;;wBAvBiD;oCAGlC;2BACoB;uBACK;uBAC1B;sBACD;2BAUA;0CAGQ;;;;;;;;;;AAG3B,IAAA,AAAMA,oBAAN,MAAMA;IAQXC,YAAkC;QAChC,OAAO,IAAI,CAACC,YAAY,CAACD,SAAS;IACpC;IAEA,MAAME,QAAQC,MAAc,EAAsB;QAChD,MAAMC,OAAkB,MAAM,IAAI,CAACH,YAAY,CAACD,SAAS,CAACG;QAC1D,IAAI,CAACE,SAAS,CAACD,MAAM;QACrB,OAAOA;IACT;IAEA,MAAME,SAASC,OAAe,EAAsB;QAClD,MAAMH,OAAkB,MAAM,IAAI,CAACH,YAAY,CAACO,YAAY,CAACC,UAAU,CAACF,SAAS,GAAG;QACpF,IAAI,CAACF,SAAS,CAACD,MAAM;QACrB,OAAOA;IACT;IAKA,MAAMM,kBACJC,aAA4B,EAC5BC,WAAsBC,eAAS,CAACC,IAAI,EACpCC,UAAU,KAAK,EAC6B;QAC5C,MAAM,IAAI,CAACC,uBAAuB,CAACL,cAAcM,KAAK,EAAEN,cAAcO,KAAK;QAC3E,IAAI;YACFP,cAAcQ,QAAQ,GAAG,MAAMC,IAAAA,uBAAY,EAACT,cAAcQ,QAAQ;YAClE,MAAMh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qC,EAAEuG,iBAAiB,MAAM,EAAEC,aAAa,IAAI,EAAElG,GAAG;YACrI,OAAO;QACT;IACF;IAEA,MAAckE,qBAAqBkC,SAAiB,EAAiB;QACnE,IAAI,MAAM,IAAI,CAACnI,YAAY,CAACO,YAAY,CAAC0F,oBAAoB,CAACkC,YAAY;YACxE,MAAM,IAAIlG,qBAAa,CAAC,qBAAqBC,kBAAU,CAAC0C,WAAW;QACrE;IACF;IAEA,MAAc7D,wBAAwBC,KAAa,EAAEC,KAAa,EAAE;QAClE,MAAMmH,SAAS,MAAM,IAAI,CAACpI,YAAY,CAACO,YAAY,CAACwC,eAAe,CAAC/B,OAAOC;QAC3E,IAAImH,QAAQ;YACV,MAAM,IAAInG,qBAAa,CAAC,GAAGmG,OAAOpH,KAAK,KAAKA,QAAQ,UAAU,QAAQ,aAAa,CAAC,EAAEkB,kBAAU,CAAC0C,WAAW;QAC9G;IACF;IAlWA,YACE,AAAiByC,WAAwB,EACzC,AAAiBrH,YAA+B,CAChD;aAFiBqH,cAAAA;aACArH,eAAAA;aAJFuB,SAAS,IAAI8G,cAAM,CAACvI,kBAAkB2B,IAAI;IAKxD;AAgWL"}
1
+ {"version":3,"sources":["../../../../../backend/src/applications/users/services/admin-users-manager.service.ts"],"sourcesContent":["/*\n * Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com>\n * This file is part of Sync-in | The open source file sync and share solution\n * See the LICENSE file for licensing details\n */\n\nimport { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common'\nimport { FastifyReply } from 'fastify'\nimport { LoginResponseDto } from '../../../authentication/dto/login-response.dto'\nimport { AuthManager } from '../../../authentication/services/auth-manager.service'\nimport { anonymizePassword, hashPassword } from '../../../common/functions'\nimport { isPathExists, moveFiles, removeFiles } from '../../files/utils/files'\nimport { GROUP_TYPE } from '../constants/group'\nimport { USER_ROLE } from '../constants/user'\nimport type { CreateOrUpdateGroupDto } from '../dto/create-or-update-group.dto'\nimport type { CreateUserDto, UpdateUserDto, UpdateUserFromGroupDto } from '../dto/create-or-update-user.dto'\nimport type { DeleteUserDto } from '../dto/delete-user.dto'\nimport type { SearchMembersDto } from '../dto/search-members.dto'\nimport type { AdminGroup } from '../interfaces/admin-group.interface'\nimport type { AdminUser } from '../interfaces/admin-user.interface'\nimport type { GroupBrowse } from '../interfaces/group-browse.interface'\nimport type { GuestUser } from '../interfaces/guest-user.interface'\nimport type { Member } from '../interfaces/member.interface'\nimport { UserModel } from '../models/user.model'\nimport type { Group } from '../schemas/group.interface'\nimport type { User } from '../schemas/user.interface'\nimport { AdminUsersQueries } from './admin-users-queries.service'\n\n@Injectable()\nexport class AdminUsersManager {\n private readonly logger = new Logger(AdminUsersManager.name)\n\n constructor(\n private readonly authManager: AuthManager,\n private readonly adminQueries: AdminUsersQueries\n ) {}\n\n listUsers(): Promise<AdminUser[]> {\n return this.adminQueries.listUsers()\n }\n\n async getUser(userId: number): Promise<AdminUser> {\n const user: AdminUser = await this.adminQueries.listUsers(userId)\n this.checkUser(user, true)\n return user\n }\n\n async getGuest(guestId: number): Promise<GuestUser> {\n const user: GuestUser = await this.adminQueries.usersQueries.listGuests(guestId, 0, true)\n this.checkUser(user, true)\n return user\n }\n\n async createUserOrGuest(createUserDto: CreateUserDto, userRole: USER_ROLE.GUEST, asAdmin: boolean): Promise<GuestUser>\n async createUserOrGuest(createUserDto: CreateUserDto, userRole: USER_ROLE, asAdmin: true): Promise<AdminUser | GuestUser>\n async createUserOrGuest(createUserDto: CreateUserDto, userRole: USER_ROLE, asAdmin?: false): Promise<UserModel>\n async createUserOrGuest(\n createUserDto: CreateUserDto,\n userRole: USER_ROLE = USER_ROLE.USER,\n asAdmin = false\n ): Promise<UserModel | AdminUser | GuestUser> {\n await this.loginOrEmailAlreadyUsed(createUserDto.login, createUserDto.email)\n try {\n createUserDto.password = await hashPassword(createUserDto.password)\n const userId: number = await this.adminQueries.usersQueries.createUserOrGuest(createUserDto, userRole)\n const user = new UserModel({ ...createUserDto, id: userId, role: userRole })\n this.logger.log(\n `${this.createUserOrGuest.name} - ${USER_ROLE[userRole]} (${userId}) was created : ${JSON.stringify(anonymizePassword(createUserDto))}`\n )\n this.adminQueries.usersQueries.clearWhiteListCaches('*')\n await user.makePaths()\n if (userRole <= USER_ROLE.USER) {\n return asAdmin ? this.getUser(user.id) : user\n } else {\n return asAdmin ? this.getGuest(user.id) : user\n }\n } catch (e) {\n this.logger.error(`${this.createUserOrGuest.name} - unable to create user *${createUserDto.login}* : ${e}`)\n throw new HttpException('Unable to create user', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n async updateUserOrGuest(userId: number, updateUserDto: UpdateUserDto): Promise<AdminUser>\n async updateUserOrGuest(userId: number, updateUserDto: UpdateUserDto, userRole: USER_ROLE.GUEST): Promise<GuestUser>\n async updateUserOrGuest(\n userId: number,\n updateUserDto: UpdateUserDto,\n userRole: USER_ROLE.USER | USER_ROLE.GUEST = USER_ROLE.USER\n ): Promise<AdminUser | GuestUser> {\n const user: AdminUser & GuestUser = userRole === USER_ROLE.USER ? await this.getUser(userId) : await this.getGuest(userId)\n const updateUser: Partial<User> = {}\n const updateUserGroups: { add: number[]; delete: number[] } = { add: [], delete: [] }\n const updateGuestManagers: { add: number[]; delete: number[] } = { add: [], delete: [] }\n for (const [k, v] of Object.entries(updateUserDto)) {\n switch (k as keyof UpdateUserDto) {\n case 'login':\n if (user.login === v) {\n break\n }\n if (await this.adminQueries.usersQueries.checkUserExists(v)) {\n throw new HttpException('Login already used', HttpStatus.FORBIDDEN)\n }\n if (!(await this.renameUserSpace(user.login, v))) {\n throw new HttpException('Unable to rename user space', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n updateUser.login = v\n break\n case 'email':\n if (user.email === v) {\n break\n }\n if (await this.adminQueries.usersQueries.checkUserExists(null, v)) {\n throw new HttpException('Email already used', HttpStatus.FORBIDDEN)\n }\n updateUser.email = v\n break\n case 'isActive':\n updateUser.isActive = v\n if (v) {\n updateUser.passwordAttempts = 0\n }\n break\n case 'password':\n updateUser.password = await hashPassword(updateUserDto.password)\n break\n case 'groups':\n if (userRole === USER_ROLE.USER) {\n const currentGroups: number[] = user.groups?.length ? user.groups.map((g) => g.id) : []\n updateUserGroups.add = v.filter((id: number) => currentGroups.indexOf(id) === -1)\n updateUserGroups.delete = currentGroups.filter((id: number) => v.indexOf(id) === -1)\n }\n break\n case 'managers':\n if (userRole === USER_ROLE.GUEST) {\n const currentManagers: number[] = user.managers?.length ? user.managers.map((m) => m.id) : []\n updateGuestManagers.add = v.filter((id: number) => currentManagers.indexOf(id) === -1)\n updateGuestManagers.delete = currentManagers.filter((id: number) => v.indexOf(id) === -1)\n }\n break\n default:\n updateUser[k] = v\n }\n }\n if (Object.keys(updateUser).length) {\n // force the type for security reason\n const forceRole = userRole === USER_ROLE.GUEST ? USER_ROLE.GUEST : undefined\n if (!(await this.adminQueries.usersQueries.updateUserOrGuest(user.id, updateUser, forceRole))) {\n throw new HttpException('Unable to update user', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n if (userRole === USER_ROLE.USER) {\n if (updateUserGroups.add.length || updateUserGroups.delete.length) {\n try {\n await this.adminQueries.updateUserGroups(user.id, updateUserGroups)\n } catch {\n throw new HttpException('Unable to update user groups', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n return this.getUser(userId)\n } else {\n if (updateGuestManagers.add.length || updateGuestManagers.delete.length) {\n try {\n await this.adminQueries.updateGuestManagers(user.id, updateGuestManagers)\n } catch {\n throw new HttpException('Unable to update guest managers', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n return this.getGuest(userId)\n }\n }\n\n async deleteUserOrGuest(userId: number, userLogin: string, deleteUserDto: DeleteUserDto): Promise<void> {\n try {\n if (await this.adminQueries.deleteUser(userId, userLogin)) {\n this.logger.log(`${this.deleteUserOrGuest.name} - *${userLogin}* (${userId}) was deleted`)\n } else {\n this.logger.error(`${this.deleteUserOrGuest.name} - *${userLogin}* (${userId}) was not deleted : not found`)\n }\n if (deleteUserDto.deleteSpace) {\n await this.deleteUserSpace(userLogin, deleteUserDto.isGuest)\n }\n } catch (e) {\n this.logger.error(`${this.deleteUserOrGuest.name} - unable to delete *${userLogin}* (${userId}) : ${e}`)\n throw new HttpException('Unable to delete user', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n async deleteUserOrGuestFromAdmin(userId: number, deleteUserDto: DeleteUserDto): Promise<void> {\n const userToDelete: UserModel = this.checkUser(await this.adminQueries.usersQueries.from(userId))\n if (userToDelete.isGuest !== deleteUserDto.isGuest) {\n throw new HttpException('User mismatch', HttpStatus.BAD_REQUEST)\n }\n await this.deleteUserOrGuest(userToDelete.id, userToDelete.login, {\n deleteSpace: deleteUserDto.isGuest ? true : deleteUserDto.deleteSpace,\n isGuest: deleteUserDto.isGuest\n } satisfies DeleteUserDto)\n }\n\n listGuests(): Promise<AdminUser[]> {\n return this.adminQueries.usersQueries.listGuests(null, null, true)\n }\n\n createGuest(user: UserModel, createGuestDto: CreateUserDto): Promise<GuestUser> {\n if (!createGuestDto.managers.length) {\n createGuestDto.managers.push(user.id)\n }\n return this.createUserOrGuest(createGuestDto, USER_ROLE.GUEST, true)\n }\n\n updateGuest(guestId: number, updateGuestDto: UpdateUserDto): Promise<GuestUser> {\n if (!Object.keys(updateGuestDto).length) {\n throw new HttpException('No changes to update', HttpStatus.BAD_REQUEST)\n }\n if (updateGuestDto.managers && !updateGuestDto.managers.length) {\n throw new HttpException('Guest must have at least one manager', HttpStatus.BAD_REQUEST)\n }\n return this.updateUserOrGuest(guestId, updateGuestDto, USER_ROLE.GUEST)\n }\n\n async browseGroups(name?: string, type: GROUP_TYPE = GROUP_TYPE.USER): Promise<GroupBrowse> {\n if (name) {\n const group: Pick<Group, 'id' | 'name' | 'type'> = await this.adminQueries.groupFromName(name)\n if (!group) {\n throw new HttpException('Group not found', HttpStatus.NOT_FOUND)\n }\n return { parentGroup: group, members: await this.adminQueries.browseGroupMembers(group.id, type) }\n }\n return { parentGroup: undefined, members: await this.adminQueries.browseRootGroupMembers(type) }\n }\n\n async getGroup(groupId: number): Promise<AdminGroup> {\n const group = await this.adminQueries.groupFromId(groupId)\n if (!group) {\n throw new HttpException('Group not found', HttpStatus.NOT_FOUND)\n }\n return group\n }\n\n async createGroup(createGroupDto: CreateOrUpdateGroupDto): Promise<AdminGroup> {\n if (!createGroupDto.name) {\n this.logger.error(`${this.createGroup.name} - missing group name : ${JSON.stringify(createGroupDto)}`)\n throw new HttpException('Group name is missing', HttpStatus.BAD_REQUEST)\n }\n await this.checkGroupNameExists(createGroupDto.name)\n try {\n const groupId: number = await this.adminQueries.createGroup(createGroupDto)\n this.logger.log(`${this.createGroup.name} - group (${groupId}) was created : ${JSON.stringify(createGroupDto)}`)\n return this.adminQueries.groupFromId(groupId)\n } catch (e) {\n this.logger.error(`${this.createGroup.name} - group was not created : ${JSON.stringify(createGroupDto)} : ${e}`)\n throw new HttpException('Unable to create group', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n async updateGroup(groupId: number, updateGroupDto: CreateOrUpdateGroupDto): Promise<AdminGroup> {\n if (updateGroupDto.name) {\n await this.checkGroupNameExists(updateGroupDto.name)\n }\n if (!(await this.adminQueries.updateGroup(groupId, updateGroupDto))) {\n throw new HttpException('Unable to update group', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n // Clear whitelist caches when the group’s visibility is changed\n if (updateGroupDto.visibility !== undefined) {\n this.adminQueries.usersQueries.clearWhiteListCaches('*')\n }\n return this.adminQueries.groupFromId(groupId)\n }\n\n async deleteGroup(groupId: number): Promise<void> {\n if (await this.adminQueries.deleteGroup(groupId)) {\n this.logger.log(`${this.deleteGroup.name} - group (${groupId}) was deleted`)\n } else {\n this.logger.warn(`${this.deleteGroup.name} - group (${groupId}) does not exist`)\n throw new HttpException('Unable to delete group', HttpStatus.BAD_REQUEST)\n }\n }\n\n async addUsersToGroup(groupId: number, userIds: number[]): Promise<void> {\n const group: AdminGroup = await this.adminQueries.groupFromId(groupId)\n if (!group) {\n throw new HttpException('Group not found', HttpStatus.NOT_FOUND)\n }\n try {\n await this.adminQueries.addUsersToGroup(groupId, userIds, group.type === GROUP_TYPE.USER ? USER_ROLE.USER : undefined)\n } catch (e) {\n throw new HttpException(e.message, HttpStatus.BAD_REQUEST)\n }\n }\n\n async updateUserFromGroup(groupId: number, userId: number, updateUserFromGroupDto: UpdateUserFromGroupDto): Promise<void> {\n try {\n await this.adminQueries.updateUserFromGroup(groupId, userId, updateUserFromGroupDto.role)\n } catch (e) {\n throw new HttpException(e.message, HttpStatus.BAD_REQUEST)\n }\n }\n\n async removeUserFromGroup(groupId: number, userId: number): Promise<void> {\n try {\n await this.adminQueries.removeUserFromGroup(groupId, userId)\n } catch (e) {\n throw new HttpException(e.message, HttpStatus.BAD_REQUEST)\n }\n }\n\n searchMembers(searchMembersDto: SearchMembersDto): Promise<Member[]> {\n return this.adminQueries.usersQueries.searchUsersOrGroups(searchMembersDto)\n }\n\n async impersonateUser(admin: UserModel, userId: number, res: FastifyReply): Promise<LoginResponseDto> {\n if (admin.id === userId) {\n throw new HttpException('You are already logged in', HttpStatus.BAD_REQUEST)\n }\n const user: UserModel = this.checkUser(await this.adminQueries.usersQueries.from(userId))\n user.impersonatedFromId = admin.id\n user.impersonatedClientId = admin.clientId\n return this.authManager.setCookies(user, res)\n }\n\n async logoutImpersonateUser(user: UserModel, res: FastifyReply): Promise<LoginResponseDto> {\n if (!user.impersonatedFromId) {\n throw new HttpException('You are not allowed to do this action', HttpStatus.FORBIDDEN)\n }\n const admin: UserModel = this.checkUser(await this.adminQueries.usersQueries.from(user.impersonatedFromId))\n if (!admin.isAdmin) {\n throw new HttpException('You are not allowed to do this action', HttpStatus.FORBIDDEN)\n }\n admin.clientId = user.impersonatedClientId\n return this.authManager.setCookies(admin, res)\n }\n\n async deleteUserSpace(userLogin: string, isGuest = false): Promise<void> {\n const userSpace: string = UserModel.getHomePath(userLogin, isGuest)\n try {\n if (await isPathExists(userSpace)) {\n await removeFiles(userSpace)\n this.logger.log(`${this.deleteUserSpace.name} - user space *${userLogin}* was deleted`)\n } else {\n this.logger.warn(`${this.deleteUserSpace.name} - user space *${userLogin}* does not exist : ${userSpace}`)\n }\n } catch (e) {\n this.logger.warn(`${this.deleteUserSpace.name} - user space *${userLogin}* (${userSpace}) was not deleted : ${e}`)\n throw new HttpException('Unable to delete user space', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n checkUser(user: User | AdminUser | GuestUser, checkOnly: true): void\n checkUser(user: User | AdminUser | GuestUser, checkOnly?: false): UserModel\n checkUser(user: User | AdminUser | GuestUser, checkOnly = false): UserModel | void {\n if (!user) {\n throw new HttpException('User not found', HttpStatus.NOT_FOUND)\n }\n if (!checkOnly) {\n return new UserModel(user, true)\n }\n }\n\n private async renameUserSpace(oldLogin: string, newLogin: string): Promise<boolean> {\n const currentUserSpace: string = UserModel.getHomePath(oldLogin)\n if (!(await isPathExists(currentUserSpace))) {\n this.logger.warn(`${this.renameUserSpace.name} - user space *${oldLogin}* does not exist : ${currentUserSpace}`)\n return false\n }\n const newUserSpace: string = UserModel.getHomePath(newLogin)\n if (await isPathExists(newUserSpace)) {\n this.logger.warn(`${this.renameUserSpace.name} - user space *${newLogin}* already exists : ${newUserSpace}`)\n return false\n }\n try {\n await moveFiles(currentUserSpace, newUserSpace)\n return true\n } catch (e) {\n // try to restore\n await moveFiles(newUserSpace, currentUserSpace, true)\n this.logger.error(`${this.renameUserSpace.name} - unable to rename user space from *${currentUserSpace}* to *${newUserSpace}* : ${e}`)\n return false\n }\n }\n\n private async checkGroupNameExists(groupName: string): Promise<void> {\n if (await this.adminQueries.usersQueries.checkGroupNameExists(groupName)) {\n throw new HttpException('Name already used', HttpStatus.BAD_REQUEST)\n }\n }\n\n private async loginOrEmailAlreadyUsed(login: string, email: string) {\n const exists = await this.adminQueries.usersQueries.checkUserExists(login, email)\n if (exists) {\n throw new HttpException(`${exists.login === login ? 'Login' : 'Email'} already used`, HttpStatus.BAD_REQUEST)\n }\n }\n}\n"],"names":["AdminUsersManager","listUsers","adminQueries","getUser","userId","user","checkUser","getGuest","guestId","usersQueries","listGuests","createUserOrGuest","createUserDto","userRole","USER_ROLE","USER","asAdmin","loginOrEmailAlreadyUsed","login","email","password","hashPassword","UserModel","id","role","logger","log","name","JSON","stringify","anonymizePassword","clearWhiteListCaches","makePaths","e","error","HttpException","HttpStatus","INTERNAL_SERVER_ERROR","updateUserOrGuest","updateUserDto","updateUser","updateUserGroups","add","delete","updateGuestManagers","k","v","Object","entries","checkUserExists","FORBIDDEN","renameUserSpace","isActive","passwordAttempts","currentGroups","groups","length","map","g","filter","indexOf","GUEST","currentManagers","managers","m","keys","forceRole","undefined","deleteUserOrGuest","userLogin","deleteUserDto","deleteUser","deleteSpace","deleteUserSpace","isGuest","deleteUserOrGuestFromAdmin","userToDelete","from","BAD_REQUEST","createGuest","createGuestDto","push","updateGuest","updateGuestDto","browseGroups","type","GROUP_TYPE","group","groupFromName","NOT_FOUND","parentGroup","members","browseGroupMembers","browseRootGroupMembers","getGroup","groupId","groupFromId","createGroup","createGroupDto","checkGroupNameExists","updateGroup","updateGroupDto","visibility","deleteGroup","warn","addUsersToGroup","userIds","message","updateUserFromGroup","updateUserFromGroupDto","removeUserFromGroup","searchMembers","searchMembersDto","searchUsersOrGroups","impersonateUser","admin","res","impersonatedFromId","impersonatedClientId","clientId","authManager","setCookies","logoutImpersonateUser","isAdmin","userSpace","getHomePath","isPathExists","removeFiles","checkOnly","oldLogin","newLogin","currentUserSpace","newUserSpace","moveFiles","groupName","exists","Logger"],"mappings":"AAAA;;;;CAIC;;;;+BAyBYA;;;eAAAA;;;wBAvBiD;oCAGlC;2BACoB;uBACK;uBAC1B;sBACD;2BAUA;0CAGQ;;;;;;;;;;AAG3B,IAAA,AAAMA,oBAAN,MAAMA;IAQXC,YAAkC;QAChC,OAAO,IAAI,CAACC,YAAY,CAACD,SAAS;IACpC;IAEA,MAAME,QAAQC,MAAc,EAAsB;QAChD,MAAMC,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AtWA,YACE,AAAiB0C,WAAwB,EACzC,AAAiBtH,YAA+B,CAChD;aAFiBsH,cAAAA;aACAtH,eAAAA;aAJFuB,SAAS,IAAI+G,cAAM,CAACxI,kBAAkB2B,IAAI;IAKxD;AAoWL"}
@@ -16,6 +16,7 @@ const _common = require("@nestjs/common");
16
16
  const _fs = require("fs");
17
17
  const _authtwofaguard = require("../../authentication/guards/auth-two-fa-guard");
18
18
  const _authrequestinterface = require("../../authentication/interfaces/auth-request.interface");
19
+ const _sendfile = require("../files/utils/send-file");
19
20
  const _routes = require("./constants/routes");
20
21
  const _user = require("./constants/user");
21
22
  const _permissionsdecorator = require("./decorators/permissions.decorator");
@@ -29,6 +30,7 @@ const _permissionsguard = require("./guards/permissions.guard");
29
30
  const _rolesguard = require("./guards/roles.guard");
30
31
  const _usermodel = require("./models/user.model");
31
32
  const _usersmanagerservice = require("./services/users-manager.service");
33
+ const _avatar = require("./utils/avatar");
32
34
  function _ts_decorate(decorators, target, key, desc) {
33
35
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
34
36
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -72,7 +74,8 @@ let UsersController = class UsersController {
72
74
  const isMe = login === 'me';
73
75
  const [path, mime] = await this.usersManager.getAvatar(isMe ? user.login : login, false, isMe && user.role <= _user.USER_ROLE.USER);
74
76
  return new _common.StreamableFile((0, _fs.createReadStream)(path), {
75
- type: mime
77
+ type: mime,
78
+ disposition: (0, _sendfile.makeContentDispositionAttachment)(_avatar.USER_AVATAR_FILE_NAME)
76
79
  });
77
80
  }
78
81
  updateAvatar(req) {