IShareProvider.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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\Share\Exceptions\GenericShareException;
  11. use OCP\Share\Exceptions\ShareNotFound;
  12. /**
  13. * Interface IShareProvider
  14. *
  15. * @since 9.0.0
  16. */
  17. interface IShareProvider {
  18. /**
  19. * Return the identifier of this provider.
  20. *
  21. * @return string Containing only [a-zA-Z0-9]
  22. * @since 9.0.0
  23. */
  24. public function identifier();
  25. /**
  26. * Create a share
  27. *
  28. * @param \OCP\Share\IShare $share
  29. * @return \OCP\Share\IShare The share object
  30. * @since 9.0.0
  31. */
  32. public function create(\OCP\Share\IShare $share);
  33. /**
  34. * Update a share
  35. *
  36. * @param \OCP\Share\IShare $share
  37. * @return \OCP\Share\IShare The share object
  38. * @since 9.0.0
  39. */
  40. public function update(\OCP\Share\IShare $share);
  41. /**
  42. * Delete a share
  43. *
  44. * @param \OCP\Share\IShare $share
  45. * @since 9.0.0
  46. */
  47. public function delete(\OCP\Share\IShare $share);
  48. /**
  49. * Unshare a file from self as recipient.
  50. * This may require special handling. If a user unshares a group
  51. * share from their self then the original group share should still exist.
  52. *
  53. * @param \OCP\Share\IShare $share
  54. * @param string $recipient UserId of the recipient
  55. * @since 9.0.0
  56. */
  57. public function deleteFromSelf(\OCP\Share\IShare $share, $recipient);
  58. /**
  59. * Restore a share for a given recipient. The implementation could be provider independant.
  60. *
  61. * @param IShare $share
  62. * @param string $recipient
  63. * @return IShare The restored share object
  64. *
  65. * @since 14.0.0
  66. * @throws GenericShareException In case the share could not be restored
  67. */
  68. public function restore(IShare $share, string $recipient): IShare;
  69. /**
  70. * Move a share as a recipient.
  71. * This is updating the share target. Thus the mount point of the recipient.
  72. * This may require special handling. If a user moves a group share
  73. * the target should only be changed for them.
  74. *
  75. * @param \OCP\Share\IShare $share
  76. * @param string $recipient userId of recipient
  77. * @return \OCP\Share\IShare
  78. * @since 9.0.0
  79. */
  80. public function move(\OCP\Share\IShare $share, $recipient);
  81. /**
  82. * Get all shares by the given user in a folder
  83. *
  84. * @param string $userId
  85. * @param Folder $node
  86. * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
  87. * @param bool $shallow Whether the method should stop at the first level, or look into sub-folders.
  88. * @return \OCP\Share\IShare[][]
  89. * @since 11.0.0
  90. */
  91. public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true);
  92. /**
  93. * Get all shares by the given user
  94. *
  95. * @param string $userId
  96. * @param int $shareType
  97. * @param Node|null $node
  98. * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
  99. * @param int $limit The maximum number of shares to be returned, -1 for all shares
  100. * @param int $offset
  101. * @return \OCP\Share\IShare[]
  102. * @since 9.0.0
  103. */
  104. public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset);
  105. /**
  106. * Get share by id
  107. *
  108. * @param int $id
  109. * @param string|null $recipientId
  110. * @return \OCP\Share\IShare
  111. * @throws ShareNotFound
  112. * @since 9.0.0
  113. */
  114. public function getShareById($id, $recipientId = null);
  115. /**
  116. * Get shares for a given path
  117. *
  118. * @param Node $path
  119. * @return \OCP\Share\IShare[]
  120. * @since 9.0.0
  121. */
  122. public function getSharesByPath(Node $path);
  123. /**
  124. * Get shared with the given user
  125. *
  126. * @param string $userId get shares where this user is the recipient
  127. * @param int $shareType
  128. * @param Node|null $node
  129. * @param int $limit The max number of entries returned, -1 for all
  130. * @param int $offset
  131. * @return \OCP\Share\IShare[]
  132. * @since 9.0.0
  133. */
  134. public function getSharedWith($userId, $shareType, $node, $limit, $offset);
  135. /**
  136. * Get a share by token
  137. *
  138. * @param string $token
  139. * @return \OCP\Share\IShare
  140. * @throws ShareNotFound
  141. * @since 9.0.0
  142. */
  143. public function getShareByToken($token);
  144. /**
  145. * A user is deleted from the system
  146. * So clean up the relevant shares.
  147. *
  148. * @param string $uid
  149. * @param int $shareType
  150. * @since 9.1.0
  151. */
  152. public function userDeleted($uid, $shareType);
  153. /**
  154. * A group is deleted from the system.
  155. * We have to clean up all shares to this group.
  156. * Providers not handling group shares should just return
  157. *
  158. * @param string $gid
  159. * @since 9.1.0
  160. */
  161. public function groupDeleted($gid);
  162. /**
  163. * A user is deleted from a group
  164. * We have to clean up all the related user specific group shares
  165. * Providers not handling group shares should just return
  166. *
  167. * @param string $uid
  168. * @param string $gid
  169. * @since 9.1.0
  170. */
  171. public function userDeletedFromGroup($uid, $gid);
  172. /**
  173. * Get the access list to the array of provided nodes.
  174. *
  175. * @see IManager::getAccessList() for sample docs
  176. *
  177. * @param Node[] $nodes The list of nodes to get access for
  178. * @param bool $currentAccess If current access is required (like for removed shares that might get revived later)
  179. * @return array
  180. * @since 12
  181. */
  182. public function getAccessList($nodes, $currentAccess);
  183. /**
  184. * Get all the shares in this provider returned as iterable to reduce memory
  185. * overhead
  186. *
  187. * @return iterable
  188. * @since 18.0.0
  189. */
  190. public function getAllShares(): iterable;
  191. }