You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

430 lines
10 KiB

3 years ago
  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 Julius Härtl <jus@bitgrid.net>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Robin Appelman <robin@icewind.nl>
  13. * @author Roeland Jago Douma <roeland@famdouma.nl>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. namespace OCP\Share;
  31. use OCP\Files\Folder;
  32. use OCP\Files\Node;
  33. use OCP\Share\Exceptions\GenericShareException;
  34. use OCP\Share\Exceptions\ShareNotFound;
  35. /**
  36. * Interface IManager
  37. *
  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 user enumeration is allowed
  340. *
  341. * @return bool
  342. * @since 19.0.0
  343. */
  344. public function allowEnumeration(): bool;
  345. /**
  346. * Check if user enumeration is limited to the users groups
  347. *
  348. * @return bool
  349. * @since 19.0.0
  350. */
  351. public function limitEnumerationToGroups(): bool;
  352. /**
  353. * Check if sharing is disabled for the given user
  354. *
  355. * @param string $userId
  356. * @return bool
  357. * @since 9.0.0
  358. */
  359. public function sharingDisabledForUser($userId);
  360. /**
  361. * Check if outgoing server2server shares are allowed
  362. * @return bool
  363. * @since 9.0.0
  364. */
  365. public function outgoingServer2ServerSharesAllowed();
  366. /**
  367. * Check if outgoing server2server shares are allowed
  368. * @return bool
  369. * @since 14.0.0
  370. */
  371. public function outgoingServer2ServerGroupSharesAllowed();
  372. /**
  373. * Check if a given share provider exists
  374. * @param int $shareType
  375. * @return bool
  376. * @since 11.0.0
  377. */
  378. public function shareProviderExists($shareType);
  379. /**
  380. * @Internal
  381. *
  382. * Get all the shares as iterable to reduce memory overhead
  383. * Note, since this opens up database cursors the iterable should
  384. * be fully itterated.
  385. *
  386. * @return iterable
  387. * @since 18.0.0
  388. */
  389. public function getAllShares(): iterable;
  390. }