IManager.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OCP\Share;
  30. use OCP\Files\Folder;
  31. use OCP\Files\Node;
  32. use OCP\Share\Exceptions\GenericShareException;
  33. use OCP\Share\Exceptions\ShareNotFound;
  34. /**
  35. * Interface IManager
  36. *
  37. * @package OCP\Share
  38. * @since 9.0.0
  39. */
  40. interface IManager {
  41. /**
  42. * Create a Share
  43. *
  44. * @param IShare $share
  45. * @return IShare The share object
  46. * @throws \Exception
  47. * @since 9.0.0
  48. */
  49. public function createShare(IShare $share);
  50. /**
  51. * Update a share.
  52. * The target of the share can't be changed this way: use moveShare
  53. * The share can't be removed this way (permission 0): use deleteShare
  54. * The state can't be changed this way: use acceptShare
  55. *
  56. * @param IShare $share
  57. * @return IShare The share object
  58. * @throws \InvalidArgumentException
  59. * @since 9.0.0
  60. */
  61. public function updateShare(IShare $share);
  62. /**
  63. * Accept a share.
  64. *
  65. * @param IShare $share
  66. * @param string $recipientId
  67. * @return IShare The share object
  68. * @throws \InvalidArgumentException
  69. * @since 18.0.0
  70. */
  71. public function acceptShare(IShare $share, string $recipientId): IShare;
  72. /**
  73. * Delete a share
  74. *
  75. * @param IShare $share
  76. * @throws ShareNotFound
  77. * @throws \InvalidArgumentException
  78. * @since 9.0.0
  79. */
  80. public function deleteShare(IShare $share);
  81. /**
  82. * Unshare a file as the recipient.
  83. * This can be different from a regular delete for example when one of
  84. * the users in a groups deletes that share. But the provider should
  85. * handle this.
  86. *
  87. * @param IShare $share
  88. * @param string $recipientId
  89. * @since 9.0.0
  90. */
  91. public function deleteFromSelf(IShare $share, $recipientId);
  92. /**
  93. * Restore the share when it has been deleted
  94. * Certain share types can be restored when they have been deleted
  95. * but the provider should properly handle this\
  96. *
  97. * @param IShare $share The share to restore
  98. * @param string $recipientId The user to restore the share for
  99. * @return IShare The restored share object
  100. * @throws GenericShareException In case restoring the share failed
  101. *
  102. * @since 14.0.0
  103. */
  104. public function restoreShare(IShare $share, string $recipientId): IShare;
  105. /**
  106. * Move the share as a recipient of the share.
  107. * This is updating the share target. So where the recipient has the share mounted.
  108. *
  109. * @param IShare $share
  110. * @param string $recipientId
  111. * @return IShare
  112. * @throws \InvalidArgumentException If $share is a link share or the $recipient does not match
  113. * @since 9.0.0
  114. */
  115. public function moveShare(IShare $share, $recipientId);
  116. /**
  117. * Get all shares shared by (initiated) by the provided user in a folder.
  118. *
  119. * @param string $userId
  120. * @param Folder $node
  121. * @param bool $reshares
  122. * @return IShare[][] [$fileId => IShare[], ...]
  123. * @since 11.0.0
  124. */
  125. public function getSharesInFolder($userId, Folder $node, $reshares = false);
  126. /**
  127. * Get shares shared by (initiated) by the provided user.
  128. *
  129. * @param string $userId
  130. * @param int $shareType
  131. * @param Node|null $path
  132. * @param bool $reshares
  133. * @param int $limit The maximum number of returned results, -1 for all results
  134. * @param int $offset
  135. * @return IShare[]
  136. * @since 9.0.0
  137. */
  138. public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0);
  139. /**
  140. * Get shares shared with $user.
  141. * Filter by $node if provided
  142. *
  143. * @param string $userId
  144. * @param int $shareType
  145. * @param Node|null $node
  146. * @param int $limit The maximum number of shares returned, -1 for all
  147. * @param int $offset
  148. * @return IShare[]
  149. * @since 9.0.0
  150. */
  151. public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0);
  152. /**
  153. * Get deleted shares shared with $user.
  154. * Filter by $node if provided
  155. *
  156. * @param string $userId
  157. * @param int $shareType
  158. * @param Node|null $node
  159. * @param int $limit The maximum number of shares returned, -1 for all
  160. * @param int $offset
  161. * @return IShare[]
  162. * @since 14.0.0
  163. */
  164. public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0);
  165. /**
  166. * Retrieve a share by the share id.
  167. * If the recipient is set make sure to retrieve the file for that user.
  168. * This makes sure that if a user has moved/deleted a group share this
  169. * is reflected.
  170. *
  171. * @param string $id
  172. * @param string|null $recipient userID of the recipient
  173. * @return IShare
  174. * @throws ShareNotFound
  175. * @since 9.0.0
  176. */
  177. public function getShareById($id, $recipient = null);
  178. /**
  179. * Get the share by token possible with password
  180. *
  181. * @param string $token
  182. * @return IShare
  183. * @throws ShareNotFound
  184. * @since 9.0.0
  185. */
  186. public function getShareByToken($token);
  187. /**
  188. * Verify the password of a public share
  189. *
  190. * @param IShare $share
  191. * @param string $password
  192. * @return bool
  193. * @since 9.0.0
  194. */
  195. public function checkPassword(IShare $share, $password);
  196. /**
  197. * The user with UID is deleted.
  198. * All share providers have to cleanup the shares with this user as well
  199. * as shares owned by this user.
  200. * Shares only initiated by this user are fine.
  201. *
  202. * @param string $uid
  203. * @since 9.1.0
  204. */
  205. public function userDeleted($uid);
  206. /**
  207. * The group with $gid is deleted
  208. * We need to clear up all shares to this group
  209. *
  210. * @param string $gid
  211. * @since 9.1.0
  212. */
  213. public function groupDeleted($gid);
  214. /**
  215. * The user $uid is deleted from the group $gid
  216. * All user specific group shares have to be removed
  217. *
  218. * @param string $uid
  219. * @param string $gid
  220. * @since 9.1.0
  221. */
  222. public function userDeletedFromGroup($uid, $gid);
  223. /**
  224. * Get access list to a path. This means
  225. * all the users that can access a given path.
  226. *
  227. * Consider:
  228. * -root
  229. * |-folder1 (23)
  230. * |-folder2 (32)
  231. * |-fileA (42)
  232. *
  233. * fileA is shared with user1 and user1@server1
  234. * folder2 is shared with group2 (user4 is a member of group2)
  235. * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2
  236. *
  237. * Then the access list to '/folder1/folder2/fileA' with $currentAccess is:
  238. * [
  239. * users => [
  240. * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'],
  241. * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'],
  242. * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'],
  243. * ],
  244. * remote => [
  245. * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'],
  246. * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'],
  247. * ],
  248. * public => bool
  249. * mail => bool
  250. * ]
  251. *
  252. * The access list to '/folder1/folder2/fileA' **without** $currentAccess is:
  253. * [
  254. * users => ['user1', 'user2', 'user4'],
  255. * remote => bool,
  256. * public => bool
  257. * mail => bool
  258. * ]
  259. *
  260. * This is required for encryption/activity
  261. *
  262. * @param \OCP\Files\Node $path
  263. * @param bool $recursive Should we check all parent folders as well
  264. * @param bool $currentAccess Should the user have currently access to the file
  265. * @return array
  266. * @since 12
  267. */
  268. public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false);
  269. /**
  270. * Instantiates a new share object. This is to be passed to
  271. * createShare.
  272. *
  273. * @return IShare
  274. * @since 9.0.0
  275. */
  276. public function newShare();
  277. /**
  278. * Is the share API enabled
  279. *
  280. * @return bool
  281. * @since 9.0.0
  282. */
  283. public function shareApiEnabled();
  284. /**
  285. * Is public link sharing enabled
  286. *
  287. * @return bool
  288. * @since 9.0.0
  289. */
  290. public function shareApiAllowLinks();
  291. /**
  292. * Is password on public link requires
  293. *
  294. * @return bool
  295. * @since 9.0.0
  296. */
  297. public function shareApiLinkEnforcePassword();
  298. /**
  299. * Is default expire date enabled
  300. *
  301. * @return bool
  302. * @since 9.0.0
  303. */
  304. public function shareApiLinkDefaultExpireDate();
  305. /**
  306. * Is default expire date enforced
  307. *`
  308. * @return bool
  309. * @since 9.0.0
  310. */
  311. public function shareApiLinkDefaultExpireDateEnforced();
  312. /**
  313. * Number of default expire days
  314. *
  315. * @return int
  316. * @since 9.0.0
  317. */
  318. public function shareApiLinkDefaultExpireDays();
  319. /**
  320. * Allow public upload on link shares
  321. *
  322. * @return bool
  323. * @since 9.0.0
  324. */
  325. public function shareApiLinkAllowPublicUpload();
  326. /**
  327. * check if user can only share with group members
  328. * @return bool
  329. * @since 9.0.0
  330. */
  331. public function shareWithGroupMembersOnly();
  332. /**
  333. * Check if users can share with groups
  334. * @return bool
  335. * @since 9.0.1
  336. */
  337. public function allowGroupSharing();
  338. /**
  339. * Check if sharing is disabled for the given user
  340. *
  341. * @param string $userId
  342. * @return bool
  343. * @since 9.0.0
  344. */
  345. public function sharingDisabledForUser($userId);
  346. /**
  347. * Check if outgoing server2server shares are allowed
  348. * @return bool
  349. * @since 9.0.0
  350. */
  351. public function outgoingServer2ServerSharesAllowed();
  352. /**
  353. * Check if outgoing server2server shares are allowed
  354. * @return bool
  355. * @since 14.0.0
  356. */
  357. public function outgoingServer2ServerGroupSharesAllowed();
  358. /**
  359. * Check if a given share provider exists
  360. * @param int $shareType
  361. * @return bool
  362. * @since 11.0.0
  363. */
  364. public function shareProviderExists($shareType);
  365. /**
  366. * @Internal
  367. *
  368. * Get all the shares as iterable to reduce memory overhead
  369. * Note, since this opens up database cursors the iterable should
  370. * be fully itterated.
  371. *
  372. * @return iterable
  373. * @since 18.0.0
  374. */
  375. public function getAllShares(): iterable;
  376. }