@sync-in/server 1.7.0 → 1.8.1

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 (275) hide show
  1. package/CHANGELOG.md +173 -58
  2. package/environment/environment.dist.yaml +6 -3
  3. package/migrations/0003_giant_luckman.sql +6 -0
  4. package/migrations/meta/0003_snapshot.json +2463 -0
  5. package/migrations/meta/_journal.json +7 -0
  6. package/package.json +19 -17
  7. package/server/app.bootstrap.js +5 -2
  8. package/server/app.bootstrap.js.map +1 -1
  9. package/server/app.constants.js +0 -4
  10. package/server/app.constants.js.map +1 -1
  11. package/server/app.service.js +7 -6
  12. package/server/app.service.js.map +1 -1
  13. package/server/applications/files/constants/only-office.js +12 -0
  14. package/server/applications/files/constants/only-office.js.map +1 -1
  15. package/server/applications/files/files.config.js +5 -0
  16. package/server/applications/files/files.config.js.map +1 -1
  17. package/server/applications/files/files.controller.js +12 -4
  18. package/server/applications/files/files.controller.js.map +1 -1
  19. package/server/applications/files/files.controller.spec.js +18 -4
  20. package/server/applications/files/files.controller.spec.js.map +1 -1
  21. package/server/applications/files/services/files-content-manager.service.js +6 -6
  22. package/server/applications/files/services/files-content-manager.service.js.map +1 -1
  23. package/server/applications/files/services/files-manager.service.js +4 -4
  24. package/server/applications/files/services/files-manager.service.js.map +1 -1
  25. package/server/applications/files/services/files-methods.service.js +4 -7
  26. package/server/applications/files/services/files-methods.service.js.map +1 -1
  27. package/server/applications/files/services/files-only-office-manager.service.js +2 -2
  28. package/server/applications/files/services/files-only-office-manager.service.js.map +1 -1
  29. package/server/applications/files/services/files-parser.service.js +6 -3
  30. package/server/applications/files/services/files-parser.service.js.map +1 -1
  31. package/server/applications/files/services/files-scheduler.service.js +51 -3
  32. package/server/applications/files/services/files-scheduler.service.js.map +1 -1
  33. package/server/applications/files/services/files-search-manager.service.js +4 -0
  34. package/server/applications/files/services/files-search-manager.service.js.map +1 -1
  35. package/server/applications/files/utils/doc-textify/adapters/pdf.js +6 -8
  36. package/server/applications/files/utils/doc-textify/adapters/pdf.js.map +1 -1
  37. package/server/applications/notifications/i18n/de.js +56 -0
  38. package/server/applications/notifications/i18n/de.js.map +1 -0
  39. package/server/applications/notifications/i18n/es.js +52 -0
  40. package/server/applications/notifications/i18n/es.js.map +1 -0
  41. package/server/applications/notifications/i18n/hi.js +52 -0
  42. package/server/applications/notifications/i18n/hi.js.map +1 -0
  43. package/server/applications/notifications/i18n/index.js +73 -8
  44. package/server/applications/notifications/i18n/index.js.map +1 -1
  45. package/server/applications/notifications/i18n/it.js +52 -0
  46. package/server/applications/notifications/i18n/it.js.map +1 -0
  47. package/server/applications/notifications/i18n/ja.js +52 -0
  48. package/server/applications/notifications/i18n/ja.js.map +1 -0
  49. package/server/applications/notifications/i18n/ko.js +52 -0
  50. package/server/applications/notifications/i18n/ko.js.map +1 -0
  51. package/server/applications/notifications/i18n/pl.js +52 -0
  52. package/server/applications/notifications/i18n/pl.js.map +1 -0
  53. package/server/applications/notifications/i18n/pt.js +52 -0
  54. package/server/applications/notifications/i18n/pt.js.map +1 -0
  55. package/server/applications/notifications/i18n/pt_br.js +52 -0
  56. package/server/applications/notifications/i18n/pt_br.js.map +1 -0
  57. package/server/applications/notifications/i18n/ru.js +52 -0
  58. package/server/applications/notifications/i18n/ru.js.map +1 -0
  59. package/server/applications/notifications/i18n/tr.js +52 -0
  60. package/server/applications/notifications/i18n/tr.js.map +1 -0
  61. package/server/applications/notifications/i18n/zh.js +52 -0
  62. package/server/applications/notifications/i18n/zh.js.map +1 -0
  63. package/server/applications/notifications/mails/models.js +6 -7
  64. package/server/applications/notifications/mails/models.js.map +1 -1
  65. package/server/applications/notifications/services/notifications-manager.service.js.map +1 -1
  66. package/server/applications/shares/dto/create-or-update-share.dto.js +11 -0
  67. package/server/applications/shares/dto/create-or-update-share.dto.js.map +1 -1
  68. package/server/applications/shares/interfaces/share-props.interface.js.map +1 -1
  69. package/server/applications/shares/schemas/share.interface.js.map +1 -1
  70. package/server/applications/shares/schemas/shares.schema.js +9 -0
  71. package/server/applications/shares/schemas/shares.schema.js.map +1 -1
  72. package/server/applications/shares/services/shares-manager.service.js +46 -17
  73. package/server/applications/shares/services/shares-manager.service.js.map +1 -1
  74. package/server/applications/shares/services/shares-queries.service.js +24 -5
  75. package/server/applications/shares/services/shares-queries.service.js.map +1 -1
  76. package/server/applications/spaces/constants/cache.js +4 -0
  77. package/server/applications/spaces/constants/cache.js.map +1 -1
  78. package/server/applications/spaces/dto/create-or-update-space.dto.js +5 -0
  79. package/server/applications/spaces/dto/create-or-update-space.dto.js.map +1 -1
  80. package/server/applications/spaces/guards/space.guard.js +3 -3
  81. package/server/applications/spaces/guards/space.guard.js.map +1 -1
  82. package/server/applications/spaces/models/space-props.model.js.map +1 -1
  83. package/server/applications/spaces/models/space.model.js.map +1 -1
  84. package/server/applications/spaces/schemas/space.interface.js.map +1 -1
  85. package/server/applications/spaces/schemas/spaces.schema.js +1 -0
  86. package/server/applications/spaces/schemas/spaces.schema.js.map +1 -1
  87. package/server/applications/spaces/services/spaces-browser.service.js.map +1 -1
  88. package/server/applications/spaces/services/spaces-manager.service.js +34 -31
  89. package/server/applications/spaces/services/spaces-manager.service.js.map +1 -1
  90. package/server/applications/spaces/services/spaces-queries.service.js +23 -7
  91. package/server/applications/spaces/services/spaces-queries.service.js.map +1 -1
  92. package/server/applications/spaces/services/spaces-scheduler.service.js +21 -20
  93. package/server/applications/spaces/services/spaces-scheduler.service.js.map +1 -1
  94. package/server/applications/spaces/spaces.controller.js +4 -2
  95. package/server/applications/spaces/spaces.controller.js.map +1 -1
  96. package/server/applications/spaces/utils/paths.js +14 -16
  97. package/server/applications/spaces/utils/paths.js.map +1 -1
  98. package/server/applications/sync/services/sync-manager.service.js +4 -3
  99. package/server/applications/sync/services/sync-manager.service.js.map +1 -1
  100. package/server/applications/sync/services/sync-paths-manager.service.js +1 -1
  101. package/server/applications/sync/services/sync-paths-manager.service.js.map +1 -1
  102. package/server/applications/sync/services/sync-paths-manager.service.spec.js +1 -1
  103. package/server/applications/sync/services/sync-paths-manager.service.spec.js.map +1 -1
  104. package/server/applications/sync/sync.controller.js +2 -1
  105. package/server/applications/sync/sync.controller.js.map +1 -1
  106. package/server/applications/users/constants/routes.js +5 -0
  107. package/server/applications/users/constants/routes.js.map +1 -1
  108. package/server/applications/users/constants/user.js +0 -16
  109. package/server/applications/users/constants/user.js.map +1 -1
  110. package/server/applications/users/dto/user-properties.dto.js +10 -0
  111. package/server/applications/users/dto/user-properties.dto.js.map +1 -1
  112. package/server/applications/users/models/user.model.js.map +1 -1
  113. package/server/applications/users/schemas/user.interface.js.map +1 -1
  114. package/server/applications/users/schemas/users.schema.js +3 -2
  115. package/server/applications/users/schemas/users.schema.js.map +1 -1
  116. package/server/applications/users/services/admin-users-manager.service.js +1 -0
  117. package/server/applications/users/services/admin-users-manager.service.js.map +1 -1
  118. package/server/applications/users/services/admin-users-manager.service.spec.js +2 -1
  119. package/server/applications/users/services/admin-users-manager.service.spec.js.map +1 -1
  120. package/server/applications/users/services/users-manager.service.js +7 -2
  121. package/server/applications/users/services/users-manager.service.js.map +1 -1
  122. package/server/applications/users/services/users-manager.service.spec.js +1 -0
  123. package/server/applications/users/services/users-manager.service.spec.js.map +1 -1
  124. package/server/applications/users/services/users-queries.service.js +18 -4
  125. package/server/applications/users/services/users-queries.service.js.map +1 -1
  126. package/server/applications/users/users.controller.js +15 -0
  127. package/server/applications/users/users.controller.js.map +1 -1
  128. package/server/applications/users/users.gateway.js +6 -0
  129. package/server/applications/users/users.gateway.js.map +1 -1
  130. package/server/applications/users/utils/test.js +2 -2
  131. package/server/applications/users/utils/test.js.map +1 -1
  132. package/server/applications/webdav/constants/routes.js +2 -2
  133. package/server/applications/webdav/constants/routes.js.map +1 -1
  134. package/server/applications/webdav/constants/webdav.js +2 -2
  135. package/server/applications/webdav/constants/webdav.js.map +1 -1
  136. package/server/applications/webdav/filters/webdav.filter.js +2 -2
  137. package/server/applications/webdav/filters/webdav.filter.js.map +1 -1
  138. package/server/applications/webdav/filters/webdav.filter.spec.js +2 -2
  139. package/server/applications/webdav/filters/webdav.filter.spec.js.map +1 -1
  140. package/server/applications/webdav/services/webdav-methods.service.js +3 -2
  141. package/server/applications/webdav/services/webdav-methods.service.js.map +1 -1
  142. package/server/applications/webdav/utils/webdav.js +1 -2
  143. package/server/applications/webdav/utils/webdav.js.map +1 -1
  144. package/server/authentication/auth.config.js +2 -2
  145. package/server/authentication/auth.config.js.map +1 -1
  146. package/server/authentication/guards/auth-basic.strategy.js +2 -2
  147. package/server/authentication/guards/auth-basic.strategy.js.map +1 -1
  148. package/server/common/i18n.js +52 -0
  149. package/server/common/i18n.js.map +1 -0
  150. package/server/common/image.js +63 -43
  151. package/server/common/image.js.map +1 -1
  152. package/server/common/interfaces.js.map +1 -1
  153. package/server/common/shared.js +5 -2
  154. package/server/common/shared.js.map +1 -1
  155. package/server/configuration/config.validation.js +3 -3
  156. package/server/configuration/config.validation.js.map +1 -1
  157. package/server/infrastructure/cache/adapters/mysql-cache.adapter.js +8 -6
  158. package/server/infrastructure/cache/adapters/mysql-cache.adapter.js.map +1 -1
  159. package/server/infrastructure/cache/adapters/redis-cache.adapter.js +22 -17
  160. package/server/infrastructure/cache/adapters/redis-cache.adapter.js.map +1 -1
  161. package/server/infrastructure/cache/cache.e2e-spec.js +1 -0
  162. package/server/infrastructure/cache/cache.e2e-spec.js.map +1 -1
  163. package/server/infrastructure/cache/cache.module.js +1 -14
  164. package/server/infrastructure/cache/cache.module.js.map +1 -1
  165. package/server/infrastructure/cache/services/cache.service.js.map +1 -1
  166. package/server/infrastructure/database/database.module.js +20 -1
  167. package/server/infrastructure/database/database.module.js.map +1 -1
  168. package/server/infrastructure/database/utils.js +48 -0
  169. package/server/infrastructure/database/utils.js.map +1 -1
  170. package/server/infrastructure/scheduler/scheduler.module.js +1 -1
  171. package/server/infrastructure/scheduler/scheduler.module.js.map +1 -1
  172. package/server/infrastructure/websocket/adapters/cluster.adapter.js +1 -3
  173. package/server/infrastructure/websocket/adapters/cluster.adapter.js.map +1 -1
  174. package/static/3rdpartylicenses.txt +137 -163
  175. package/static/chunk-2KLC4T2Z.js +1 -0
  176. package/static/chunk-2VMSXRCB.js +12 -0
  177. package/static/chunk-3GMLWAFZ.js +1 -0
  178. package/static/chunk-3OHSRRKH.js +4 -0
  179. package/static/chunk-3R4WKOHQ.js +1 -0
  180. package/static/{chunk-7ITZXYYJ.js → chunk-3R74L4UU.js} +1 -1
  181. package/static/chunk-3XVM35O2.js +1 -0
  182. package/static/chunk-3YVRP3VM.js +2 -0
  183. package/static/chunk-5NMSIIQB.js +1 -0
  184. package/static/chunk-5UKZLU5H.js +1 -0
  185. package/static/chunk-AF24EYXU.js +1 -0
  186. package/static/chunk-AKQVEHO6.js +2 -0
  187. package/static/chunk-BCVX464U.js +2 -0
  188. package/static/chunk-BQV4FRM6.js +1 -0
  189. package/static/{chunk-EVIE5F2U.js → chunk-CETH7UYS.js} +1 -1
  190. package/static/chunk-CHJ64RJM.js +1 -0
  191. package/static/chunk-DIT6W7VM.js +562 -0
  192. package/static/chunk-DKSEQTMX.js +1 -0
  193. package/static/chunk-DM4NXKEP.js +1 -0
  194. package/static/chunk-DPUVSXRB.js +1 -0
  195. package/static/chunk-DSWEWLXJ.js +1 -0
  196. package/static/chunk-FJE6BOFL.js +1 -0
  197. package/static/chunk-FZ3JPGYZ.js +1 -0
  198. package/static/chunk-IQSKQXC3.js +1 -0
  199. package/static/chunk-ITUFI2BJ.js +1 -0
  200. package/static/chunk-JPT5WEAT.js +1 -0
  201. package/static/chunk-LCTZJ537.js +1 -0
  202. package/static/chunk-LK2UCQJ6.js +1 -0
  203. package/static/chunk-LNTUR3GU.js +1 -0
  204. package/static/chunk-LP5TBXEN.js +7 -0
  205. package/static/{chunk-IPAC4VAF.js → chunk-LVSNIS5P.js} +1 -1
  206. package/static/{chunk-SIPE37PA.js → chunk-MTVSJTIW.js} +1 -1
  207. package/static/chunk-N3U6637P.js +1 -0
  208. package/static/chunk-NNV4OXSB.js +1 -0
  209. package/static/chunk-O6FYXVHI.js +1 -0
  210. package/static/chunk-OOGP4WSH.js +2 -0
  211. package/static/chunk-PB4AIT7O.js +1 -0
  212. package/static/chunk-PCWDQPOM.js +2 -0
  213. package/static/chunk-PNR6M34W.js +1 -0
  214. package/static/chunk-PVDHBQRM.js +1 -0
  215. package/static/chunk-Q5KM7LTX.js +1 -0
  216. package/static/chunk-QHC6ZPQ4.js +1 -0
  217. package/static/chunk-QMRBZHE4.js +1 -0
  218. package/static/chunk-QO6BTONN.js +1 -0
  219. package/static/chunk-QSJRY3TF.js +1 -0
  220. package/static/chunk-QUUIRSYT.js +1 -0
  221. package/static/chunk-RFH46UW3.js +1 -0
  222. package/static/{chunk-PTGDOWV3.js → chunk-RSXHRKM5.js} +1 -1
  223. package/static/chunk-RV3VZJPZ.js +1 -0
  224. package/static/{chunk-QNJFQVYI.js → chunk-S7HNXVRB.js} +1 -1
  225. package/static/chunk-SBZ572Q4.js +2 -0
  226. package/static/chunk-SJR5R3Y4.js +1 -0
  227. package/static/chunk-SLHTEGRU.js +1 -0
  228. package/static/{chunk-SH5EVL4E.js → chunk-SSFF27P2.js} +1 -1
  229. package/static/chunk-UNCPXHHT.js +1 -0
  230. package/static/chunk-URHTCJ7G.js +1 -0
  231. package/static/chunk-V3LHHZYN.js +1 -0
  232. package/static/{chunk-DJYJ66UF.js → chunk-VJTXJ43D.js} +1 -1
  233. package/static/chunk-VQQKMY2C.js +1 -0
  234. package/static/{chunk-IQOALFYU.js → chunk-WSSU2HXE.js} +1 -1
  235. package/static/chunk-XDZGW64M.js +3 -0
  236. package/static/chunk-XTRDKGKG.js +1 -0
  237. package/static/chunk-YLWTEC3X.js +1 -0
  238. package/static/chunk-Z5J5F5SX.js +1 -0
  239. package/static/chunk-ZIJQRARU.js +1 -0
  240. package/static/index.html +2 -2
  241. package/static/main-4H5BJY3J.js +9 -0
  242. package/static/scripts-WRDOQIU5.js +24 -0
  243. package/static/{styles-A5VYX3CE.css → styles-2C2UNCNB.css} +1 -1
  244. package/server/applications/spaces/interfaces/space-quota.interface.js +0 -10
  245. package/server/applications/spaces/interfaces/space-quota.interface.js.map +0 -1
  246. package/static/chunk-22EANI6R.js +0 -1
  247. package/static/chunk-3GFGJYMK.js +0 -1
  248. package/static/chunk-4YGJGZZZ.js +0 -1
  249. package/static/chunk-5K7HEX3C.js +0 -27
  250. package/static/chunk-5KLMS6A4.js +0 -1
  251. package/static/chunk-ATP3BFHV.js +0 -562
  252. package/static/chunk-BB4G55KE.js +0 -1
  253. package/static/chunk-EWKSX76T.js +0 -1
  254. package/static/chunk-FHLACA7V.js +0 -1
  255. package/static/chunk-GCATNU55.js +0 -1
  256. package/static/chunk-GYODPCIE.js +0 -1
  257. package/static/chunk-HZTFYLM5.js +0 -1
  258. package/static/chunk-JSUKJT6Z.js +0 -1
  259. package/static/chunk-JXZCNFW7.js +0 -1
  260. package/static/chunk-LTGFCQR7.js +0 -1
  261. package/static/chunk-LV3PYKWO.js +0 -1
  262. package/static/chunk-N2WFNW6M.js +0 -7
  263. package/static/chunk-ORMRCEGT.js +0 -1
  264. package/static/chunk-OUTBJSMW.js +0 -1
  265. package/static/chunk-RS2PX32L.js +0 -1
  266. package/static/chunk-RSSWH3S2.js +0 -1
  267. package/static/chunk-RTRJ3KFH.js +0 -1
  268. package/static/chunk-TKTCBDOG.js +0 -1
  269. package/static/chunk-V6K2N46L.js +0 -1
  270. package/static/chunk-XLCCZSQL.js +0 -4
  271. package/static/chunk-YPEH66GG.js +0 -1
  272. package/static/chunk-YPOIUQ57.js +0 -1
  273. package/static/chunk-ZKCFO2OA.js +0 -4
  274. package/static/main-MZ7HWZXO.js +0 -9
  275. package/static/scripts-VZVAP2P4.js +0 -30
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../backend/src/applications/shares/services/shares-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 path from 'node:path'\nimport { ACTION } from '../../../common/constants'\nimport {\n anonymizePassword,\n convertDiffUpdate,\n diffCollection,\n differencePermissions,\n generateShortUUID,\n hashPassword,\n intersectPermissions\n} from '../../../common/functions'\nimport type { Entries } from '../../../common/interfaces'\nimport { ContextManager } from '../../../infrastructure/context/services/context-manager.service'\nimport type { FileProps } from '../../files/interfaces/file-props.interface'\nimport { FileError } from '../../files/models/file-error'\nimport { checkExternalPath, getProps, isPathExists } from '../../files/utils/files'\nimport { LINK_TYPE } from '../../links/constants/links'\nimport type { CreateOrUpdateLinkDto } from '../../links/dto/create-or-update-link.dto'\nimport type { LinkGuest } from '../../links/interfaces/link-guest.interface'\nimport type { Link } from '../../links/schemas/link.interface'\nimport { LinksQueries } from '../../links/services/links-queries.service'\nimport { NOTIFICATION_APP, NOTIFICATION_APP_EVENT } from '../../notifications/constants/notifications'\nimport type { NotificationContent, NotificationOptions } from '../../notifications/interfaces/notification-properties.interface'\nimport type { UserMailNotification } from '../../notifications/interfaces/user-mail-notification'\nimport { NotificationsManager } from '../../notifications/services/notifications-manager.service'\nimport { SPACE_OPERATION, SPACE_PERMS_SEP, SPACE_REPOSITORY, SPACE_ROLE } from '../../spaces/constants/spaces'\nimport type { SpaceMemberDto } from '../../spaces/dto/create-or-update-space.dto'\nimport { SpaceEnv } from '../../spaces/models/space-env.model'\nimport type { SpaceProps } from '../../spaces/models/space-props.model'\nimport { SpacesQueries } from '../../spaces/services/spaces-queries.service'\nimport { havePermission, haveSpacePermission, removePermissions } from '../../spaces/utils/permissions'\nimport { MEMBER_TYPE } from '../../users/constants/member'\nimport { GUEST_PERMISSION, USER_NOTIFICATION, USER_ROLE } from '../../users/constants/user'\nimport { CreateUserDto } from '../../users/dto/create-or-update-user.dto'\nimport { UserModel } from '../../users/models/user.model'\nimport type { User } from '../../users/schemas/user.interface'\nimport { UsersQueries } from '../../users/services/users-queries.service'\nimport { SHARE_ALL_OPERATIONS, SHARE_TYPE } from '../constants/shares'\nimport type { CreateOrUpdateShareDto, ShareMemberDto } from '../dto/create-or-update-share.dto'\nimport type { ShareChildMember } from '../interfaces/share-child.interface'\nimport type { ShareEnv } from '../interfaces/share-env.interface'\nimport type { ShareFile } from '../interfaces/share-file.interface'\nimport type { ShareLink } from '../interfaces/share-link.interface'\nimport type { ShareProps } from '../interfaces/share-props.interface'\nimport type { ShareChild } from '../models/share-child.model'\nimport type { ShareMembers } from '../schemas/share-members.interface'\nimport type { Share } from '../schemas/share.interface'\nimport { SharesQueries } from './shares-queries.service'\n\n@Injectable()\nexport class SharesManager {\n private readonly logger = new Logger(SharesManager.name)\n\n constructor(\n private readonly contextManager: ContextManager,\n private readonly notificationsManager: NotificationsManager,\n private readonly sharesQueries: SharesQueries,\n private readonly spaceQueries: SpacesQueries,\n private readonly usersQueries: UsersQueries,\n private readonly linksQueries: LinksQueries\n ) {}\n\n permissions(user: UserModel, spaceAlias: string) {\n return this.sharesQueries.permissions(user.id, spaceAlias, +user.isAdmin)\n }\n\n listShares(user: UserModel): Promise<ShareFile[]> {\n return this.sharesQueries.listShares(user)\n }\n\n listSpaceShares(spaceId: number): Promise<ShareChild[]> {\n return this.sharesQueries.listSpaceShares(spaceId)\n }\n\n listChildShares(user: UserModel, shareId: number): Promise<ShareChild[]> {\n return this.sharesQueries.listChildShares(user.id, shareId, +user.isAdmin)\n }\n\n async setAllowedPermissions(user: UserModel, share: ShareProps | ShareLink, asAdmin = false) {\n if (share.file?.ownerId === user.id || (share.externalPath && user.isAdmin)) {\n // current user is the file owner (personal space case)\n share.file.permissions = SHARE_ALL_OPERATIONS\n } else if (share.file?.space?.alias) {\n share.file.ownerId = null\n // retrieve space permissions (cached query)\n const spacePermissions: Partial<SpaceEnv> = await this.spaceQueries.permissions(user.id, share.file.space.alias, share.file.space.root?.alias)\n if (!spacePermissions) {\n this.logger.warn(`${this.setAllowedPermissions.name} - missing space permissions : ${JSON.stringify(share)}`)\n throw new HttpException('Space not found', HttpStatus.NOT_FOUND)\n }\n // compute permissions\n const spaceEnv = new SpaceEnv(spacePermissions)\n spaceEnv.setPermissions(true)\n share.file.permissions = spaceEnv.envPermissions\n } else if (share.parent?.alias) {\n // retrieve parent share permissions (cached query)\n // use current the user permissions on the share or the share owner permissions if we request the share as admin\n const userId = asAdmin ? share.ownerId : user.id\n const sharePermissions: Partial<SpaceEnv> = await this.sharesQueries.permissions(userId, share.parent.alias, +user.isAdmin)\n if (!sharePermissions) {\n this.logger.warn(`${this.setAllowedPermissions.name} - missing share permissions : ${JSON.stringify(share)}`)\n throw new HttpException('Share not found', HttpStatus.NOT_FOUND)\n }\n share.file.permissions = sharePermissions.permissions\n } else {\n this.logger.error(`${this.setAllowedPermissions.name} - case not handled ${JSON.stringify(share)}`)\n throw new HttpException('Missing information', HttpStatus.BAD_REQUEST)\n }\n }\n\n async getShareWithMembers(user: UserModel, shareId: number, asAdmin = false): Promise<ShareProps> {\n // asAdmin : true if the user is the owner of the parent share or if the share is requested from the administration\n const share: ShareProps = await this.sharesQueries.getShareWithMembers(user, shareId, asAdmin)\n if (!share) {\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n await this.setAllowedPermissions(user, share, asAdmin)\n return share\n }\n\n async createShare(user: UserModel, createOrUpdateShareDto: CreateOrUpdateShareDto): Promise<ShareProps> {\n const share: Partial<Share> = {\n name: createOrUpdateShareDto.name,\n alias: await this.sharesQueries.uniqueShareAlias(createOrUpdateShareDto.name),\n description: createOrUpdateShareDto.description,\n externalPath: createOrUpdateShareDto.externalPath,\n enabled: createOrUpdateShareDto.enabled,\n disabledAt: createOrUpdateShareDto.enabled ? null : new Date(),\n type: createOrUpdateShareDto.type || SHARE_TYPE.COMMON\n }\n if (share.externalPath) {\n /* EXTERNAL PATH CASE */\n if (!user.isAdmin) {\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n try {\n await checkExternalPath(share.externalPath)\n } catch (e: any) {\n throw new HttpException(e.message, e instanceof FileError ? e.httpCode : HttpStatus.INTERNAL_SERVER_ERROR)\n }\n share.ownerId = null\n } else {\n /* SPACES CASE */\n share.externalPath = null\n share.ownerId = user.id\n if (createOrUpdateShareDto.file.ownerId) {\n /* PERSONAL SPACE CASE */\n // check file\n const realPath = path.join(user.filesPath, createOrUpdateShareDto.file.path)\n if (!(await isPathExists(realPath))) {\n this.logger.warn(`${this.createShare.name} - location does not exist : ${realPath}`)\n throw new HttpException('The location does not exist', HttpStatus.NOT_FOUND)\n }\n const fileProps: FileProps = { ...(await getProps(realPath, createOrUpdateShareDto.file.path)), id: createOrUpdateShareDto.file.id }\n share.fileId = await this.spaceQueries.getOrCreateUserFile(user.id, fileProps)\n } else if (createOrUpdateShareDto.file.space?.alias) {\n /* SPACE CASE */\n const spacePermissions: Partial<SpaceEnv> = await this.spaceQueries.permissions(\n user.id,\n createOrUpdateShareDto.file.space.alias,\n createOrUpdateShareDto.file.space.root.alias\n )\n if (!spacePermissions) {\n throw new HttpException('Space not found', HttpStatus.NOT_FOUND)\n }\n // compute space permissions\n const space: SpaceEnv = new SpaceEnv(spacePermissions)\n space.setPermissions(true)\n // intersect space permissions for members\n for (const m of createOrUpdateShareDto.members) {\n m.permissions = intersectPermissions(space.envPermissions, m.permissions)\n }\n // intersect space permissions for links\n for (const l of createOrUpdateShareDto.links) {\n l.permissions = intersectPermissions(space.envPermissions, l.permissions)\n }\n // check file\n try {\n space.setPaths(user, createOrUpdateShareDto.file.space.root.alias, createOrUpdateShareDto.file.path.split('/').slice(space.root.id ? 1 : 0))\n } catch (e) {\n if (e instanceof FileError) {\n throw new HttpException(e.message, e.httpCode)\n }\n throw new HttpException(e.message, HttpStatus.BAD_REQUEST)\n }\n if (!(await isPathExists(space.realPath))) {\n this.logger.warn(`${this.createShare.name} - space location does not exist : *${space.alias}* (${space.id}) : ${space.realPath}`)\n throw new HttpException('The location does not exist', HttpStatus.NOT_FOUND)\n }\n share.spaceId = space.id\n share.spaceRootId = space.root?.id || null\n // define share.fileId\n // if the file is the same as the space root, ignores share.fileId and only uses spaceId and spaceRootId\n const isExternalSpaceRoot =\n createOrUpdateShareDto.file?.id < 0 &&\n createOrUpdateShareDto.file?.path === createOrUpdateShareDto.file?.space?.root?.alias &&\n createOrUpdateShareDto.file?.space?.root?.alias === spacePermissions.root?.alias &&\n createOrUpdateShareDto.file?.space?.root?.name === spacePermissions.root?.name\n const isSpaceRoot = Number(createOrUpdateShareDto.file.id) === Number(spacePermissions.root?.file?.id)\n if (!isSpaceRoot && !isExternalSpaceRoot) {\n const fileProps: FileProps = { ...(await getProps(space.realPath, space.dbFile.path)), id: undefined }\n // get or create file id\n share.fileId = await this.spaceQueries.getOrCreateSpaceFile(createOrUpdateShareDto.file.id, fileProps, space.dbFile)\n }\n } else {\n // unexpected case\n throw new HttpException('Missing information', HttpStatus.BAD_REQUEST)\n }\n }\n // create share\n share.id = await this.sharesQueries.createShare(share)\n // check & update members\n await this.createOrUpdateLinksAsMembers(user, share, LINK_TYPE.SHARE, createOrUpdateShareDto.links)\n await this.updateMembers(user, share, [], createOrUpdateShareDto.members)\n return this.getShareWithMembers(user, share.id)\n }\n\n async updateShare(user: UserModel, shareId: number, createOrUpdateShareDto: CreateOrUpdateShareDto, asAdmin = false): Promise<ShareProps> {\n // asAdmin : true if the user is the owner of the parent share or if the share is requested from the administration\n const share: ShareProps = await this.getShareWithMembers(user, shareId, asAdmin)\n // check & update share info\n const shareDiffProps: Partial<ShareProps> = { modifiedAt: new Date() }\n for (const prop of ['name', 'description', 'enabled']) {\n if (createOrUpdateShareDto[prop] !== share[prop]) {\n shareDiffProps[prop] = createOrUpdateShareDto[prop]\n if (prop === 'name') {\n shareDiffProps.alias = await this.sharesQueries.uniqueShareAlias(shareDiffProps.name)\n } else if (prop === 'enabled') {\n shareDiffProps.disabledAt = shareDiffProps[prop] ? null : new Date()\n }\n }\n }\n // update in db\n this.sharesQueries.updateShare(shareDiffProps, { id: shareId }).catch((e: Error) => this.logger.error(`${this.updateShare.name} - ${e}`))\n // check & update members\n const linkMembers: ShareMemberDto[] = await this.createOrUpdateLinksAsMembers(user, share, LINK_TYPE.SHARE, createOrUpdateShareDto.links)\n // intersect share permissions for members\n for (const m of createOrUpdateShareDto.members) {\n m.permissions = intersectPermissions(share.file.permissions, m.permissions)\n }\n // intersect share permissions for links\n for (const l of linkMembers) {\n l.permissions = intersectPermissions(share.file.permissions, l.permissions)\n }\n await this.updateMembers(user, share, share.members, [...createOrUpdateShareDto.members, ...linkMembers])\n return this.getShareWithMembers(user, share.id, asAdmin)\n }\n\n async deleteShare(user: UserModel, shareId: number, asAdmin = false): Promise<void> {\n // asAdmin : true if the user is the owner of the parent share or if the share is requested from an admin\n if (!asAdmin && !user.isAdmin && !(await this.sharesQueries.shareExistsForOwner(user.id, shareId))) {\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n try {\n await this.deleteAllLinkMembers(shareId, LINK_TYPE.SHARE)\n await this.removeShareFromOwners(shareId, 'all', false, user.id)\n } catch (e) {\n this.logger.error(`${this.deleteShare.name} - unable to delete share (${shareId}) (asAdmin = ${asAdmin}) : ${e}`)\n throw new HttpException('Unable to delete share', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n async getChildShare(user: UserModel, shareId: number, childId: number, isLink?: false): Promise<ShareProps>\n async getChildShare(user: UserModel, shareId: number, childId: number, isLink?: true): Promise<ShareLink>\n async getChildShare(user: UserModel, shareId: number, childId: number, isLink?: boolean): Promise<ShareProps | ShareLink> {\n if (await this.checkChildSharePermissions(user, shareId, childId)) {\n if (isLink) {\n return this.getShareLink(user, childId, true)\n }\n return this.getShareWithMembers(user, childId, true)\n }\n }\n\n async updateChildShare(user: UserModel, shareId: number, childId: number, createOrUpdateShareDto: CreateOrUpdateShareDto): Promise<ShareProps> {\n if (await this.checkChildSharePermissions(user, shareId, childId)) {\n return this.updateShare(user, childId, createOrUpdateShareDto, true)\n }\n }\n\n async deleteChildShare(user: UserModel, shareId: number, childId: number): Promise<void> {\n if (await this.checkChildSharePermissions(user, shareId, childId)) {\n return this.deleteShare(user, childId, true)\n }\n }\n\n async createChildShare(user: UserModel, createOrUpdateShareDto: CreateOrUpdateShareDto): Promise<ShareProps> {\n // check parent share\n const pSharePermissions = await this.sharesQueries.permissions(user.id, createOrUpdateShareDto.parent.alias, +user.isAdmin)\n if (!pSharePermissions) {\n this.logger.warn(`${this.createChildShare.name} - parent share does not exist or not authorized : ${createOrUpdateShareDto.parent.alias}`)\n throw new HttpException('Parent share not found', HttpStatus.NOT_FOUND)\n }\n if (!haveSpacePermission(pSharePermissions, SPACE_OPERATION.SHARE_OUTSIDE)) {\n this.logger.warn(`${this.createChildShare.name} - is not allowed to share outside of : *${pSharePermissions.alias}* (${pSharePermissions.id})`)\n throw new HttpException('You are not allowed to do this action', HttpStatus.FORBIDDEN)\n }\n if (!pSharePermissions.enabled) {\n this.logger.warn(`${this.createChildShare.name} - parent share is disabled : ${createOrUpdateShareDto.parent.alias}`)\n throw new HttpException('Parent share is disabled', HttpStatus.FORBIDDEN)\n }\n\n let pShare: Partial<SpaceEnv>\n let filePath: string\n if (pSharePermissions.root.externalPath) {\n const highestParentId = await this.sharesQueries.findHighestParentShare(pSharePermissions.id)\n if (!highestParentId) {\n this.logger.warn(\n `${this.createChildShare.name} - unable to find the highest parent of : *${pSharePermissions.alias}* (${pSharePermissions.id})`\n )\n throw new HttpException('Parent share not found', HttpStatus.NOT_FOUND)\n }\n pShare = await this.sharesQueries.shareEnv(highestParentId)\n filePath = path.join(pSharePermissions.root?.file?.path || '', createOrUpdateShareDto.file.path)\n } else {\n pShare = await this.sharesQueries.shareEnv(pSharePermissions.id)\n filePath = createOrUpdateShareDto.file.path\n }\n\n // create a fake space env -> share env\n const pShareEnv: Partial<ShareEnv> = new SpaceEnv(pShare, null, false)\n try {\n pShareEnv.setPaths(user, null, filePath.split('/'))\n } catch (e) {\n if (e instanceof FileError) {\n throw new HttpException(e.message, e.httpCode)\n }\n throw new HttpException(e.message, HttpStatus.BAD_REQUEST)\n }\n // check file\n if (!(await isPathExists(pShareEnv.realPath))) {\n this.logger.warn(\n `${this.createChildShare.name} - parent share location does not exist : ${pShareEnv.alias} (${pShareEnv.id}) : ${pShareEnv.realPath}`\n )\n throw new HttpException('The location does not exist', HttpStatus.NOT_FOUND)\n }\n\n /* Manage the case where the child share is created from the parent share itself */\n // special case, the parent share is directly linked to the space root file\n const isLinkedToShareSpaceRoot =\n pShareEnv.fileId === null &&\n Number(createOrUpdateShareDto.file.id) === Number(pSharePermissions.root?.id) &&\n createOrUpdateShareDto.file.path === '.'\n // special case, the parent share is directly linked to the share with an external path\n const isLinkedToShareExternalPath =\n createOrUpdateShareDto.file.id < 0 && !!pShareEnv.root.externalPath && createOrUpdateShareDto.file.path === '.'\n let fileId: number = null\n if (!isLinkedToShareSpaceRoot && !isLinkedToShareExternalPath) {\n // fileId is mandatory for a file in a child share\n const fileProps: FileProps = { ...(await getProps(pShareEnv.realPath, pShareEnv.dbFile.path)), id: undefined }\n fileId = await this.spaceQueries.getOrCreateSpaceFile(createOrUpdateShareDto.file.id, fileProps, pShareEnv.dbFile)\n }\n\n const share: Partial<Share> = {\n name: createOrUpdateShareDto.name,\n alias: await this.sharesQueries.uniqueShareAlias(createOrUpdateShareDto.name),\n ownerId: user.id,\n spaceId: pShareEnv.spaceId,\n spaceRootId: pShareEnv.spaceRootId,\n parentId: pSharePermissions.id,\n fileId: fileId,\n description: createOrUpdateShareDto.description,\n externalPath: pShareEnv.root.externalPath,\n enabled: createOrUpdateShareDto.enabled,\n disabledAt: createOrUpdateShareDto.enabled ? null : new Date(),\n type: createOrUpdateShareDto.type || SHARE_TYPE.COMMON\n }\n // create child share\n share.id = await this.sharesQueries.createShare(share)\n // intersect parent share permissions for members\n for (const m of createOrUpdateShareDto.members) {\n m.permissions = intersectPermissions(pSharePermissions.permissions, m.permissions)\n }\n // intersect parent share permissions for links\n for (const l of createOrUpdateShareDto.links) {\n l.permissions = intersectPermissions(pSharePermissions.permissions, l.permissions)\n }\n // check & update members\n await this.createOrUpdateLinksAsMembers(user, share, LINK_TYPE.SHARE, createOrUpdateShareDto.links)\n await this.updateMembers(user, share, [], createOrUpdateShareDto.members)\n return this.getShareWithMembers(user, share.id)\n }\n\n async updateSharesFromSpace(\n /*\n In this case the space is considered as a parent share\n The shares and child shares of the member should be deleted if the member is removed from the space\n Member permissions on shares and its child shares must be updated if the parent share owner's permissions are updated on the space\n */\n spaceId: number,\n currentMembers: SpaceMemberDto[],\n toRemove: SpaceMemberDto[],\n toUpdate: { object: SpaceMemberDto; rmPermissions: SPACE_OPERATION[] }[]\n ) {\n // skip if no actions\n if (!toRemove.length && !toUpdate.length) return\n // get all space manager ids (ignore them, they have all permissions on the space)\n const spaceManagerIds: number[] = currentMembers.filter((m) => m.spaceRole === SPACE_ROLE.IS_MANAGER).map((m) => m.id)\n const [rmOwners, upOwners] = await this.diffSharesPermissions(currentMembers, toRemove, toUpdate, spaceManagerIds)\n if (!rmOwners.length && !upOwners.length) return\n\n const owners: Record<\n number,\n {\n type: ACTION.UPDATE | ACTION.DELETE\n rmPermissions?: SPACE_OPERATION[]\n }\n > = {\n ...Object.fromEntries(rmOwners.map((uId: number) => [uId, { type: ACTION.DELETE }])),\n ...Object.fromEntries(\n upOwners.reduce(\n (\n acc: [\n number,\n {\n type: ACTION.UPDATE\n rmPermissions: SPACE_OPERATION[]\n }\n ][],\n o\n ) => {\n for (const id of o.ids) {\n acc.push([id, { type: ACTION.UPDATE, rmPermissions: o.rmPermissions }])\n }\n return acc\n },\n []\n )\n )\n }\n // find all parent shares which are owned by the modified/removed members of the space\n for (const share of await this.sharesQueries.selectParentSharesFromSpaceId(\n spaceId,\n Object.keys(owners).map((id: string) => parseInt(id))\n )) {\n if (share.ownerId in owners) {\n const action = owners[share.ownerId]\n if (action.type === ACTION.UPDATE) {\n this.removeChildSharesPermissions(\n share.id,\n [\n {\n ids: [share.ownerId],\n rmPermissions: action.rmPermissions\n }\n ],\n false\n ).catch((e: Error) => this.logger.error(`${this.updateSharesFromSpace.name} - ${e}`))\n } else {\n this.removeShareFromOwners(share.id, [share.ownerId], false).catch((e: Error) =>\n this.logger.error(`${this.updateSharesFromSpace.name} - ${e}`)\n )\n }\n this.logger.log(`${this.updateSharesFromSpace.name} - ${action.type} share (${share.id}) for owner ${share.ownerId} from space ${spaceId}`)\n }\n }\n }\n\n async updateSharesFromSpaceRoots(\n /* update or remove shares related to space roots changes */\n spaceId: number,\n toRemove: number[],\n toUpdate: {\n id: number\n rmPermissions: SPACE_OPERATION[]\n }[]\n ): Promise<void> {\n // skip if no actions\n if (!toRemove.length && !toUpdate.length) return\n\n for (const root of toUpdate) {\n for (const share of await this.sharesQueries.selectShares({ spaceId: spaceId, spaceRootId: root.id, parentId: null })) {\n this.removeChildSharesPermissions(\n share.id,\n [\n {\n ids: 'all',\n rmPermissions: root.rmPermissions\n }\n ],\n false\n ).catch((e: Error) => this.logger.error(`${this.updateSharesFromSpaceRoots.name} - ${e}`))\n }\n }\n\n for (const rootId of toRemove) {\n for (const share of await this.sharesQueries.selectShares({ spaceId: spaceId, spaceRootId: rootId, parentId: null })) {\n // use await ! avoid database lock ! next action is to delete the root space which is cascaded with share.spaceRootId\n await this.removeShareFromOwners(share.id, [share.ownerId], false)\n }\n }\n }\n\n async removeSharesFromSpace(spaceId: number): Promise<void> {\n for (const share of await this.sharesQueries.selectShares({ spaceId: spaceId, parentId: null })) {\n // use await ! avoid database lock ! next action is to delete the space which is cascaded with share.spaceId\n await this.removeShareFromOwners(share.id, [share.ownerId], false)\n }\n }\n\n async generateLinkUUID(userId: number): Promise<{ uuid: string }> {\n let uuid: string = generateShortUUID()\n while (!(await this.linksQueries.isUniqueUUID(userId, uuid))) {\n uuid = generateShortUUID()\n }\n return { uuid: uuid }\n }\n\n listShareLinks(user: UserModel): Promise<ShareLink[]> {\n return this.sharesQueries.listShareLinks(user)\n }\n\n async getShareLink(user: UserModel, shareId: number, asAdmin: boolean = false): Promise<ShareLink> {\n const shareLink: ShareLink = await this.sharesQueries.listShareLinks(user, shareId, asAdmin)\n if (!shareLink) {\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n await this.setAllowedPermissions(user, shareLink)\n if (shareLink.file?.permissions) {\n // share link does not have these permissions\n shareLink.file.permissions = removePermissions(shareLink.file.permissions, [SPACE_OPERATION.SHARE_INSIDE, SPACE_OPERATION.SHARE_OUTSIDE])\n }\n return shareLink\n }\n\n async getLinkFromSpaceOrShare(user: UserModel, linkId: number, spaceOrShareId: number, type: LINK_TYPE): Promise<LinkGuest> {\n let linkGuest: LinkGuest\n if (type === LINK_TYPE.SPACE) {\n linkGuest = await this.linksQueries.linkFromSpace(user.id, linkId, spaceOrShareId)\n } else {\n linkGuest = await this.linksQueries.linkFromShare(user.id, linkId, spaceOrShareId, +user.isAdmin)\n }\n if (!linkGuest) {\n this.logger.warn(`${this.getLinkFromSpaceOrShare.name} - unable to find link (${linkId}) on ${type} (${spaceOrShareId})`)\n throw new HttpException('Link not found', HttpStatus.NOT_FOUND)\n }\n return linkGuest\n }\n\n async createOrUpdateLinksAsMembers(\n user: UserModel,\n spaceOrShare: Partial<SpaceProps> | Partial<ShareProps>,\n type: LINK_TYPE,\n links: SpaceMemberDto[] | ShareMemberDto[]\n ): Promise<SpaceMemberDto[] | ShareMemberDto[]> {\n /* only used during the share creation from the share manager */\n const linkMembers: SpaceMemberDto[] | ShareMemberDto[] = []\n for (const link of links) {\n if (link.id < 0) {\n // new link (permissions are needed to create guest link)\n await this.createLinkFromSpaceOrShare(user, link.linkSettings.uuid, spaceOrShare.id, type, {\n ...link.linkSettings,\n permissions: link.permissions\n })\n // notify the guest link (if email is specified)\n this.notifyGuestLink(user, link, spaceOrShare.name, type === LINK_TYPE.SHARE ? ACTION.ADD : ACTION.UPDATE).catch((e: Error) =>\n this.logger.error(`${this.createOrUpdateLinksAsMembers.name} - ${e}`)\n )\n } else {\n if (link.linkSettings) {\n // modified link\n await this.updateLinkFromSpaceOrShare(user, link.linkId, spaceOrShare.id, type, link.linkSettings)\n }\n // unmodified link\n linkMembers.push(link)\n }\n }\n return linkMembers\n }\n\n async updateLinkFromSpaceOrShare(\n user: UserModel,\n linkId: number,\n spaceOrShareId: number,\n type: LINK_TYPE,\n createOrUpdateLinkDto: CreateOrUpdateLinkDto,\n fromAPI: boolean = false\n ): Promise<LinkGuest> {\n const link: LinkGuest = await this.getLinkFromSpaceOrShare(user, linkId, spaceOrShareId, type)\n if (!link) {\n this.logger.error(`${this.updateLinkFromSpaceOrShare.name} - (${linkId}) from ${type} (${spaceOrShareId}) and user (${user.id}) was not found`)\n throw new HttpException('Unable to find link', HttpStatus.NOT_FOUND)\n }\n const fieldsWhiteList: (keyof CreateOrUpdateLinkDto)[] = [\n 'name',\n 'email',\n 'requireAuth',\n 'limitAccess',\n 'expiresAt',\n 'language',\n 'isActive',\n 'password',\n 'permissions',\n 'shareName',\n 'shareDescription'\n ]\n const [updateUser, updateLink, updateShare, updateMember]: [\n Partial<Pick<User, 'language' | 'isActive' | 'password'>>,\n Partial<Pick<Link, 'name' | 'email' | 'requireAuth' | 'limitAccess' | 'expiresAt'>>,\n Partial<Pick<Share, 'alias' | 'name' | 'description'>>,\n Partial<Pick<ShareMembers, 'permissions'>>\n ] = [{}, {}, {}, {}]\n for (const [k, v] of Object.entries(createOrUpdateLinkDto) as Entries<CreateOrUpdateLinkDto>) {\n if (fieldsWhiteList.indexOf(k) > -1 && link[k] !== v) {\n switch (k) {\n case 'password':\n if (v) {\n updateUser.password = await hashPassword(v)\n }\n break\n case 'permissions':\n if (fromAPI) {\n // permissions are only present if the share type is link\n // intersect permissions to ensure that the user does not attempt to exceed his rights\n const shareLink: ShareLink = await this.getShareLink(user, spaceOrShareId)\n updateMember.permissions = intersectPermissions(shareLink.file.permissions, v)\n }\n break\n case 'language':\n updateUser.language = v\n break\n case 'isActive':\n updateUser.isActive = v\n break\n case 'shareName':\n updateShare.name = v\n updateShare.alias = await this.sharesQueries.uniqueShareAlias(v)\n break\n case 'shareDescription':\n updateShare.description = v\n break\n case 'expiresAt':\n if (JSON.stringify(link[k]) !== JSON.stringify(v)) {\n updateLink[k] = v\n }\n break\n default:\n updateLink[k] = v\n }\n }\n }\n if (!Object.keys(updateUser).length && !Object.keys(updateLink).length && !Object.keys(updateShare).length && !Object.keys(updateMember).length) {\n this.logger.warn(`${this.updateLinkFromSpaceOrShare.name} - no diff to update`)\n return fromAPI ? link : null\n }\n try {\n await this.linksQueries.updateLinkFromSpaceOrShare(link, spaceOrShareId, updateUser, updateLink, updateShare, updateMember)\n this.logger.debug(\n `${this.updateLinkFromSpaceOrShare.name} - link (${linkId}) updated : ${JSON.stringify({\n ...{ user: anonymizePassword(updateUser) },\n ...{ link: updateLink },\n ...{ share: updateShare },\n ...{ member: updateMember }\n })}`\n )\n } catch (e) {\n this.logger.error(`${this.updateLinkFromSpaceOrShare.name} - ${e}`)\n throw new HttpException('Unable to update link', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n if (fromAPI) {\n // for security reasons\n delete updateUser.password\n Object.assign(link, updateUser, updateLink, updateMember)\n return link\n }\n }\n\n async createGuestLink(\n permission: GUEST_PERMISSION.SPACES | GUEST_PERMISSION.SHARES,\n password?: string,\n language?: string,\n isActive: boolean = true\n ): Promise<Partial<User>> {\n const random = generateShortUUID(64)\n const guestLink = {\n login: random,\n email: `${random}@sync-in`,\n firstName: 'Guest',\n lastName: 'Link',\n language: language || null,\n permissions: permission,\n password: await hashPassword(password || generateShortUUID(24)),\n role: USER_ROLE.LINK,\n isActive: isActive\n } satisfies CreateUserDto\n try {\n ;(guestLink as Partial<User>).id = await this.usersQueries.createUserOrGuest(guestLink, USER_ROLE.LINK)\n return guestLink\n } catch (e) {\n this.logger.error(`${this.createGuestLink.name} - unable to create guest link : ${e}`)\n throw new HttpException('Unable to create guest link', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n /* MANAGE SHARE LINKS */\n\n async deleteAllLinkMembers(spaceOrShareId: number, type: LINK_TYPE): Promise<void> {\n const ids: { id: number; linkId: number }[] = await this.linksQueries.allLinksFromSpaceOrShare(spaceOrShareId, type)\n await this.deleteGuestLinks(ids)\n }\n\n async deleteLinkMembers(members: SpaceMemberDto[] | ShareMemberDto[]): Promise<void> {\n await this.deleteGuestLinks(members)\n }\n\n private async updateMembers(user: UserModel, share: Partial<Share>, oldMembers: ShareMemberDto[], currentMembers: ShareMemberDto[]) {\n if (oldMembers.length === 0 && currentMembers.length === 0) {\n return\n }\n // diff\n const [add, update, remove]: [ShareMemberDto[], Record<string | 'object', { old: any; new: any } | ShareMemberDto>[], ShareMemberDto[]] =\n diffCollection(oldMembers, currentMembers, ['permissions'], ['id', 'type'])\n\n // check members whitelists\n let toAdd: ShareMemberDto[] = []\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 share *${share.alias}* (${share.id}) : not in the members whitelist`\n )\n return false\n }\n return true\n })\n }\n\n // filter links\n const toRemove = remove.filter((m) => !m.linkId)\n // do remove links\n this.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.sharesQueries.updateMembers(share.id, toAdd, convertDiffUpdate(update), toRemove)\n\n // lists deleted and updated members as potential share owners\n const [rmMembersChildShares, upMembersChildShares]: [ShareMemberDto[], { object: ShareMemberDto; rmPermissions: SPACE_OPERATION[] }[]] = [[], []]\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 child shares from the current share\n rmMembersChildShares.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 } else if (action === ACTION.UPDATE) {\n // stores permissions updates and members who might own child shares created from the current share\n for (const m of update as { object: ShareMemberDto; permissions: { old: string; new: string } }[]) {\n if (\n ((m.object.type === MEMBER_TYPE.USER || m.object.type === MEMBER_TYPE.GUEST) && 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 const diffPermissions = differencePermissions(m.permissions.old, m.permissions.new) as SPACE_OPERATION[]\n if (diffPermissions.length) {\n upMembersChildShares.push({ object: m.object, rmPermissions: diffPermissions })\n }\n }\n }\n }\n\n // clear cache &|| notify\n this.onShareActionForMembers(share, action, members, user).catch((e: Error) => this.logger.error(`${this.updateMembers.name} - ${e}`))\n }\n\n // do updates\n // remove or update potential child shares\n this.updateMembersChildSharesPermissions(share.id, currentMembers, rmMembersChildShares, upMembersChildShares).catch((e: Error) =>\n this.logger.error(`${this.updateMembers.name} - ${e}`)\n )\n }\n\n private async updateMembersChildSharesPermissions(\n parentShareId: number,\n currentMembers: ShareMemberDto[],\n toRemove: ShareMemberDto[],\n toUpdate: { object: ShareMemberDto; rmPermissions: SPACE_OPERATION[] }[]\n ) {\n /*\n child shares of the member should be deleted if the member is removed from the parent share\n the permissions of the child shares members should be updated if the member's permissions are updated\n */\n const [removeUsersChildShares, updateUsersChildShares] = await this.diffSharesPermissions(currentMembers, toRemove, toUpdate)\n await Promise.all([\n this.removeShareFromOwners(parentShareId, removeUsersChildShares),\n this.removeChildSharesPermissions(parentShareId, updateUsersChildShares)\n ])\n }\n\n private async diffSharesPermissions(\n currentMembers: ShareMemberDto[] | SpaceMemberDto[],\n toRemove: ShareMemberDto[] | SpaceMemberDto[],\n toUpdate: { object: ShareMemberDto | SpaceMemberDto; rmPermissions: SPACE_OPERATION[] }[],\n ignoreUserIds: number[] = []\n ): Promise<[number[], { ids: number[]; rmPermissions: SPACE_OPERATION[] }[]]> {\n // remove shares from members\n const [removeUsersChildShares, removeGroupsChildShares]: number[][] = [[], []]\n for (const m of toRemove) {\n if (m.type === MEMBER_TYPE.USER || m.type === MEMBER_TYPE.GUEST) {\n if (ignoreUserIds.indexOf(m.id) > -1) {\n continue\n }\n // do not remove child shares if the user is a member of a group with share permission\n const memberGroupIds = await this.usersQueries.groupsWhitelist(m.id)\n const groupSharePermission = currentMembers.find(\n (m) =>\n (m.type === MEMBER_TYPE.GROUP || m.type === MEMBER_TYPE.PGROUP) &&\n memberGroupIds.indexOf(m.id) > -1 &&\n havePermission(m.permissions, SPACE_OPERATION.SHARE_OUTSIDE)\n )\n if (groupSharePermission) {\n this.logger.debug(\n `${this.diffSharesPermissions.name} - ignore user (${m.id}) removal : is a member of the group (${groupSharePermission.id}) with share permission`\n )\n continue\n }\n removeUsersChildShares.push(m.id)\n } else {\n removeGroupsChildShares.push(m.id)\n }\n }\n\n // update shares permissions from members\n const [updateUsersChildShares, updateGroupsChildShares]: { ids: number[]; rmPermissions: SPACE_OPERATION[] }[][] = [[], []]\n for (const m of toUpdate) {\n // all child share permissions must be updated\n if (m.object.type === MEMBER_TYPE.USER || m.object.type === MEMBER_TYPE.GUEST) {\n if (ignoreUserIds.indexOf(m.object.id) > -1) continue\n // check if the user is a member of the existing groups on the share\n // since group and user permissions are aggregated, we should check the group permissions\n const memberGroupIds = await this.usersQueries.groupsWhitelist(m.object.id)\n const groupPermissions = currentMembers\n .filter((m) => (m.type === MEMBER_TYPE.GROUP || m.type === MEMBER_TYPE.PGROUP) && memberGroupIds.indexOf(m.id) > -1)\n .reduce((perms: string[], m: ShareMemberDto) => {\n for (const p of m.permissions.split(SPACE_PERMS_SEP).filter((p: string) => p !== '' && perms.indexOf(p) === -1)) {\n perms.push(p)\n }\n return perms\n }, [])\n // find all permissions that the user must keep\n const [permsToKeep, permsToRemove]: SPACE_OPERATION[][] = [[], []]\n // compare the permissions removed from group to user's\n m.rmPermissions.forEach((p: SPACE_OPERATION) => (groupPermissions.indexOf(p) > -1 ? permsToKeep.push(p) : permsToRemove.push(p)))\n if (!permsToRemove.length) {\n // the groups provide these permissions to user, no need to update child shares\n continue\n }\n // remove only unmatched permissions\n m.rmPermissions = permsToRemove\n }\n // group members by permissions to optimize queries\n const memberTypeChildShares =\n m.object.type === MEMBER_TYPE.USER || m.object.type === MEMBER_TYPE.GUEST ? updateUsersChildShares : updateGroupsChildShares\n const memberWithSamePermissions = memberTypeChildShares.find((p) => p.rmPermissions.toString() === m.rmPermissions.toString())\n if (memberWithSamePermissions) {\n memberWithSamePermissions.ids.push(m.object.id)\n } else {\n memberTypeChildShares.push({ ids: [m.object.id], rmPermissions: m.rmPermissions })\n }\n }\n\n // retrieves all users from groups and subgroups & add them to the remove and update lists\n if (removeGroupsChildShares.length) {\n // ignore user id if the user is already removed or is a member of the parent share\n const rmUsersFromGroups = (await this.usersQueries.allUserIdsFromGroupsAndSubGroups(removeGroupsChildShares)).filter(\n (id) =>\n ignoreUserIds.indexOf(id) === -1 &&\n removeUsersChildShares.indexOf(id) === -1 &&\n !currentMembers.find((m) => (m.type === MEMBER_TYPE.USER || m.type === MEMBER_TYPE.GUEST) && m.id === id)\n )\n removeUsersChildShares.push(...rmUsersFromGroups)\n }\n if (updateGroupsChildShares.length) {\n for (const g of updateGroupsChildShares) {\n // ignore user id if the user is already removed or is a member of the parent share\n const rmUsersPermissionsFromGroups: number[] = []\n for (const uId of await this.usersQueries.allUserIdsFromGroupsAndSubGroups(g.ids)) {\n if (ignoreUserIds.indexOf(uId) > -1 || removeUsersChildShares.indexOf(uId) > -1) {\n continue\n }\n // check if the user is a member of the existing groups on the share\n // since group and user permissions are aggregated, we should check the group permissions\n const memberGroupIds = await this.usersQueries.groupsWhitelist(uId)\n const groupPermissions = currentMembers\n .filter(\n (m) =>\n ((m.type === MEMBER_TYPE.GROUP || m.type === MEMBER_TYPE.PGROUP) && memberGroupIds.indexOf(m.id) > -1) ||\n ((m.type === MEMBER_TYPE.USER || m.type === MEMBER_TYPE.GUEST) && m.id === uId)\n )\n .reduce((perms: string[], m: ShareMemberDto) => {\n for (const p of m.permissions.split(SPACE_PERMS_SEP).filter((p: string) => p !== '' && perms.indexOf(p) === -1)) {\n perms.push(p)\n }\n return perms\n }, [])\n // find all permissions that the user must keep\n const [permsToKeep, permsToRemove]: SPACE_OPERATION[][] = [[], []]\n // compare the permissions removed from group to user's\n g.rmPermissions.forEach((p: SPACE_OPERATION) => (groupPermissions.indexOf(p) > -1 ? permsToKeep.push(p) : permsToRemove.push(p)))\n if (!permsToKeep.length) {\n // user does not have the removed permissions from groups or from himself, we can remove the permissions to his child shares\n rmUsersPermissionsFromGroups.push(uId)\n } else if (permsToRemove.length) {\n // remove only unmatched permissions\n updateUsersChildShares.push({ ids: [uId], rmPermissions: permsToRemove })\n }\n }\n if (!rmUsersPermissionsFromGroups.length) continue\n // group users by permissions to optimize queries\n const memberWithSamePermissions = updateUsersChildShares.find((p) => p.rmPermissions.toString() === g.rmPermissions.toString())\n if (memberWithSamePermissions) {\n memberWithSamePermissions.ids.push(...rmUsersPermissionsFromGroups)\n } else {\n updateUsersChildShares.push({ ids: rmUsersPermissionsFromGroups, rmPermissions: g.rmPermissions })\n }\n }\n }\n return [removeUsersChildShares, updateUsersChildShares]\n }\n\n private async removeShareFromOwners(shareId: number, ownerIds: number[] | 'all', asParent: boolean = true, fromUserId?: number) {\n // deletes only the first (child) shares, child shares will be deleted in cascade\n const where = { ...(asParent ? { parentId: shareId } : { id: shareId }), ...(ownerIds !== 'all' && { ownerId: ownerIds }) }\n for (const share of await this.sharesQueries.selectShares(where)) {\n try {\n // store current child shares members before delete parent share\n const members: ShareChildMember[] = await this.sharesQueries.membersFromChildSharesPermissions(share.id, [share.ownerId], null, false)\n await this.sharesQueries.deleteShare(share.id)\n this.logger.log(`${this.removeShareFromOwners.name} - share *${share.alias}* (${share.id}) from owner (${share.ownerId}) was removed`)\n // clear cache & notify users\n if (!fromUserId || fromUserId !== share.ownerId) {\n this.clearCachePermissionsAndOrNotify(share, ACTION.DELETE_PERMANENTLY, [share.ownerId]).catch((e: Error) =>\n this.logger.error(`${this.removeShareFromOwners.name} - ${e}`)\n )\n }\n members.forEach((m) => this.clearCachePermissionsAndOrNotify({ alias: m.shareAlias, name: m.shareName }, ACTION.DELETE, [m.userId]))\n } catch (e) {\n this.logger.error(\n `${this.removeShareFromOwners.name} - share *${share.alias}* (${share.id}) from owner (${share.ownerId}) was not removed : ${e}`\n )\n }\n }\n }\n\n private async removeChildSharesPermissions(\n shareId: number,\n userPermissions: {\n ids: number[] | 'all'\n rmPermissions: SPACE_OPERATION[]\n }[],\n asParent: boolean = true\n ) {\n // remove permissions of all members of the child shares\n if (!userPermissions.length) return\n for (const userPerm of userPermissions) {\n const members: ShareChildMember[] = await this.sharesQueries.membersFromChildSharesPermissions(\n shareId,\n userPerm.ids,\n userPerm.rmPermissions.join('|'),\n asParent\n )\n for (const m of members) {\n const permissions = removePermissions(m.userPermissions, userPerm.rmPermissions)\n try {\n await this.sharesQueries.updateMember({ permissions: permissions }, { id: m.id })\n this.clearCachePermissionsAndOrNotify(\n {\n alias: m.shareAlias,\n name: m.shareName\n },\n ACTION.UPDATE,\n [m.userId]\n ).catch((e: Error) => this.logger.error(`${this.removeChildSharesPermissions.name} - ${e}`))\n this.logger.log(\n `${this.removeChildSharesPermissions.name} - user (${m.id}) permissions ${JSON.stringify(userPerm.rmPermissions)} on share : ${m.shareAlias} (${m.shareId}) was removed`\n )\n } catch (e) {\n this.logger.error(\n `${this.removeChildSharesPermissions.name} - user (${m.id}) permissions on share *${m.shareAlias}* (${m.shareId}) was not removed : ${e}`\n )\n }\n }\n }\n }\n\n private async checkChildSharePermissions(user: UserModel, shareId: number, childId: number): Promise<boolean> {\n const isOwnerForChildShare: number = await this.sharesQueries.childExistsForShareOwner(user.id, shareId, childId, user.isAdmin)\n if (isOwnerForChildShare !== childId) {\n this.logger.warn(`${this.checkChildSharePermissions.name} - is not allowed to manage child share (${childId}) from share (${shareId})`)\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n return true\n }\n\n private async onShareActionForMembers(share: Partial<Share>, action: ACTION, members: { groupIds: number[]; userIds: number[] }, user?: UserModel) {\n this.clearCachePermissionsAndOrNotify(\n share,\n action,\n Array.from(new Set([...(await this.usersQueries.allUserIdsFromGroupsAndSubGroups(members.groupIds)), ...members.userIds])).filter(\n (uid) => uid !== user?.id\n ),\n user\n ).catch((e: Error) => this.logger.error(`${this.onShareActionForMembers.name} - ${e}`))\n }\n\n private async createLinkFromSpaceOrShare(\n user: UserModel,\n uuid: string,\n spaceOrShareId: number,\n type: LINK_TYPE,\n createOrUpdateLinkDto: CreateOrUpdateLinkDto\n ): Promise<void> {\n /* only used during the share creation from this manager */\n if (!(await this.linksQueries.isReservedUUID(user.id, uuid))) {\n this.logger.error(`${this.createLinkFromSpaceOrShare.name} - user attempted to use UUID (${uuid}) was not reserved`)\n throw new HttpException('UUID was not reserved', HttpStatus.BAD_REQUEST)\n }\n const permission = type === LINK_TYPE.SPACE ? GUEST_PERMISSION.SPACES : GUEST_PERMISSION.SHARES\n const guestLink: Partial<User> = await this.createGuestLink(\n permission,\n createOrUpdateLinkDto.password,\n createOrUpdateLinkDto.language,\n createOrUpdateLinkDto.isActive !== undefined ? createOrUpdateLinkDto.isActive : true\n )\n this.logger.debug(`${this.createLinkFromSpaceOrShare.name} - guest link (${guestLink.id}) created`)\n let linkId: number\n try {\n linkId = await this.linksQueries.createLinkToSpaceOrShare(guestLink.id, spaceOrShareId, type, {\n ...createOrUpdateLinkDto,\n uuid: uuid,\n userId: guestLink.id\n })\n this.logger.debug(\n `${this.createLinkFromSpaceOrShare.name} - link (${linkId}) for guest link (${guestLink.id}) created : ${JSON.stringify(createOrUpdateLinkDto)}`\n )\n } catch (e) {\n this.logger.error(`${this.createLinkFromSpaceOrShare.name} - unable to create link with uuid (${uuid}) : ${e}`)\n throw new HttpException('Unable to update link', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n private async deleteGuestLinks(guestLinks: Partial<{ id: number; linkId: number }>[]) {\n for (const guestLink of guestLinks) {\n try {\n await this.usersQueries.deleteGuestLink(guestLink.id)\n this.logger.log(`${this.deleteGuestLinks.name} - guest (${guestLink.id}) (link: ${guestLink.linkId}) was removed`)\n } catch (e) {\n this.logger.error(`${this.deleteGuestLinks.name} - guest (${guestLink.id}) (link: ${guestLink.linkId}) was not removed : ${e}`)\n }\n }\n }\n\n /* MANAGE CACHE PERMISSIONS AND NOTIFY */\n\n private async clearCachePermissionsAndOrNotify(share: Partial<Share>, action: ACTION, memberIds: number[], user?: UserModel): Promise<void> {\n if (!memberIds?.length) {\n return\n }\n this.logger.verbose(`${this.clearCachePermissionsAndOrNotify.name} - share:${share.alias} ${action} members:${JSON.stringify(memberIds)}`)\n if (action !== ACTION.ADD) {\n // clear permissions for share members\n this.sharesQueries\n .clearCachePermissions(share.alias, memberIds)\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n }\n if (action !== ACTION.UPDATE) {\n // notify the members who have joined or left the share\n const notification: NotificationContent = {\n app: NOTIFICATION_APP.SHARES,\n event: user ? NOTIFICATION_APP_EVENT.SHARES[action] : NOTIFICATION_APP_EVENT.SHARES_WITHOUT_OWNER[action],\n element: share.name,\n url: SPACE_REPOSITORY.SHARES\n }\n this.notificationsManager\n .create(memberIds, notification, {\n currentUrl: this.contextManager.get('headerOriginUrl'),\n author: user,\n action: action\n })\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n }\n }\n\n private async notifyGuestLink(user: UserModel, link: SpaceMemberDto | ShareMemberDto, spaceOrShareName: string, action: ACTION) {\n if (!link.linkSettings.email) {\n return\n }\n this.notificationsManager\n .sendEmailNotification(\n [\n {\n id: -1,\n email: link.linkSettings.email,\n language: link.linkSettings.language,\n notification: USER_NOTIFICATION.APPLICATION_EMAIL\n } satisfies UserMailNotification\n ],\n {\n app: NOTIFICATION_APP.LINKS,\n event: NOTIFICATION_APP_EVENT.LINKS[action],\n element: spaceOrShareName,\n url: null\n } satisfies NotificationContent,\n {\n author: user,\n linkUUID: link.linkSettings.uuid,\n linkPassword: link.linkSettings.password,\n currentUrl: this.contextManager.get('headerOriginUrl'),\n action: action\n } satisfies NotificationOptions\n )\n .catch((e: Error) => this.logger.error(`${this.notifyGuestLink.name} - ${e}`))\n }\n}\n"],"names":["SharesManager","permissions","user","spaceAlias","sharesQueries","id","isAdmin","listShares","listSpaceShares","spaceId","listChildShares","shareId","setAllowedPermissions","share","asAdmin","file","ownerId","externalPath","SHARE_ALL_OPERATIONS","space","alias","spacePermissions","spaceQueries","root","logger","warn","name","JSON","stringify","HttpException","HttpStatus","NOT_FOUND","spaceEnv","SpaceEnv","setPermissions","envPermissions","parent","userId","sharePermissions","error","BAD_REQUEST","getShareWithMembers","FORBIDDEN","createShare","createOrUpdateShareDto","uniqueShareAlias","description","enabled","disabledAt","Date","type","SHARE_TYPE","COMMON","checkExternalPath","e","message","FileError","httpCode","INTERNAL_SERVER_ERROR","realPath","path","join","filesPath","isPathExists","fileProps","getProps","fileId","getOrCreateUserFile","m","members","intersectPermissions","l","links","setPaths","split","slice","spaceRootId","isExternalSpaceRoot","isSpaceRoot","Number","dbFile","undefined","getOrCreateSpaceFile","createOrUpdateLinksAsMembers","LINK_TYPE","SHARE","updateMembers","updateShare","shareDiffProps","modifiedAt","prop","catch","linkMembers","deleteShare","shareExistsForOwner","deleteAllLinkMembers","removeShareFromOwners","getChildShare","childId","isLink","checkChildSharePermissions","getShareLink","updateChildShare","deleteChildShare","createChildShare","pSharePermissions","haveSpacePermission","SPACE_OPERATION","SHARE_OUTSIDE","pShare","filePath","highestParentId","findHighestParentShare","shareEnv","pShareEnv","isLinkedToShareSpaceRoot","isLinkedToShareExternalPath","parentId","updateSharesFromSpace","currentMembers","toRemove","toUpdate","length","spaceManagerIds","filter","spaceRole","SPACE_ROLE","IS_MANAGER","map","rmOwners","upOwners","diffSharesPermissions","owners","Object","fromEntries","uId","ACTION","DELETE","reduce","acc","o","ids","push","UPDATE","rmPermissions","selectParentSharesFromSpaceId","keys","parseInt","action","removeChildSharesPermissions","log","updateSharesFromSpaceRoots","selectShares","rootId","removeSharesFromSpace","generateLinkUUID","uuid","generateShortUUID","linksQueries","isUniqueUUID","listShareLinks","shareLink","removePermissions","SHARE_INSIDE","getLinkFromSpaceOrShare","linkId","spaceOrShareId","linkGuest","SPACE","linkFromSpace","linkFromShare","spaceOrShare","link","createLinkFromSpaceOrShare","linkSettings","notifyGuestLink","ADD","updateLinkFromSpaceOrShare","createOrUpdateLinkDto","fromAPI","fieldsWhiteList","updateUser","updateLink","updateMember","k","v","entries","indexOf","password","hashPassword","language","isActive","debug","anonymizePassword","member","assign","createGuestLink","permission","random","guestLink","login","email","firstName","lastName","role","USER_ROLE","LINK","usersQueries","createUserOrGuest","allLinksFromSpaceOrShare","deleteGuestLinks","deleteLinkMembers","oldMembers","add","update","remove","diffCollection","toAdd","userIdsWhitelist","groupIdsWhitelist","Promise","all","usersWhitelist","groupsWhitelist","MEMBER_TYPE","USER","GUEST","GROUP","PGROUP","status","convertDiffUpdate","rmMembersChildShares","upMembersChildShares","userIds","groupIds","object","diffPermissions","differencePermissions","old","new","onShareActionForMembers","updateMembersChildSharesPermissions","parentShareId","removeUsersChildShares","updateUsersChildShares","ignoreUserIds","removeGroupsChildShares","memberGroupIds","groupSharePermission","find","havePermission","updateGroupsChildShares","groupPermissions","perms","p","SPACE_PERMS_SEP","permsToKeep","permsToRemove","forEach","memberTypeChildShares","memberWithSamePermissions","toString","rmUsersFromGroups","allUserIdsFromGroupsAndSubGroups","g","rmUsersPermissionsFromGroups","ownerIds","asParent","fromUserId","where","membersFromChildSharesPermissions","clearCachePermissionsAndOrNotify","DELETE_PERMANENTLY","shareAlias","shareName","userPermissions","userPerm","isOwnerForChildShare","childExistsForShareOwner","Array","from","Set","uid","isReservedUUID","GUEST_PERMISSION","SPACES","SHARES","createLinkToSpaceOrShare","guestLinks","deleteGuestLink","memberIds","verbose","clearCachePermissions","notification","app","NOTIFICATION_APP","event","NOTIFICATION_APP_EVENT","SHARES_WITHOUT_OWNER","element","url","SPACE_REPOSITORY","notificationsManager","create","currentUrl","contextManager","get","author","spaceOrShareName","sendEmailNotification","USER_NOTIFICATION","APPLICATION_EMAIL","LINKS","linkUUID","linkPassword","Logger"],"mappings":"AAAA;;;;CAIC;;;;+BAqDYA;;;eAAAA;;;wBAnDiD;iEAC7C;2BACM;2BAShB;uCAEwB;2BAEL;uBACgC;uBAChC;qCAIG;+BAC4B;6CAGpB;wBAC0C;+BAEtD;sCAEK;6BACyC;wBAC3C;sBACmC;qCAIlC;wBACoB;sCAUnB;;;;;;;;;;;;;;;AAGvB,IAAA,AAAMA,gBAAN,MAAMA;IAYXC,YAAYC,IAAe,EAAEC,UAAkB,EAAE;QAC/C,OAAO,IAAI,CAACC,aAAa,CAACH,WAAW,CAACC,KAAKG,EAAE,EAAEF,YAAY,CAACD,KAAKI,OAAO;IAC1E;IAEAC,WAAWL,IAAe,EAAwB;QAChD,OAAO,IAAI,CAACE,aAAa,CAACG,UAAU,CAACL;IACvC;IAEAM,gBAAgBC,OAAe,EAAyB;QACtD,OAAO,IAAI,CAACL,aAAa,CAACI,eAAe,CAACC;IAC5C;IAEAC,gBAAgBR,IAAe,EAAES,OAAe,EAAyB;QACvE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;gBAC9BX,UAAUlB,KAAKE,YAAY,CAACgB,QAAQ;gBACpCuG,cAAciB,uBAAiB,CAACC,iBAAiB;YACnD;SACD,EACD;YACEjB,KAAKC,+BAAgB,CAACiB,KAAK;YAC3BhB,OAAOC,qCAAsB,CAACe,KAAK,CAACpK,OAAO;YAC3CuJ,SAASS;YACTR,KAAK;QACP,GACA;YACEO,QAAQjT;YACRuT,UAAU7I,KAAKE,YAAY,CAAClB,IAAI;YAChC8J,cAAc9I,KAAKE,YAAY,CAACc,QAAQ;YACxCoH,YAAY,IAAI,CAACC,cAAc,CAACC,GAAG,CAAC;YACpC9J,QAAQA;QACV,GAEDzD,KAAK,CAAC,CAACrC,IAAa,IAAI,CAAC9B,MAAM,CAACe,KAAK,CAAC,GAAG,IAAI,CAACwI,eAAe,CAACrJ,IAAI,CAAC,GAAG,EAAE4B,GAAG;IAChF;IAhjCA,YACE,AAAiB2P,cAA8B,EAC/C,AAAiBH,oBAA0C,EAC3D,AAAiB1S,aAA4B,EAC7C,AAAiBkB,YAA2B,EAC5C,AAAiByL,YAA0B,EAC3C,AAAiBjD,YAA0B,CAC3C;aANiBmJ,iBAAAA;aACAH,uBAAAA;aACA1S,gBAAAA;aACAkB,eAAAA;aACAyL,eAAAA;aACAjD,eAAAA;aARFtI,SAAS,IAAImS,cAAM,CAAC3T,cAAc0B,IAAI;IASpD;AA0iCL"}
1
+ {"version":3,"sources":["../../../../../backend/src/applications/shares/services/shares-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 path from 'node:path'\nimport { ACTION } from '../../../common/constants'\nimport {\n anonymizePassword,\n convertDiffUpdate,\n diffCollection,\n differencePermissions,\n generateShortUUID,\n hashPassword,\n intersectPermissions\n} from '../../../common/functions'\nimport type { Entries, StorageQuota } from '../../../common/interfaces'\nimport { ContextManager } from '../../../infrastructure/context/services/context-manager.service'\nimport type { FileProps } from '../../files/interfaces/file-props.interface'\nimport { FileError } from '../../files/models/file-error'\nimport { checkExternalPath, dirSize, getProps, isPathExists } from '../../files/utils/files'\nimport { LINK_TYPE } from '../../links/constants/links'\nimport type { CreateOrUpdateLinkDto } from '../../links/dto/create-or-update-link.dto'\nimport type { LinkGuest } from '../../links/interfaces/link-guest.interface'\nimport type { Link } from '../../links/schemas/link.interface'\nimport { LinksQueries } from '../../links/services/links-queries.service'\nimport { NOTIFICATION_APP, NOTIFICATION_APP_EVENT } from '../../notifications/constants/notifications'\nimport type { NotificationContent, NotificationOptions } from '../../notifications/interfaces/notification-properties.interface'\nimport type { UserMailNotification } from '../../notifications/interfaces/user-mail-notification'\nimport { NotificationsManager } from '../../notifications/services/notifications-manager.service'\nimport { CACHE_QUOTA_SHARE_PREFIX, CACHE_QUOTA_TTL } from '../../spaces/constants/cache'\nimport { SPACE_OPERATION, SPACE_PERMS_SEP, SPACE_REPOSITORY, SPACE_ROLE } from '../../spaces/constants/spaces'\nimport type { SpaceMemberDto } from '../../spaces/dto/create-or-update-space.dto'\nimport { SpaceEnv } from '../../spaces/models/space-env.model'\nimport type { SpaceProps } from '../../spaces/models/space-props.model'\nimport { SpacesQueries } from '../../spaces/services/spaces-queries.service'\nimport { havePermission, haveSpacePermission, removePermissions } from '../../spaces/utils/permissions'\nimport { MEMBER_TYPE } from '../../users/constants/member'\nimport { GUEST_PERMISSION, USER_NOTIFICATION, USER_ROLE } from '../../users/constants/user'\nimport { CreateUserDto } from '../../users/dto/create-or-update-user.dto'\nimport { UserModel } from '../../users/models/user.model'\nimport type { User } from '../../users/schemas/user.interface'\nimport { UsersQueries } from '../../users/services/users-queries.service'\nimport { SHARE_ALL_OPERATIONS, SHARE_TYPE } from '../constants/shares'\nimport type { CreateOrUpdateShareDto, ShareMemberDto } from '../dto/create-or-update-share.dto'\nimport type { ShareChildMember } from '../interfaces/share-child.interface'\nimport type { ShareEnv } from '../interfaces/share-env.interface'\nimport type { ShareFile } from '../interfaces/share-file.interface'\nimport type { ShareLink } from '../interfaces/share-link.interface'\nimport type { ShareProps } from '../interfaces/share-props.interface'\nimport type { ShareChild } from '../models/share-child.model'\nimport type { ShareMembers } from '../schemas/share-members.interface'\nimport type { Share } from '../schemas/share.interface'\nimport { SharesQueries } from './shares-queries.service'\n\n@Injectable()\nexport class SharesManager {\n private readonly logger = new Logger(SharesManager.name)\n\n constructor(\n private readonly contextManager: ContextManager,\n private readonly notificationsManager: NotificationsManager,\n private readonly sharesQueries: SharesQueries,\n private readonly spacesQueries: SpacesQueries,\n private readonly usersQueries: UsersQueries,\n private readonly linksQueries: LinksQueries\n ) {}\n\n permissions(user: UserModel, spaceAlias: string) {\n return this.sharesQueries.permissions(user.id, spaceAlias, +user.isAdmin)\n }\n\n listShares(user: UserModel): Promise<ShareFile[]> {\n return this.sharesQueries.listShares(user)\n }\n\n listSpaceShares(spaceId: number): Promise<ShareChild[]> {\n return this.sharesQueries.listSpaceShares(spaceId)\n }\n\n listChildShares(user: UserModel, shareId: number): Promise<ShareChild[]> {\n return this.sharesQueries.listChildShares(user.id, shareId, +user.isAdmin)\n }\n\n async setAllowedPermissions(user: UserModel, share: ShareProps | ShareLink, asAdmin = false) {\n if (share.file?.ownerId === user.id || (share.externalPath && user.isAdmin)) {\n // current user is the file owner (personal space case)\n share.file.permissions = SHARE_ALL_OPERATIONS\n } else if (share.file?.space?.alias) {\n share.file.ownerId = null\n // retrieve space permissions (cached query)\n const spacePermissions: Partial<SpaceEnv> = await this.spacesQueries.permissions(user.id, share.file.space.alias, share.file.space.root?.alias)\n if (!spacePermissions) {\n this.logger.warn(`${this.setAllowedPermissions.name} - missing space permissions : ${JSON.stringify(share)}`)\n throw new HttpException('Space not found', HttpStatus.NOT_FOUND)\n }\n // compute permissions\n const spaceEnv = new SpaceEnv(spacePermissions)\n spaceEnv.setPermissions(true)\n share.file.permissions = spaceEnv.envPermissions\n } else if (share.parent?.alias) {\n // retrieve parent share permissions (cached query)\n // use current the user permissions on the share or the share owner permissions if we request the share as admin\n const userId = asAdmin ? share.ownerId : user.id\n const sharePermissions: Partial<SpaceEnv> = await this.sharesQueries.permissions(userId, share.parent.alias, +user.isAdmin)\n if (!sharePermissions) {\n this.logger.warn(`${this.setAllowedPermissions.name} - missing share permissions : ${JSON.stringify(share)}`)\n throw new HttpException('Share not found', HttpStatus.NOT_FOUND)\n }\n share.file.permissions = sharePermissions.permissions\n } else {\n this.logger.error(`${this.setAllowedPermissions.name} - case not handled ${JSON.stringify(share)}`)\n throw new HttpException('Missing information', HttpStatus.BAD_REQUEST)\n }\n }\n\n async getShareWithMembers(user: UserModel, shareId: number, asAdmin = false): Promise<ShareProps> {\n // asAdmin : true if the user is the owner of the parent share or if the share is requested from the administration\n const share: ShareProps = await this.sharesQueries.getShareWithMembers(user, shareId, asAdmin)\n if (!share) {\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n await this.setAllowedPermissions(user, share, asAdmin)\n return share\n }\n\n async createShare(user: UserModel, createOrUpdateShareDto: CreateOrUpdateShareDto): Promise<ShareProps> {\n const share: Partial<Share> = {\n name: createOrUpdateShareDto.name,\n alias: await this.sharesQueries.uniqueShareAlias(createOrUpdateShareDto.name),\n description: createOrUpdateShareDto.description,\n externalPath: createOrUpdateShareDto.externalPath,\n enabled: createOrUpdateShareDto.enabled,\n storageQuota: createOrUpdateShareDto.storageQuota,\n storageIndexing: createOrUpdateShareDto.storageIndexing,\n disabledAt: createOrUpdateShareDto.enabled ? null : new Date(),\n type: createOrUpdateShareDto.type || SHARE_TYPE.COMMON\n }\n if (share.externalPath) {\n /* EXTERNAL PATH CASE */\n if (!user.isAdmin) {\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n try {\n await checkExternalPath(share.externalPath)\n } catch (e: any) {\n throw new HttpException(e.message, e instanceof FileError ? e.httpCode : HttpStatus.INTERNAL_SERVER_ERROR)\n }\n share.ownerId = null\n } else {\n /* SPACES CASE */\n share.externalPath = null\n share.ownerId = user.id\n if (createOrUpdateShareDto.file.ownerId) {\n /* PERSONAL SPACE CASE */\n // check file\n const realPath = path.join(user.filesPath, createOrUpdateShareDto.file.path)\n if (!(await isPathExists(realPath))) {\n this.logger.warn(`${this.createShare.name} - location does not exist : ${realPath}`)\n throw new HttpException('The location does not exist', HttpStatus.NOT_FOUND)\n }\n const fileProps: FileProps = { ...(await getProps(realPath, createOrUpdateShareDto.file.path)), id: createOrUpdateShareDto.file.id }\n share.fileId = await this.spacesQueries.getOrCreateUserFile(user.id, fileProps)\n } else if (createOrUpdateShareDto.file.space?.alias) {\n /* SPACE CASE */\n const spacePermissions: Partial<SpaceEnv> = await this.spacesQueries.permissions(\n user.id,\n createOrUpdateShareDto.file.space.alias,\n createOrUpdateShareDto.file.space.root.alias\n )\n if (!spacePermissions) {\n throw new HttpException('Space not found', HttpStatus.NOT_FOUND)\n }\n // compute space permissions\n const space: SpaceEnv = new SpaceEnv(spacePermissions)\n space.setPermissions(true)\n // intersect space permissions for members\n for (const m of createOrUpdateShareDto.members) {\n m.permissions = intersectPermissions(space.envPermissions, m.permissions)\n }\n // intersect space permissions for links\n for (const l of createOrUpdateShareDto.links) {\n l.permissions = intersectPermissions(space.envPermissions, l.permissions)\n }\n // check file\n try {\n space.setPaths(user, createOrUpdateShareDto.file.space.root.alias, createOrUpdateShareDto.file.path.split('/').slice(space.root.id ? 1 : 0))\n } catch (e) {\n if (e instanceof FileError) {\n throw new HttpException(e.message, e.httpCode)\n }\n throw new HttpException(e.message, HttpStatus.BAD_REQUEST)\n }\n if (!(await isPathExists(space.realPath))) {\n this.logger.warn(`${this.createShare.name} - space location does not exist : *${space.alias}* (${space.id}) : ${space.realPath}`)\n throw new HttpException('The location does not exist', HttpStatus.NOT_FOUND)\n }\n share.spaceId = space.id\n share.spaceRootId = space.root?.id || null\n // define share.fileId\n // if the file is the same as the space root, ignores share.fileId and only uses spaceId and spaceRootId\n const isExternalSpaceRoot =\n createOrUpdateShareDto.file?.id < 0 &&\n createOrUpdateShareDto.file?.path === createOrUpdateShareDto.file?.space?.root?.alias &&\n createOrUpdateShareDto.file?.space?.root?.alias === spacePermissions.root?.alias &&\n createOrUpdateShareDto.file?.space?.root?.name === spacePermissions.root?.name\n const isSpaceRoot = Number(createOrUpdateShareDto.file.id) === Number(spacePermissions.root?.file?.id)\n if (!isSpaceRoot && !isExternalSpaceRoot) {\n const fileProps: FileProps = { ...(await getProps(space.realPath, space.dbFile.path)), id: undefined }\n // get or create file id\n share.fileId = await this.spacesQueries.getOrCreateSpaceFile(createOrUpdateShareDto.file.id, fileProps, space.dbFile)\n }\n } else {\n // unexpected case\n throw new HttpException('Missing information', HttpStatus.BAD_REQUEST)\n }\n }\n // create share\n share.id = await this.sharesQueries.createShare(share)\n // check & update members\n await this.createOrUpdateLinksAsMembers(user, share, LINK_TYPE.SHARE, createOrUpdateShareDto.links)\n await this.updateMembers(user, share, [], createOrUpdateShareDto.members)\n return this.getShareWithMembers(user, share.id)\n }\n\n async updateShare(user: UserModel, shareId: number, createOrUpdateShareDto: CreateOrUpdateShareDto, asAdmin = false): Promise<ShareProps> {\n // asAdmin: true if the user is the owner of the parent share or if the share is requested from the administration\n const share: ShareProps = await this.getShareWithMembers(user, shareId, asAdmin)\n // check and update share info\n const shareDiffProps: Partial<ShareProps> = { modifiedAt: new Date() }\n const props: (keyof CreateOrUpdateShareDto)[] = ['name', 'description', 'enabled', 'storageQuota', 'storageIndexing']\n for (const prop of props) {\n if (createOrUpdateShareDto[prop] !== share[prop]) {\n shareDiffProps[prop] = createOrUpdateShareDto[prop]\n if (prop === 'name') {\n shareDiffProps.alias = await this.sharesQueries.uniqueShareAlias(shareDiffProps.name)\n } else if (prop === 'enabled') {\n shareDiffProps.disabledAt = shareDiffProps[prop] ? null : new Date()\n }\n }\n }\n // update in db\n if (!(await this.sharesQueries.updateShare(shareId, shareDiffProps))) {\n throw new HttpException('Unable to update share', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n // check & update members\n const linkMembers: ShareMemberDto[] = await this.createOrUpdateLinksAsMembers(user, share, LINK_TYPE.SHARE, createOrUpdateShareDto.links)\n // intersect share permissions for members\n for (const m of createOrUpdateShareDto.members) {\n m.permissions = intersectPermissions(share.file.permissions, m.permissions)\n }\n // intersect share permissions for links\n for (const l of linkMembers) {\n l.permissions = intersectPermissions(share.file.permissions, l.permissions)\n }\n await this.updateMembers(user, share, share.members, [...createOrUpdateShareDto.members, ...linkMembers])\n return this.getShareWithMembers(user, share.id, asAdmin)\n }\n\n async deleteShare(user: UserModel, shareId: number, asAdmin = false): Promise<void> {\n // asAdmin : true if the user is the owner of the parent share or if the share is requested from an admin\n if (!asAdmin && !user.isAdmin && !(await this.sharesQueries.shareExistsForOwner(user.id, shareId))) {\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n try {\n await this.deleteAllLinkMembers(shareId, LINK_TYPE.SHARE)\n await this.removeShareFromOwners(shareId, 'all', false, user.id)\n } catch (e) {\n this.logger.error(`${this.deleteShare.name} - unable to delete share (${shareId}) (asAdmin = ${asAdmin}) : ${e}`)\n throw new HttpException('Unable to delete share', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n async getChildShare(user: UserModel, shareId: number, childId: number, isLink?: false): Promise<ShareProps>\n async getChildShare(user: UserModel, shareId: number, childId: number, isLink?: true): Promise<ShareLink>\n async getChildShare(user: UserModel, shareId: number, childId: number, isLink?: boolean): Promise<ShareProps | ShareLink> {\n if (await this.checkChildSharePermissions(user, shareId, childId)) {\n if (isLink) {\n return this.getShareLink(user, childId, true)\n }\n return this.getShareWithMembers(user, childId, true)\n }\n }\n\n async updateChildShare(user: UserModel, shareId: number, childId: number, createOrUpdateShareDto: CreateOrUpdateShareDto): Promise<ShareProps> {\n if (await this.checkChildSharePermissions(user, shareId, childId)) {\n return this.updateShare(user, childId, createOrUpdateShareDto, true)\n }\n }\n\n async deleteChildShare(user: UserModel, shareId: number, childId: number): Promise<void> {\n if (await this.checkChildSharePermissions(user, shareId, childId)) {\n return this.deleteShare(user, childId, true)\n }\n }\n\n async createChildShare(user: UserModel, createOrUpdateShareDto: CreateOrUpdateShareDto): Promise<ShareProps> {\n // check parent share\n const pSharePermissions = await this.sharesQueries.permissions(user.id, createOrUpdateShareDto.parent.alias, +user.isAdmin)\n if (!pSharePermissions) {\n this.logger.warn(`${this.createChildShare.name} - parent share does not exist or not authorized : ${createOrUpdateShareDto.parent.alias}`)\n throw new HttpException('Parent share not found', HttpStatus.NOT_FOUND)\n }\n if (!haveSpacePermission(pSharePermissions, SPACE_OPERATION.SHARE_OUTSIDE)) {\n this.logger.warn(`${this.createChildShare.name} - is not allowed to share outside of : *${pSharePermissions.alias}* (${pSharePermissions.id})`)\n throw new HttpException('You are not allowed to do this action', HttpStatus.FORBIDDEN)\n }\n if (!pSharePermissions.enabled) {\n this.logger.warn(`${this.createChildShare.name} - parent share is disabled : ${createOrUpdateShareDto.parent.alias}`)\n throw new HttpException('Parent share is disabled', HttpStatus.FORBIDDEN)\n }\n\n let pShare: Partial<SpaceEnv>\n let filePath: string\n if (pSharePermissions.root.externalPath) {\n const highestParentId = await this.sharesQueries.findHighestParentShare(pSharePermissions.id)\n if (!highestParentId) {\n this.logger.warn(\n `${this.createChildShare.name} - unable to find the highest parent of : *${pSharePermissions.alias}* (${pSharePermissions.id})`\n )\n throw new HttpException('Parent share not found', HttpStatus.NOT_FOUND)\n }\n pShare = await this.sharesQueries.shareEnv(highestParentId)\n filePath = path.join(pSharePermissions.root?.file?.path || '', createOrUpdateShareDto.file.path)\n } else {\n pShare = await this.sharesQueries.shareEnv(pSharePermissions.id)\n filePath = createOrUpdateShareDto.file.path\n }\n\n // create a fake space env -> share env\n const pShareEnv: Partial<ShareEnv> = new SpaceEnv(pShare, null, false)\n try {\n pShareEnv.setPaths(user, null, filePath.split('/'))\n } catch (e) {\n if (e instanceof FileError) {\n throw new HttpException(e.message, e.httpCode)\n }\n throw new HttpException(e.message, HttpStatus.BAD_REQUEST)\n }\n // check file\n if (!(await isPathExists(pShareEnv.realPath))) {\n this.logger.warn(\n `${this.createChildShare.name} - parent share location does not exist : ${pShareEnv.alias} (${pShareEnv.id}) : ${pShareEnv.realPath}`\n )\n throw new HttpException('The location does not exist', HttpStatus.NOT_FOUND)\n }\n\n /* Manage the case where the child share is created from the parent share itself */\n // special case, the parent share is directly linked to the space root file\n const isLinkedToShareSpaceRoot =\n pShareEnv.fileId === null &&\n Number(createOrUpdateShareDto.file.id) === Number(pSharePermissions.root?.id) &&\n createOrUpdateShareDto.file.path === '.'\n // special case, the parent share is directly linked to the share with an external path\n const isLinkedToShareExternalPath =\n createOrUpdateShareDto.file.id < 0 && !!pShareEnv.root.externalPath && createOrUpdateShareDto.file.path === '.'\n let fileId: number = null\n if (!isLinkedToShareSpaceRoot && !isLinkedToShareExternalPath) {\n // fileId is mandatory for a file in a child share\n const fileProps: FileProps = { ...(await getProps(pShareEnv.realPath, pShareEnv.dbFile.path)), id: undefined }\n fileId = await this.spacesQueries.getOrCreateSpaceFile(createOrUpdateShareDto.file.id, fileProps, pShareEnv.dbFile)\n }\n\n const share: Partial<Share> = {\n name: createOrUpdateShareDto.name,\n alias: await this.sharesQueries.uniqueShareAlias(createOrUpdateShareDto.name),\n ownerId: user.id,\n spaceId: pShareEnv.spaceId,\n spaceRootId: pShareEnv.spaceRootId,\n parentId: pSharePermissions.id,\n fileId: fileId,\n description: createOrUpdateShareDto.description,\n externalPath: pShareEnv.root.externalPath,\n enabled: createOrUpdateShareDto.enabled,\n disabledAt: createOrUpdateShareDto.enabled ? null : new Date(),\n type: createOrUpdateShareDto.type || SHARE_TYPE.COMMON\n }\n // create child share\n share.id = await this.sharesQueries.createShare(share)\n // intersect parent share permissions for members\n for (const m of createOrUpdateShareDto.members) {\n m.permissions = intersectPermissions(pSharePermissions.permissions, m.permissions)\n }\n // intersect parent share permissions for links\n for (const l of createOrUpdateShareDto.links) {\n l.permissions = intersectPermissions(pSharePermissions.permissions, l.permissions)\n }\n // check & update members\n await this.createOrUpdateLinksAsMembers(user, share, LINK_TYPE.SHARE, createOrUpdateShareDto.links)\n await this.updateMembers(user, share, [], createOrUpdateShareDto.members)\n return this.getShareWithMembers(user, share.id)\n }\n\n async updateSharesFromSpace(\n /*\n In this case the space is considered as a parent share\n The shares and child shares of the member should be deleted if the member is removed from the space\n Member permissions on shares and its child shares must be updated if the parent share owner's permissions are updated on the space\n */\n spaceId: number,\n currentMembers: SpaceMemberDto[],\n toRemove: SpaceMemberDto[],\n toUpdate: { object: SpaceMemberDto; rmPermissions: SPACE_OPERATION[] }[]\n ) {\n // skip if no actions\n if (!toRemove.length && !toUpdate.length) return\n // get all space manager ids (ignore them, they have all permissions on the space)\n const spaceManagerIds: number[] = currentMembers.filter((m) => m.spaceRole === SPACE_ROLE.IS_MANAGER).map((m) => m.id)\n const [rmOwners, upOwners] = await this.diffSharesPermissions(currentMembers, toRemove, toUpdate, spaceManagerIds)\n if (!rmOwners.length && !upOwners.length) return\n\n const owners: Record<\n number,\n {\n type: ACTION.UPDATE | ACTION.DELETE\n rmPermissions?: SPACE_OPERATION[]\n }\n > = {\n ...Object.fromEntries(rmOwners.map((uId: number) => [uId, { type: ACTION.DELETE }])),\n ...Object.fromEntries(\n upOwners.reduce(\n (\n acc: [\n number,\n {\n type: ACTION.UPDATE\n rmPermissions: SPACE_OPERATION[]\n }\n ][],\n o\n ) => {\n for (const id of o.ids) {\n acc.push([id, { type: ACTION.UPDATE, rmPermissions: o.rmPermissions }])\n }\n return acc\n },\n []\n )\n )\n }\n // find all parent shares which are owned by the modified/removed members of the space\n for (const share of await this.sharesQueries.selectParentSharesFromSpaceId(\n spaceId,\n Object.keys(owners).map((id: string) => parseInt(id))\n )) {\n if (share.ownerId in owners) {\n const action = owners[share.ownerId]\n if (action.type === ACTION.UPDATE) {\n this.removeChildSharesPermissions(\n share.id,\n [\n {\n ids: [share.ownerId],\n rmPermissions: action.rmPermissions\n }\n ],\n false\n ).catch((e: Error) => this.logger.error(`${this.updateSharesFromSpace.name} - ${e}`))\n } else {\n this.removeShareFromOwners(share.id, [share.ownerId], false).catch((e: Error) =>\n this.logger.error(`${this.updateSharesFromSpace.name} - ${e}`)\n )\n }\n this.logger.log(`${this.updateSharesFromSpace.name} - ${action.type} share (${share.id}) for owner ${share.ownerId} from space ${spaceId}`)\n }\n }\n }\n\n async updateSharesFromSpaceRoots(\n /* update or remove shares related to space roots changes */\n spaceId: number,\n toRemove: number[],\n toUpdate: {\n id: number\n rmPermissions: SPACE_OPERATION[]\n }[]\n ): Promise<void> {\n // skip if no actions\n if (!toRemove.length && !toUpdate.length) return\n\n for (const root of toUpdate) {\n for (const share of await this.sharesQueries.selectShares({ spaceId: spaceId, spaceRootId: root.id, parentId: null })) {\n this.removeChildSharesPermissions(\n share.id,\n [\n {\n ids: 'all',\n rmPermissions: root.rmPermissions\n }\n ],\n false\n ).catch((e: Error) => this.logger.error(`${this.updateSharesFromSpaceRoots.name} - ${e}`))\n }\n }\n\n for (const rootId of toRemove) {\n for (const share of await this.sharesQueries.selectShares({ spaceId: spaceId, spaceRootId: rootId, parentId: null })) {\n // use await ! avoid database lock ! next action is to delete the root space which is cascaded with share.spaceRootId\n await this.removeShareFromOwners(share.id, [share.ownerId], false)\n }\n }\n }\n\n async removeSharesFromSpace(spaceId: number): Promise<void> {\n for (const share of await this.sharesQueries.selectShares({ spaceId: spaceId, parentId: null })) {\n // use await ! avoid database lock ! next action is to delete the space which is cascaded with share.spaceId\n await this.removeShareFromOwners(share.id, [share.ownerId], false)\n }\n }\n\n async generateLinkUUID(userId: number): Promise<{ uuid: string }> {\n let uuid: string = generateShortUUID()\n while (!(await this.linksQueries.isUniqueUUID(userId, uuid))) {\n uuid = generateShortUUID()\n }\n return { uuid: uuid }\n }\n\n listShareLinks(user: UserModel): Promise<ShareLink[]> {\n return this.sharesQueries.listShareLinks(user)\n }\n\n async getShareLink(user: UserModel, shareId: number, asAdmin: boolean = false): Promise<ShareLink> {\n const shareLink: ShareLink = await this.sharesQueries.listShareLinks(user, shareId, asAdmin)\n if (!shareLink) {\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n await this.setAllowedPermissions(user, shareLink)\n if (shareLink.file?.permissions) {\n // share link does not have these permissions\n shareLink.file.permissions = removePermissions(shareLink.file.permissions, [SPACE_OPERATION.SHARE_INSIDE, SPACE_OPERATION.SHARE_OUTSIDE])\n }\n return shareLink\n }\n\n async getLinkFromSpaceOrShare(user: UserModel, linkId: number, spaceOrShareId: number, type: LINK_TYPE): Promise<LinkGuest> {\n let linkGuest: LinkGuest\n if (type === LINK_TYPE.SPACE) {\n linkGuest = await this.linksQueries.linkFromSpace(user.id, linkId, spaceOrShareId)\n } else {\n linkGuest = await this.linksQueries.linkFromShare(user.id, linkId, spaceOrShareId, +user.isAdmin)\n }\n if (!linkGuest) {\n this.logger.warn(`${this.getLinkFromSpaceOrShare.name} - unable to find link (${linkId}) on ${type} (${spaceOrShareId})`)\n throw new HttpException('Link not found', HttpStatus.NOT_FOUND)\n }\n return linkGuest\n }\n\n async createOrUpdateLinksAsMembers(\n user: UserModel,\n spaceOrShare: Partial<SpaceProps> | Partial<ShareProps>,\n type: LINK_TYPE,\n links: SpaceMemberDto[] | ShareMemberDto[]\n ): Promise<SpaceMemberDto[] | ShareMemberDto[]> {\n /* only used during the share creation from the share manager */\n const linkMembers: SpaceMemberDto[] | ShareMemberDto[] = []\n for (const link of links) {\n if (link.id < 0) {\n // new link (permissions are needed to create guest link)\n await this.createLinkFromSpaceOrShare(user, link.linkSettings.uuid, spaceOrShare.id, type, {\n ...link.linkSettings,\n permissions: link.permissions\n })\n // notify the guest link (if email is specified)\n this.notifyGuestLink(user, link, spaceOrShare.name, type === LINK_TYPE.SHARE ? ACTION.ADD : ACTION.UPDATE).catch((e: Error) =>\n this.logger.error(`${this.createOrUpdateLinksAsMembers.name} - ${e}`)\n )\n } else {\n if (link.linkSettings) {\n // modified link\n await this.updateLinkFromSpaceOrShare(user, link.linkId, spaceOrShare.id, type, link.linkSettings)\n }\n // unmodified link\n linkMembers.push(link)\n }\n }\n return linkMembers\n }\n\n async updateLinkFromSpaceOrShare(\n user: UserModel,\n linkId: number,\n spaceOrShareId: number,\n type: LINK_TYPE,\n createOrUpdateLinkDto: CreateOrUpdateLinkDto,\n fromAPI: boolean = false\n ): Promise<LinkGuest> {\n const link: LinkGuest = await this.getLinkFromSpaceOrShare(user, linkId, spaceOrShareId, type)\n if (!link) {\n this.logger.error(`${this.updateLinkFromSpaceOrShare.name} - (${linkId}) from ${type} (${spaceOrShareId}) and user (${user.id}) was not found`)\n throw new HttpException('Unable to find link', HttpStatus.NOT_FOUND)\n }\n const fieldsWhiteList: (keyof CreateOrUpdateLinkDto)[] = [\n 'name',\n 'email',\n 'requireAuth',\n 'limitAccess',\n 'expiresAt',\n 'language',\n 'isActive',\n 'password',\n 'permissions',\n 'shareName',\n 'shareDescription'\n ]\n const [updateUser, updateLink, updateShare, updateMember]: [\n Partial<Pick<User, 'language' | 'isActive' | 'password'>>,\n Partial<Pick<Link, 'name' | 'email' | 'requireAuth' | 'limitAccess' | 'expiresAt'>>,\n Partial<Pick<Share, 'alias' | 'name' | 'description'>>,\n Partial<Pick<ShareMembers, 'permissions'>>\n ] = [{}, {}, {}, {}]\n for (const [k, v] of Object.entries(createOrUpdateLinkDto) as Entries<CreateOrUpdateLinkDto>) {\n if (fieldsWhiteList.indexOf(k) > -1 && link[k] !== v) {\n switch (k) {\n case 'password':\n if (v) {\n updateUser.password = await hashPassword(v)\n }\n break\n case 'permissions':\n if (fromAPI) {\n // permissions are only present if the share type is link\n // intersect permissions to ensure that the user does not attempt to exceed his rights\n const shareLink: ShareLink = await this.getShareLink(user, spaceOrShareId)\n updateMember.permissions = intersectPermissions(shareLink.file.permissions, v)\n }\n break\n case 'language':\n updateUser.language = v\n break\n case 'isActive':\n updateUser.isActive = v\n break\n case 'shareName':\n updateShare.name = v\n updateShare.alias = await this.sharesQueries.uniqueShareAlias(v)\n break\n case 'shareDescription':\n updateShare.description = v\n break\n case 'expiresAt':\n if (JSON.stringify(link[k]) !== JSON.stringify(v)) {\n updateLink[k] = v\n }\n break\n default:\n updateLink[k] = v\n }\n }\n }\n if (!Object.keys(updateUser).length && !Object.keys(updateLink).length && !Object.keys(updateShare).length && !Object.keys(updateMember).length) {\n this.logger.warn(`${this.updateLinkFromSpaceOrShare.name} - no diff to update`)\n return fromAPI ? link : null\n }\n try {\n await this.linksQueries.updateLinkFromSpaceOrShare(link, spaceOrShareId, updateUser, updateLink, updateShare, updateMember)\n this.logger.debug(\n `${this.updateLinkFromSpaceOrShare.name} - link (${linkId}) updated : ${JSON.stringify({\n ...{ user: anonymizePassword(updateUser) },\n ...{ link: updateLink },\n ...{ share: updateShare },\n ...{ member: updateMember }\n })}`\n )\n } catch (e) {\n this.logger.error(`${this.updateLinkFromSpaceOrShare.name} - ${e}`)\n throw new HttpException('Unable to update link', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n if (fromAPI) {\n // for security reasons\n delete updateUser.password\n Object.assign(link, updateUser, updateLink, updateMember)\n return link\n }\n }\n\n async createGuestLink(\n permission: GUEST_PERMISSION.SPACES | GUEST_PERMISSION.SHARES,\n password?: string,\n language?: string,\n isActive: boolean = true\n ): Promise<Partial<User>> {\n const random = generateShortUUID(64)\n const guestLink = {\n login: random,\n email: `${random}@sync-in`,\n firstName: 'Guest',\n lastName: 'Link',\n language: language || null,\n permissions: permission,\n password: await hashPassword(password || generateShortUUID(24)),\n role: USER_ROLE.LINK,\n isActive: isActive\n } satisfies CreateUserDto\n try {\n ;(guestLink as Partial<User>).id = await this.usersQueries.createUserOrGuest(guestLink, USER_ROLE.LINK)\n return guestLink\n } catch (e) {\n this.logger.error(`${this.createGuestLink.name} - unable to create guest link : ${e}`)\n throw new HttpException('Unable to create guest link', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n /* MANAGE SHARE LINKS */\n\n async deleteAllLinkMembers(spaceOrShareId: number, type: LINK_TYPE): Promise<void> {\n const ids: { id: number; linkId: number }[] = await this.linksQueries.allLinksFromSpaceOrShare(spaceOrShareId, type)\n await this.deleteGuestLinks(ids)\n }\n\n async deleteLinkMembers(members: SpaceMemberDto[] | ShareMemberDto[]): Promise<void> {\n await this.deleteGuestLinks(members)\n }\n\n async updateSharesExternalPathQuota(shareId?: number) {\n for (const share of await this.sharesQueries.sharesQuotaExternalPaths(shareId)) {\n if (!(await isPathExists(share.externalPath))) {\n this.logger.warn(`${this.updateSharesExternalPathQuota.name} - *${share.alias}* home path does not exist`)\n continue\n }\n const [size, errors] = await dirSize(share.externalPath)\n for (const [path, error] of Object.entries(errors)) {\n this.logger.warn(`${this.updateSharesExternalPathQuota.name} - unable to get size for *${share.alias}* on ${path} : ${error}`)\n }\n const shareQuota: StorageQuota = { storageUsage: size, storageQuota: share.storageQuota }\n this.sharesQueries.cache\n .set(`${CACHE_QUOTA_SHARE_PREFIX}-${share.id}`, shareQuota, CACHE_QUOTA_TTL)\n .catch((e: Error) => this.logger.error(`${this.updateSharesExternalPathQuota.name} - ${e}`))\n if (share.storageUsage !== shareQuota.storageUsage) {\n this.logger.log(\n `${this.updateSharesExternalPathQuota.name} - share *${share.alias}* (${share.id}) : storage usage updated : ${shareQuota.storageUsage}`\n )\n await this.sharesQueries.updateShare(share.id, { storageUsage: shareQuota.storageUsage })\n }\n }\n }\n\n private async updateMembers(user: UserModel, share: Partial<Share>, oldMembers: ShareMemberDto[], currentMembers: ShareMemberDto[]) {\n if (oldMembers.length === 0 && currentMembers.length === 0) {\n return\n }\n // diff\n const [add, update, remove]: [ShareMemberDto[], Record<string | 'object', { old: any; new: any } | ShareMemberDto>[], ShareMemberDto[]] =\n diffCollection(oldMembers, currentMembers, ['permissions'], ['id', 'type'])\n\n // check members whitelists\n let toAdd: ShareMemberDto[] = []\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 share *${share.alias}* (${share.id}) : not in the members whitelist`\n )\n return false\n }\n return true\n })\n }\n\n // filter links\n const toRemove = remove.filter((m) => !m.linkId)\n // do remove links\n this.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.sharesQueries.updateMembers(share.id, toAdd, convertDiffUpdate(update), toRemove)\n\n // lists deleted and updated members as potential share owners\n const [rmMembersChildShares, upMembersChildShares]: [ShareMemberDto[], { object: ShareMemberDto; rmPermissions: SPACE_OPERATION[] }[]] = [[], []]\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 child shares from the current share\n rmMembersChildShares.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 } else if (action === ACTION.UPDATE) {\n // stores permissions updates and members who might own child shares created from the current share\n for (const m of update as { object: ShareMemberDto; permissions: { old: string; new: string } }[]) {\n if (\n ((m.object.type === MEMBER_TYPE.USER || m.object.type === MEMBER_TYPE.GUEST) && 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 const diffPermissions = differencePermissions(m.permissions.old, m.permissions.new) as SPACE_OPERATION[]\n if (diffPermissions.length) {\n upMembersChildShares.push({ object: m.object, rmPermissions: diffPermissions })\n }\n }\n }\n }\n\n // clear cache &|| notify\n this.onShareActionForMembers(share, action, members, user).catch((e: Error) => this.logger.error(`${this.updateMembers.name} - ${e}`))\n }\n\n // do updates\n // remove or update potential child shares\n this.updateMembersChildSharesPermissions(share.id, currentMembers, rmMembersChildShares, upMembersChildShares).catch((e: Error) =>\n this.logger.error(`${this.updateMembers.name} - ${e}`)\n )\n }\n\n private async updateMembersChildSharesPermissions(\n parentShareId: number,\n currentMembers: ShareMemberDto[],\n toRemove: ShareMemberDto[],\n toUpdate: { object: ShareMemberDto; rmPermissions: SPACE_OPERATION[] }[]\n ) {\n /*\n child shares of the member should be deleted if the member is removed from the parent share\n the permissions of the child shares members should be updated if the member's permissions are updated\n */\n const [removeUsersChildShares, updateUsersChildShares] = await this.diffSharesPermissions(currentMembers, toRemove, toUpdate)\n await Promise.all([\n this.removeShareFromOwners(parentShareId, removeUsersChildShares),\n this.removeChildSharesPermissions(parentShareId, updateUsersChildShares)\n ])\n }\n\n private async diffSharesPermissions(\n currentMembers: ShareMemberDto[] | SpaceMemberDto[],\n toRemove: ShareMemberDto[] | SpaceMemberDto[],\n toUpdate: { object: ShareMemberDto | SpaceMemberDto; rmPermissions: SPACE_OPERATION[] }[],\n ignoreUserIds: number[] = []\n ): Promise<[number[], { ids: number[]; rmPermissions: SPACE_OPERATION[] }[]]> {\n // remove shares from members\n const [removeUsersChildShares, removeGroupsChildShares]: number[][] = [[], []]\n for (const m of toRemove) {\n if (m.type === MEMBER_TYPE.USER || m.type === MEMBER_TYPE.GUEST) {\n if (ignoreUserIds.indexOf(m.id) > -1) {\n continue\n }\n // do not remove child shares if the user is a member of a group with share permission\n const memberGroupIds = await this.usersQueries.groupsWhitelist(m.id)\n const groupSharePermission = currentMembers.find(\n (m) =>\n (m.type === MEMBER_TYPE.GROUP || m.type === MEMBER_TYPE.PGROUP) &&\n memberGroupIds.indexOf(m.id) > -1 &&\n havePermission(m.permissions, SPACE_OPERATION.SHARE_OUTSIDE)\n )\n if (groupSharePermission) {\n this.logger.debug(\n `${this.diffSharesPermissions.name} - ignore user (${m.id}) removal : is a member of the group (${groupSharePermission.id}) with share permission`\n )\n continue\n }\n removeUsersChildShares.push(m.id)\n } else {\n removeGroupsChildShares.push(m.id)\n }\n }\n\n // update shares permissions from members\n const [updateUsersChildShares, updateGroupsChildShares]: { ids: number[]; rmPermissions: SPACE_OPERATION[] }[][] = [[], []]\n for (const m of toUpdate) {\n // all child share permissions must be updated\n if (m.object.type === MEMBER_TYPE.USER || m.object.type === MEMBER_TYPE.GUEST) {\n if (ignoreUserIds.indexOf(m.object.id) > -1) continue\n // check if the user is a member of the existing groups on the share\n // since group and user permissions are aggregated, we should check the group permissions\n const memberGroupIds = await this.usersQueries.groupsWhitelist(m.object.id)\n const groupPermissions = currentMembers\n .filter((m) => (m.type === MEMBER_TYPE.GROUP || m.type === MEMBER_TYPE.PGROUP) && memberGroupIds.indexOf(m.id) > -1)\n .reduce((perms: string[], m: ShareMemberDto) => {\n for (const p of m.permissions.split(SPACE_PERMS_SEP).filter((p: string) => p !== '' && perms.indexOf(p) === -1)) {\n perms.push(p)\n }\n return perms\n }, [])\n // find all permissions that the user must keep\n const [permsToKeep, permsToRemove]: SPACE_OPERATION[][] = [[], []]\n // compare the permissions removed from group to user's\n m.rmPermissions.forEach((p: SPACE_OPERATION) => (groupPermissions.indexOf(p) > -1 ? permsToKeep.push(p) : permsToRemove.push(p)))\n if (!permsToRemove.length) {\n // the groups provide these permissions to user, no need to update child shares\n continue\n }\n // remove only unmatched permissions\n m.rmPermissions = permsToRemove\n }\n // group members by permissions to optimize queries\n const memberTypeChildShares =\n m.object.type === MEMBER_TYPE.USER || m.object.type === MEMBER_TYPE.GUEST ? updateUsersChildShares : updateGroupsChildShares\n const memberWithSamePermissions = memberTypeChildShares.find((p) => p.rmPermissions.toString() === m.rmPermissions.toString())\n if (memberWithSamePermissions) {\n memberWithSamePermissions.ids.push(m.object.id)\n } else {\n memberTypeChildShares.push({ ids: [m.object.id], rmPermissions: m.rmPermissions })\n }\n }\n\n // retrieves all users from groups and subgroups & add them to the remove and update lists\n if (removeGroupsChildShares.length) {\n // ignore user id if the user is already removed or is a member of the parent share\n const rmUsersFromGroups = (await this.usersQueries.allUserIdsFromGroupsAndSubGroups(removeGroupsChildShares)).filter(\n (id) =>\n ignoreUserIds.indexOf(id) === -1 &&\n removeUsersChildShares.indexOf(id) === -1 &&\n !currentMembers.find((m) => (m.type === MEMBER_TYPE.USER || m.type === MEMBER_TYPE.GUEST) && m.id === id)\n )\n removeUsersChildShares.push(...rmUsersFromGroups)\n }\n if (updateGroupsChildShares.length) {\n for (const g of updateGroupsChildShares) {\n // ignore user id if the user is already removed or is a member of the parent share\n const rmUsersPermissionsFromGroups: number[] = []\n for (const uId of await this.usersQueries.allUserIdsFromGroupsAndSubGroups(g.ids)) {\n if (ignoreUserIds.indexOf(uId) > -1 || removeUsersChildShares.indexOf(uId) > -1) {\n continue\n }\n // check if the user is a member of the existing groups on the share\n // since group and user permissions are aggregated, we should check the group permissions\n const memberGroupIds = await this.usersQueries.groupsWhitelist(uId)\n const groupPermissions = currentMembers\n .filter(\n (m) =>\n ((m.type === MEMBER_TYPE.GROUP || m.type === MEMBER_TYPE.PGROUP) && memberGroupIds.indexOf(m.id) > -1) ||\n ((m.type === MEMBER_TYPE.USER || m.type === MEMBER_TYPE.GUEST) && m.id === uId)\n )\n .reduce((perms: string[], m: ShareMemberDto) => {\n for (const p of m.permissions.split(SPACE_PERMS_SEP).filter((p: string) => p !== '' && perms.indexOf(p) === -1)) {\n perms.push(p)\n }\n return perms\n }, [])\n // find all permissions that the user must keep\n const [permsToKeep, permsToRemove]: SPACE_OPERATION[][] = [[], []]\n // compare the permissions removed from group to user's\n g.rmPermissions.forEach((p: SPACE_OPERATION) => (groupPermissions.indexOf(p) > -1 ? permsToKeep.push(p) : permsToRemove.push(p)))\n if (!permsToKeep.length) {\n // user does not have the removed permissions from groups or from himself, we can remove the permissions to his child shares\n rmUsersPermissionsFromGroups.push(uId)\n } else if (permsToRemove.length) {\n // remove only unmatched permissions\n updateUsersChildShares.push({ ids: [uId], rmPermissions: permsToRemove })\n }\n }\n if (!rmUsersPermissionsFromGroups.length) continue\n // group users by permissions to optimize queries\n const memberWithSamePermissions = updateUsersChildShares.find((p) => p.rmPermissions.toString() === g.rmPermissions.toString())\n if (memberWithSamePermissions) {\n memberWithSamePermissions.ids.push(...rmUsersPermissionsFromGroups)\n } else {\n updateUsersChildShares.push({ ids: rmUsersPermissionsFromGroups, rmPermissions: g.rmPermissions })\n }\n }\n }\n return [removeUsersChildShares, updateUsersChildShares]\n }\n\n private async removeShareFromOwners(shareId: number, ownerIds: number[] | 'all', asParent: boolean = true, fromUserId?: number) {\n // deletes only the first (child) shares, child shares will be deleted in cascade\n const where = { ...(asParent ? { parentId: shareId } : { id: shareId }), ...(ownerIds !== 'all' && { ownerId: ownerIds }) }\n for (const share of await this.sharesQueries.selectShares(where)) {\n try {\n // store current child shares members before delete parent share\n const members: ShareChildMember[] = await this.sharesQueries.membersFromChildSharesPermissions(share.id, [share.ownerId], null, false)\n await this.sharesQueries.deleteShare(share.id)\n this.logger.log(`${this.removeShareFromOwners.name} - share *${share.alias}* (${share.id}) from owner (${share.ownerId}) was removed`)\n // clear cache and notify users\n if (share.ownerId && (!fromUserId || fromUserId !== share.ownerId)) {\n this.clearCachePermissionsAndOrNotify(share, ACTION.DELETE_PERMANENTLY, [share.ownerId]).catch((e: Error) =>\n this.logger.error(`${this.removeShareFromOwners.name} - ${e}`)\n )\n }\n members.forEach((m) => this.clearCachePermissionsAndOrNotify({ alias: m.shareAlias, name: m.shareName }, ACTION.DELETE, [m.userId]))\n } catch (e) {\n this.logger.error(\n `${this.removeShareFromOwners.name} - share *${share.alias}* (${share.id}) from owner (${share.ownerId}) was not removed : ${e}`\n )\n }\n }\n }\n\n private async removeChildSharesPermissions(\n shareId: number,\n userPermissions: {\n ids: number[] | 'all'\n rmPermissions: SPACE_OPERATION[]\n }[],\n asParent: boolean = true\n ) {\n // remove permissions of all members of the child shares\n if (!userPermissions.length) return\n for (const userPerm of userPermissions) {\n const members: ShareChildMember[] = await this.sharesQueries.membersFromChildSharesPermissions(\n shareId,\n userPerm.ids,\n userPerm.rmPermissions.join('|'),\n asParent\n )\n for (const m of members) {\n const permissions = removePermissions(m.userPermissions, userPerm.rmPermissions)\n try {\n await this.sharesQueries.updateMember({ permissions: permissions }, { id: m.id })\n this.clearCachePermissionsAndOrNotify(\n {\n alias: m.shareAlias,\n name: m.shareName\n },\n ACTION.UPDATE,\n [m.userId]\n ).catch((e: Error) => this.logger.error(`${this.removeChildSharesPermissions.name} - ${e}`))\n this.logger.log(\n `${this.removeChildSharesPermissions.name} - user (${m.id}) permissions ${JSON.stringify(userPerm.rmPermissions)} on share : ${m.shareAlias} (${m.shareId}) was removed`\n )\n } catch (e) {\n this.logger.error(\n `${this.removeChildSharesPermissions.name} - user (${m.id}) permissions on share *${m.shareAlias}* (${m.shareId}) was not removed : ${e}`\n )\n }\n }\n }\n }\n\n private async checkChildSharePermissions(user: UserModel, shareId: number, childId: number): Promise<boolean> {\n const isOwnerForChildShare: number = await this.sharesQueries.childExistsForShareOwner(user.id, shareId, childId, user.isAdmin)\n if (isOwnerForChildShare !== childId) {\n this.logger.warn(`${this.checkChildSharePermissions.name} - is not allowed to manage child share (${childId}) from share (${shareId})`)\n throw new HttpException('Not authorized', HttpStatus.FORBIDDEN)\n }\n return true\n }\n\n private async onShareActionForMembers(share: Partial<Share>, action: ACTION, members: { groupIds: number[]; userIds: number[] }, user?: UserModel) {\n this.clearCachePermissionsAndOrNotify(\n share,\n action,\n Array.from(new Set([...(await this.usersQueries.allUserIdsFromGroupsAndSubGroups(members.groupIds)), ...members.userIds])).filter(\n (uid) => uid !== user?.id\n ),\n user\n ).catch((e: Error) => this.logger.error(`${this.onShareActionForMembers.name} - ${e}`))\n }\n\n private async createLinkFromSpaceOrShare(\n user: UserModel,\n uuid: string,\n spaceOrShareId: number,\n type: LINK_TYPE,\n createOrUpdateLinkDto: CreateOrUpdateLinkDto\n ): Promise<void> {\n /* only used during the share creation from this manager */\n if (!(await this.linksQueries.isReservedUUID(user.id, uuid))) {\n this.logger.error(`${this.createLinkFromSpaceOrShare.name} - user attempted to use UUID (${uuid}) was not reserved`)\n throw new HttpException('UUID was not reserved', HttpStatus.BAD_REQUEST)\n }\n const permission = type === LINK_TYPE.SPACE ? GUEST_PERMISSION.SPACES : GUEST_PERMISSION.SHARES\n const guestLink: Partial<User> = await this.createGuestLink(\n permission,\n createOrUpdateLinkDto.password,\n createOrUpdateLinkDto.language,\n createOrUpdateLinkDto.isActive !== undefined ? createOrUpdateLinkDto.isActive : true\n )\n this.logger.debug(`${this.createLinkFromSpaceOrShare.name} - guest link (${guestLink.id}) created`)\n let linkId: number\n try {\n linkId = await this.linksQueries.createLinkToSpaceOrShare(guestLink.id, spaceOrShareId, type, {\n ...createOrUpdateLinkDto,\n uuid: uuid,\n userId: guestLink.id\n })\n this.logger.debug(\n `${this.createLinkFromSpaceOrShare.name} - link (${linkId}) for guest link (${guestLink.id}) created : ${JSON.stringify(createOrUpdateLinkDto)}`\n )\n } catch (e) {\n this.logger.error(`${this.createLinkFromSpaceOrShare.name} - unable to create link with uuid (${uuid}) : ${e}`)\n throw new HttpException('Unable to update link', HttpStatus.INTERNAL_SERVER_ERROR)\n }\n }\n\n private async deleteGuestLinks(guestLinks: Partial<{ id: number; linkId: number }>[]) {\n for (const guestLink of guestLinks) {\n try {\n await this.usersQueries.deleteGuestLink(guestLink.id)\n this.logger.log(`${this.deleteGuestLinks.name} - guest (${guestLink.id}) (link: ${guestLink.linkId}) was removed`)\n } catch (e) {\n this.logger.error(`${this.deleteGuestLinks.name} - guest (${guestLink.id}) (link: ${guestLink.linkId}) was not removed : ${e}`)\n }\n }\n }\n\n /* MANAGE CACHE PERMISSIONS AND NOTIFY */\n\n private async clearCachePermissionsAndOrNotify(share: Partial<Share>, action: ACTION, memberIds: number[], user?: UserModel): Promise<void> {\n if (!memberIds?.length) {\n return\n }\n this.logger.verbose(`${this.clearCachePermissionsAndOrNotify.name} - share:${share.alias} ${action} members:${JSON.stringify(memberIds)}`)\n if (action !== ACTION.ADD) {\n // clear permissions for share members\n this.sharesQueries\n .clearCachePermissions(share.alias, memberIds)\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n }\n if (action !== ACTION.UPDATE) {\n // notify the members who have joined or left the share\n const notification: NotificationContent = {\n app: NOTIFICATION_APP.SHARES,\n event: user ? NOTIFICATION_APP_EVENT.SHARES[action] : NOTIFICATION_APP_EVENT.SHARES_WITHOUT_OWNER[action],\n element: share.name,\n url: SPACE_REPOSITORY.SHARES\n }\n this.notificationsManager\n .create(memberIds, notification, {\n currentUrl: this.contextManager.get('headerOriginUrl'),\n author: user,\n action: action\n })\n .catch((e: Error) => this.logger.error(`${this.clearCachePermissionsAndOrNotify.name} - ${e}`))\n }\n }\n\n private async notifyGuestLink(user: UserModel, link: SpaceMemberDto | ShareMemberDto, spaceOrShareName: string, action: ACTION) {\n if (!link.linkSettings.email) {\n return\n }\n this.notificationsManager\n .sendEmailNotification(\n [\n {\n id: -1,\n email: link.linkSettings.email,\n language: link.linkSettings.language,\n notification: USER_NOTIFICATION.APPLICATION_EMAIL\n } satisfies UserMailNotification\n ],\n {\n app: NOTIFICATION_APP.LINKS,\n event: NOTIFICATION_APP_EVENT.LINKS[action],\n element: spaceOrShareName,\n url: null\n } satisfies NotificationContent,\n {\n author: user,\n linkUUID: link.linkSettings.uuid,\n linkPassword: link.linkSettings.password,\n currentUrl: this.contextManager.get('headerOriginUrl'),\n action: action\n } satisfies NotificationOptions\n )\n .catch((e: Error) => this.logger.error(`${this.notifyGuestLink.name} - ${e}`))\n }\n}\n"],"names":["SharesManager","permissions","user","spaceAlias","sharesQueries","id","isAdmin","listShares","listSpaceShares","spaceId","listChildShares","shareId","setAllowedPermissions","share","asAdmin","file","ownerId","externalPath","SHARE_ALL_OPERATIONS","space","alias","spacePermissions","spacesQueries","root","logger","warn","name","JSON","stringify","HttpException","HttpStatus","NOT_FOUND","spaceEnv","SpaceEnv","setPermissions","envPermissions","parent","userId","sharePermissions","error","BAD_REQUEST","getShareWithMembers","FORBIDDEN","createShare","createOrUpdateShareDto","uniqueShareAlias","description","enabled","storageQuota","storageIndexing","disabledAt","Date","type","SHARE_TYPE","COMMON","checkExternalPath","e","message","FileError","httpCode","INTERNAL_SERVER_ERROR","realPath","path","join","filesPath","isPathExists","fileProps","getProps","fileId","getOrCreateUserFile","m","members","intersectPermissions","l","links","setPaths","split","slice","spaceRootId","isExternalSpaceRoot","isSpaceRoot","Number","dbFile","undefined","getOrCreateSpaceFile","createOrUpdateLinksAsMembers","LINK_TYPE","SHARE","updateMembers","updateShare","shareDiffProps","modifiedAt","props","prop","linkMembers","deleteShare","shareExistsForOwner","deleteAllLinkMembers","removeShareFromOwners","getChildShare","childId","isLink","checkChildSharePermissions","getShareLink","updateChildShare","deleteChildShare","createChildShare","pSharePermissions","haveSpacePermission","SPACE_OPERATION","SHARE_OUTSIDE","pShare","filePath","highestParentId","findHighestParentShare","shareEnv","pShareEnv","isLinkedToShareSpaceRoot","isLinkedToShareExternalPath","parentId","updateSharesFromSpace","currentMembers","toRemove","toUpdate","length","spaceManagerIds","filter","spaceRole","SPACE_ROLE","IS_MANAGER","map","rmOwners","upOwners","diffSharesPermissions","owners","Object","fromEntries","uId","ACTION","DELETE","reduce","acc","o","ids","push","UPDATE","rmPermissions","selectParentSharesFromSpaceId","keys","parseInt","action","removeChildSharesPermissions","catch","log","updateSharesFromSpaceRoots","selectShares","rootId","removeSharesFromSpace","generateLinkUUID","uuid","generateShortUUID","linksQueries","isUniqueUUID","listShareLinks","shareLink","removePermissions","SHARE_INSIDE","getLinkFromSpaceOrShare","linkId","spaceOrShareId","linkGuest","SPACE","linkFromSpace","linkFromShare","spaceOrShare","link","createLinkFromSpaceOrShare","linkSettings","notifyGuestLink","ADD","updateLinkFromSpaceOrShare","createOrUpdateLinkDto","fromAPI","fieldsWhiteList","updateUser","updateLink","updateMember","k","v","entries","indexOf","password","hashPassword","language","isActive","debug","anonymizePassword","member","assign","createGuestLink","permission","random","guestLink","login","email","firstName","lastName","role","USER_ROLE","LINK","usersQueries","createUserOrGuest","allLinksFromSpaceOrShare","deleteGuestLinks","deleteLinkMembers","updateSharesExternalPathQuota","sharesQuotaExternalPaths","size","errors","dirSize","shareQuota","storageUsage","cache","set","CACHE_QUOTA_SHARE_PREFIX","CACHE_QUOTA_TTL","oldMembers","add","update","remove","diffCollection","toAdd","userIdsWhitelist","groupIdsWhitelist","Promise","all","usersWhitelist","groupsWhitelist","MEMBER_TYPE","USER","GUEST","GROUP","PGROUP","status","convertDiffUpdate","rmMembersChildShares","upMembersChildShares","userIds","groupIds","object","diffPermissions","differencePermissions","old","new","onShareActionForMembers","updateMembersChildSharesPermissions","parentShareId","removeUsersChildShares","updateUsersChildShares","ignoreUserIds","removeGroupsChildShares","memberGroupIds","groupSharePermission","find","havePermission","updateGroupsChildShares","groupPermissions","perms","p","SPACE_PERMS_SEP","permsToKeep","permsToRemove","forEach","memberTypeChildShares","memberWithSamePermissions","toString","rmUsersFromGroups","allUserIdsFromGroupsAndSubGroups","g","rmUsersPermissionsFromGroups","ownerIds","asParent","fromUserId","where","membersFromChildSharesPermissions","clearCachePermissionsAndOrNotify","DELETE_PERMANENTLY","shareAlias","shareName","userPermissions","userPerm","isOwnerForChildShare","childExistsForShareOwner","Array","from","Set","uid","isReservedUUID","GUEST_PERMISSION","SPACES","SHARES","createLinkToSpaceOrShare","guestLinks","deleteGuestLink","memberIds","verbose","clearCachePermissions","notification","app","NOTIFICATION_APP","event","NOTIFICATION_APP_EVENT","SHARES_WITHOUT_OWNER","element","url","SPACE_REPOSITORY","notificationsManager","create","currentUrl","contextManager","get","author","spaceOrShareName","sendEmailNotification","USER_NOTIFICATION","APPLICATION_EMAIL","LINKS","linkUUID","linkPassword","Logger"],"mappings":"AAAA;;;;CAIC;;;;+BAsDYA;;;eAAAA;;;wBApDiD;iEAC7C;2BACM;2BAShB;uCAEwB;2BAEL;uBACyC;uBACzC;qCAIG;+BAC4B;6CAGpB;uBACqB;wBACqB;+BAEtD;sCAEK;6BACyC;wBAC3C;sBACmC;qCAIlC;wBACoB;sCAUnB;;;;;;;;;;;;;;;AAGvB,IAAA,AAAMA,gBAAN,MAAMA;IAYXC,YAAYC,IAAe,EAAEC,UAAkB,EAAE;QAC/C,OAAO,IAAI,CAACC,aAAa,CAACH,WAAW,CAACC,KAAKG,EAAE,EAAEF,YAAY,CAACD,KAAKI,OAAO;IAC1E;IAEAC,WAAWL,IAAe,EAAwB;QAChD,OAAO,IAAI,CAACE,aAAa,CAACG,UAAU,CAACL;IACvC;IAEAM,gBAAgBC,OAAe,EAAyB;QACtD,OAAO,IAAI,CAACL,aAAa,CAACI,eAAe,CAACC;IAC5C;IAEAC,gBAAgBR,IAAe,EAAES,OAAe,EAAyB;QACvE,OAAO,IAAI,CAACP,aAAa,CAACM,eAAe,CAACR,KAAKG,EAAE,EAAEM,SAAS,CAACT,KAAKI,OAAO;IAC3E;IAEA,MAAMM,sBAAsBV,IAAe,EAAEW,KAA6B,EAAEC,UAAU,KAAK,EAAE;QAC3F,IAAID,MAAME,IAAI,EAAEC,YAAYd,KAAKG,EAAE,IAAKQ,MAAMI,YAAY,IAAIf,KAAKI,OAAO,EAAG;YAC3E,uDAAuD;YACvDO,MAAME,IAAI,CAACd,WAAW,GAAGiB,4BAAoB;QAC/C,OAAO,IAAIL,MAAME,IAAI,EAAEI,OAAOC,OAAO;YACnCP,MAAME,IAAI,CAACC,OAAO,GAAG;YACrB,4CAA4C;YAC5C,MAAMK,mBAAsC,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S;YACTR,KAAK;QACP,GACA;YACEO,QAAQ/T;YACRqU,UAAUxJ,KAAKE,YAAY,CAAClB,IAAI;YAChCyK,cAAczJ,KAAKE,YAAY,CAACc,QAAQ;YACxC+H,YAAY,IAAI,CAACC,cAAc,CAACC,GAAG,CAAC;YACpC1K,QAAQA;QACV,GAEDE,KAAK,CAAC,CAAChG,IAAa,IAAI,CAAChC,MAAM,CAACe,KAAK,CAAC,GAAG,IAAI,CAAC2I,eAAe,CAACxJ,IAAI,CAAC,GAAG,EAAE8B,GAAG;IAChF;IA5kCA,YACE,AAAiBuQ,cAA8B,EAC/C,AAAiBH,oBAA0C,EAC3D,AAAiBxT,aAA4B,EAC7C,AAAiBkB,aAA4B,EAC7C,AAAiB4L,YAA0B,EAC3C,AAAiBjD,YAA0B,CAC3C;aANiB8J,iBAAAA;aACAH,uBAAAA;aACAxT,gBAAAA;aACAkB,gBAAAA;aACA4L,eAAAA;aACAjD,eAAAA;aARFzI,SAAS,IAAIiT,cAAM,CAACzU,cAAc0B,IAAI;IASpD;AAskCL"}
@@ -138,6 +138,19 @@ let SharesQueries = class SharesQueries {
138
138
  ownerId: _sharesschema.shares.ownerId
139
139
  }).from(_sharesschema.shares).where((0, _drizzleorm.and)(...where));
140
140
  }
141
+ sharesQuotaExternalPaths(shareId) {
142
+ return this.db.select({
143
+ id: _sharesschema.shares.id,
144
+ alias: _sharesschema.shares.alias,
145
+ storageUsage: _sharesschema.shares.storageUsage,
146
+ storageQuota: _sharesschema.shares.storageQuota,
147
+ externalPath: _sharesschema.shares.externalPath
148
+ }).from(_sharesschema.shares).where((0, _drizzleorm.and)((0, _drizzleorm.isNotNull)(_sharesschema.shares.externalPath), ...[
149
+ ...shareId ? [
150
+ (0, _drizzleorm.eq)(_sharesschema.shares.id, shareId)
151
+ ] : []
152
+ ]));
153
+ }
141
154
  async listShareLinks(user, shareId, asAdmin = false) {
142
155
  if (!this.shareLinksListQuery) {
143
156
  const [selectFile, shareRootFile, parentShare, parentShareFile, childShareFromRoot, shareMembers] = this.shareFileSelect();
@@ -200,6 +213,9 @@ let SharesQueries = class SharesQueries {
200
213
  externalPath: (0, _drizzleorm.sql)`IF (${_sharesschema.shares.externalPath} IS NOT NULL AND ${_sharesschema.shares.ownerId} IS NOT NULL, '.', ${_sharesschema.shares.externalPath})`,
201
214
  enabled: _sharesschema.shares.enabled,
202
215
  description: _sharesschema.shares.description,
216
+ storageUsage: _sharesschema.shares.storageUsage,
217
+ storageQuota: _sharesschema.shares.storageQuota,
218
+ storageIndexing: _sharesschema.shares.storageIndexing,
203
219
  createdAt: _sharesschema.shares.createdAt,
204
220
  modifiedAt: _sharesschema.shares.modifiedAt,
205
221
  disabledAt: _sharesschema.shares.disabledAt,
@@ -258,13 +274,14 @@ let SharesQueries = class SharesQueries {
258
274
  async createShare(share) {
259
275
  return (0, _utils.dbGetInsertedId)(await this.db.insert(_sharesschema.shares).values(share));
260
276
  }
261
- async updateShare(set, filters) {
262
- const where = (0, _utils.convertToWhere)(_sharesschema.shares, filters);
277
+ async updateShare(id, set) {
263
278
  try {
264
- (0, _utils.dbCheckAffectedRows)(await this.db.update(_sharesschema.shares).set(set).where((0, _drizzleorm.and)(...where)).limit(1), 1);
265
- this.logger.debug(`${this.updateShare.name} - ${JSON.stringify(filters)} was updated : ${JSON.stringify(set)}`);
279
+ (0, _utils.dbCheckAffectedRows)(await this.db.update(_sharesschema.shares).set(set).where((0, _drizzleorm.eq)(_sharesschema.shares.id, id)).limit(1), 1);
280
+ this.logger.debug(`${this.updateShare.name} - share (${id}) was updated : ${JSON.stringify(set)}`);
281
+ return true;
266
282
  } catch (e) {
267
- this.logger.error(`${this.updateShare.name} - ${JSON.stringify(filters)} was not updated : ${JSON.stringify(set)} : ${e}`);
283
+ this.logger.error(`${this.updateShare.name} - share (${id}) was not updated : ${JSON.stringify(set)} : ${e}`);
284
+ return false;
268
285
  }
269
286
  }
270
287
  async deleteShare(shareId) {
@@ -716,6 +733,8 @@ let SharesQueries = class SharesQueries {
716
733
  };
717
734
  this.sharePermissionsQuery = this.db.select(select).from(unionAlias).groupBy(unionAlias.id).limit(1).prepare();
718
735
  }
736
+ // `userId` is used in `fromUserQuery` and `fromGroupsQuery` function
737
+ // `isAdmin` is used in `fromAdminSharesQuery` function
719
738
  const [r] = await this.sharePermissionsQuery.execute({
720
739
  userId,
721
740
  shareAlias,