1
0

IManager.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCP\Share;
  8. use OCP\Files\Folder;
  9. use OCP\Files\Node;
  10. use OCP\IUser;
  11. use OCP\Share\Exceptions\GenericShareException;
  12. use OCP\Share\Exceptions\ShareNotFound;
  13. /**
  14. * This interface allows to manage sharing files between users and groups.
  15. *
  16. * This interface must not be implemented in your application but
  17. * instead should be used as a service and injected in your code with
  18. * dependency injection.
  19. *
  20. * @since 9.0.0
  21. */
  22. interface IManager {
  23. /**
  24. * Create a Share
  25. *
  26. * @param IShare $share
  27. * @return IShare The share object
  28. * @throws \Exception
  29. * @since 9.0.0
  30. */
  31. public function createShare(IShare $share);
  32. /**
  33. * Update a share.
  34. * The target of the share can't be changed this way: use moveShare
  35. * The share can't be removed this way (permission 0): use deleteShare
  36. * The state can't be changed this way: use acceptShare
  37. *
  38. * @param IShare $share
  39. * @param bool $onlyValid Only updates valid shares, invalid shares will be deleted automatically and are not updated
  40. * @return IShare The share object
  41. * @throws \InvalidArgumentException
  42. * @since 9.0.0
  43. */
  44. public function updateShare(IShare $share, bool $onlyValid = true);
  45. /**
  46. * Accept a share.
  47. *
  48. * @param IShare $share
  49. * @param string $recipientId
  50. * @return IShare The share object
  51. * @throws \InvalidArgumentException
  52. * @since 18.0.0
  53. */
  54. public function acceptShare(IShare $share, string $recipientId): IShare;
  55. /**
  56. * Delete a share
  57. *
  58. * @param IShare $share
  59. * @throws ShareNotFound
  60. * @throws \InvalidArgumentException
  61. * @since 9.0.0
  62. */
  63. public function deleteShare(IShare $share);
  64. /**
  65. * Unshare a file as the recipient.
  66. * This can be different from a regular delete for example when one of
  67. * the users in a groups deletes that share. But the provider should
  68. * handle this.
  69. *
  70. * @param IShare $share
  71. * @param string $recipientId
  72. * @since 9.0.0
  73. */
  74. public function deleteFromSelf(IShare $share, $recipientId);
  75. /**
  76. * Restore the share when it has been deleted
  77. * Certain share types can be restored when they have been deleted
  78. * but the provider should properly handle this\
  79. *
  80. * @param IShare $share The share to restore
  81. * @param string $recipientId The user to restore the share for
  82. * @return IShare The restored share object
  83. * @throws GenericShareException In case restoring the share failed
  84. *
  85. * @since 14.0.0
  86. */
  87. public function restoreShare(IShare $share, string $recipientId): IShare;
  88. /**
  89. * Move the share as a recipient of the share.
  90. * This is updating the share target. So where the recipient has the share mounted.
  91. *
  92. * @param IShare $share
  93. * @param string $recipientId
  94. * @return IShare
  95. * @throws \InvalidArgumentException If $share is a link share or the $recipient does not match
  96. * @since 9.0.0
  97. */
  98. public function moveShare(IShare $share, $recipientId);
  99. /**
  100. * Get all shares shared by (initiated) by the provided user in a folder.
  101. *
  102. * @param string $userId
  103. * @param Folder $node
  104. * @param bool $reshares
  105. * @param bool $shallow Whether the method should stop at the first level, or look into sub-folders.
  106. * @return IShare[][] [$fileId => IShare[], ...]
  107. * @since 11.0.0
  108. */
  109. public function getSharesInFolder($userId, Folder $node, $reshares = false, $shallow = true);
  110. /**
  111. * Get shares shared by (initiated) by the provided user.
  112. *
  113. * @param string $userId
  114. * @param int $shareType
  115. * @param Node|null $path
  116. * @param bool $reshares
  117. * @param int $limit The maximum number of returned results, -1 for all results
  118. * @param int $offset
  119. * @param bool $onlyValid Only returns valid shares, invalid shares will be deleted automatically and are not returned
  120. * @return IShare[]
  121. * @since 9.0.0
  122. */
  123. public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0, bool $onlyValid = true);
  124. /**
  125. * Get shares shared with $user.
  126. * Filter by $node if provided
  127. *
  128. * @param string $userId
  129. * @param int $shareType
  130. * @param Node|null $node
  131. * @param int $limit The maximum number of shares returned, -1 for all
  132. * @param int $offset
  133. * @return IShare[]
  134. * @since 9.0.0
  135. */
  136. public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0);
  137. /**
  138. * Get deleted shares shared with $user.
  139. * Filter by $node if provided
  140. *
  141. * @param string $userId
  142. * @param int $shareType
  143. * @param Node|null $node
  144. * @param int $limit The maximum number of shares returned, -1 for all
  145. * @param int $offset
  146. * @return IShare[]
  147. * @since 14.0.0
  148. */
  149. public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0);
  150. /**
  151. * Retrieve a share by the share id.
  152. * If the recipient is set make sure to retrieve the file for that user.
  153. * This makes sure that if a user has moved/deleted a group share this
  154. * is reflected.
  155. *
  156. * @param string $id
  157. * @param string|null $recipient userID of the recipient
  158. * @param bool $onlyValid Only returns valid shares, invalid shares will be deleted automatically and are not returned
  159. * @return IShare
  160. * @throws ShareNotFound
  161. * @since 9.0.0
  162. */
  163. public function getShareById($id, $recipient = null, bool $onlyValid = true);
  164. /**
  165. * Get the share by token possible with password
  166. *
  167. * @param string $token
  168. * @return IShare
  169. * @throws ShareNotFound
  170. * @since 9.0.0
  171. */
  172. public function getShareByToken($token);
  173. /**
  174. * Verify the password of a public share
  175. *
  176. * @param IShare $share
  177. * @param ?string $password
  178. * @return bool
  179. * @since 9.0.0
  180. */
  181. public function checkPassword(IShare $share, $password);
  182. /**
  183. * The user with UID is deleted.
  184. * All share providers have to cleanup the shares with this user as well
  185. * as shares owned by this user.
  186. * Shares only initiated by this user are fine.
  187. *
  188. * @param string $uid
  189. * @since 9.1.0
  190. */
  191. public function userDeleted($uid);
  192. /**
  193. * The group with $gid is deleted
  194. * We need to clear up all shares to this group
  195. *
  196. * @param string $gid
  197. * @since 9.1.0
  198. */
  199. public function groupDeleted($gid);
  200. /**
  201. * The user $uid is deleted from the group $gid
  202. * All user specific group shares have to be removed
  203. *
  204. * @param string $uid
  205. * @param string $gid
  206. * @since 9.1.0
  207. */
  208. public function userDeletedFromGroup($uid, $gid);
  209. /**
  210. * Get access list to a path. This means
  211. * all the users that can access a given path.
  212. *
  213. * Consider:
  214. * -root
  215. * |-folder1 (23)
  216. * |-folder2 (32)
  217. * |-fileA (42)
  218. *
  219. * fileA is shared with user1 and user1@server1 and email1@maildomain1
  220. * folder2 is shared with group2 (user4 is a member of group2)
  221. * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2
  222. * and email2@maildomain2
  223. *
  224. * Then the access list to '/folder1/folder2/fileA' with $currentAccess is:
  225. * [
  226. * users => [
  227. * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'],
  228. * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'],
  229. * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'],
  230. * ],
  231. * remote => [
  232. * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'],
  233. * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'],
  234. * ],
  235. * public => bool
  236. * mail => [
  237. * 'email1@maildomain1' => ['node_id' => 42, 'token' => 'aBcDeFg'],
  238. * 'email2@maildomain2' => ['node_id' => 23, 'token' => 'hIjKlMn'],
  239. * ]
  240. *
  241. * The access list to '/folder1/folder2/fileA' **without** $currentAccess is:
  242. * [
  243. * users => ['user1', 'user2', 'user4'],
  244. * remote => bool,
  245. * public => bool
  246. * mail => ['email1@maildomain1', 'email2@maildomain2']
  247. * ]
  248. *
  249. * This is required for encryption/activity
  250. *
  251. * @param \OCP\Files\Node $path
  252. * @param bool $recursive Should we check all parent folders as well
  253. * @param bool $currentAccess Should the user have currently access to the file
  254. * @return array
  255. * @since 12
  256. */
  257. public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false);
  258. /**
  259. * Instantiates a new share object. This is to be passed to
  260. * createShare.
  261. *
  262. * @return IShare
  263. * @since 9.0.0
  264. */
  265. public function newShare();
  266. /**
  267. * Is the share API enabled
  268. *
  269. * @return bool
  270. * @since 9.0.0
  271. */
  272. public function shareApiEnabled();
  273. /**
  274. * Is public link sharing enabled
  275. *
  276. * @return bool
  277. * @since 9.0.0
  278. */
  279. public function shareApiAllowLinks();
  280. /**
  281. * Is password on public link required
  282. *
  283. * @param bool $checkGroupMembership Check group membership exclusion
  284. * @return bool
  285. * @since 9.0.0
  286. * @since 24.0.0 Added optional $checkGroupMembership parameter
  287. */
  288. public function shareApiLinkEnforcePassword(bool $checkGroupMembership = true);
  289. /**
  290. * Is default expire date enabled
  291. *
  292. * @return bool
  293. * @since 9.0.0
  294. */
  295. public function shareApiLinkDefaultExpireDate();
  296. /**
  297. * Is default expire date enforced
  298. *`
  299. * @return bool
  300. * @since 9.0.0
  301. */
  302. public function shareApiLinkDefaultExpireDateEnforced();
  303. /**
  304. * Number of default expire days
  305. *
  306. * @return int
  307. * @since 9.0.0
  308. */
  309. public function shareApiLinkDefaultExpireDays();
  310. /**
  311. * Is default internal expire date enabled
  312. *
  313. * @return bool
  314. * @since 22.0.0
  315. */
  316. public function shareApiInternalDefaultExpireDate(): bool;
  317. /**
  318. * Is default remote expire date enabled
  319. *
  320. * @return bool
  321. * @since 22.0.0
  322. */
  323. public function shareApiRemoteDefaultExpireDate(): bool;
  324. /**
  325. * Is default expire date enforced
  326. *
  327. * @return bool
  328. * @since 22.0.0
  329. */
  330. public function shareApiInternalDefaultExpireDateEnforced(): bool;
  331. /**
  332. * Is default expire date enforced for remote shares
  333. *
  334. * @return bool
  335. * @since 22.0.0
  336. */
  337. public function shareApiRemoteDefaultExpireDateEnforced(): bool;
  338. /**
  339. * Number of default expire days
  340. *
  341. * @return int
  342. * @since 22.0.0
  343. */
  344. public function shareApiInternalDefaultExpireDays(): int;
  345. /**
  346. * Number of default expire days for remote shares
  347. *
  348. * @return int
  349. * @since 22.0.0
  350. */
  351. public function shareApiRemoteDefaultExpireDays(): int;
  352. /**
  353. * Allow public upload on link shares
  354. *
  355. * @return bool
  356. * @since 9.0.0
  357. */
  358. public function shareApiLinkAllowPublicUpload();
  359. /**
  360. * check if user can only share with group members
  361. * @return bool
  362. * @since 9.0.0
  363. */
  364. public function shareWithGroupMembersOnly();
  365. /**
  366. * If shareWithGroupMembersOnly is enabled, return an optional
  367. * list of groups that must be excluded from the principle of
  368. * belonging to the same group.
  369. * @return array
  370. * @since 27.0.0
  371. */
  372. public function shareWithGroupMembersOnlyExcludeGroupsList();
  373. /**
  374. * Check if users can share with groups
  375. * @return bool
  376. * @since 9.0.1
  377. */
  378. public function allowGroupSharing();
  379. /**
  380. * Check if user enumeration is allowed
  381. *
  382. * @return bool
  383. * @since 19.0.0
  384. */
  385. public function allowEnumeration(): bool;
  386. /**
  387. * Check if user enumeration is limited to the users groups
  388. *
  389. * @return bool
  390. * @since 19.0.0
  391. */
  392. public function limitEnumerationToGroups(): bool;
  393. /**
  394. * Check if user enumeration is limited to the phonebook matches
  395. *
  396. * @return bool
  397. * @since 21.0.1
  398. */
  399. public function limitEnumerationToPhone(): bool;
  400. /**
  401. * Check if user enumeration is allowed to return on full match
  402. *
  403. * @return bool
  404. * @since 21.0.1
  405. */
  406. public function allowEnumerationFullMatch(): bool;
  407. /**
  408. * Check if the search should match the email
  409. *
  410. * @return bool
  411. * @since 25.0.0
  412. */
  413. public function matchEmail(): bool;
  414. /**
  415. * Check if the search should ignore the second in parentheses display name if there is any
  416. *
  417. * @return bool
  418. * @since 25.0.0
  419. */
  420. public function ignoreSecondDisplayName(): bool;
  421. /**
  422. * Check if the current user can enumerate the target user
  423. *
  424. * @param IUser|null $currentUser
  425. * @param IUser $targetUser
  426. * @return bool
  427. * @since 23.0.0
  428. */
  429. public function currentUserCanEnumerateTargetUser(?IUser $currentUser, IUser $targetUser): bool;
  430. /**
  431. * Check if sharing is disabled for the given user
  432. *
  433. * @param string $userId
  434. * @return bool
  435. * @since 9.0.0
  436. */
  437. public function sharingDisabledForUser($userId);
  438. /**
  439. * Check if outgoing server2server shares are allowed
  440. * @return bool
  441. * @since 9.0.0
  442. */
  443. public function outgoingServer2ServerSharesAllowed();
  444. /**
  445. * Check if outgoing server2server shares are allowed
  446. * @return bool
  447. * @since 14.0.0
  448. */
  449. public function outgoingServer2ServerGroupSharesAllowed();
  450. /**
  451. * Check if a given share provider exists
  452. * @param int $shareType
  453. * @return bool
  454. * @since 11.0.0
  455. */
  456. public function shareProviderExists($shareType);
  457. /**
  458. * @param string $shareProviderClass
  459. * @since 21.0.0
  460. */
  461. public function registerShareProvider(string $shareProviderClass): void;
  462. /**
  463. * @Internal
  464. *
  465. * Get all the shares as iterable to reduce memory overhead
  466. * Note, since this opens up database cursors the iterable should
  467. * be fully itterated.
  468. *
  469. * @return iterable
  470. * @since 18.0.0
  471. */
  472. public function getAllShares(): iterable;
  473. }