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.

212 lines
4.5 KiB

  1. <?php
  2. /**
  3. * @author Roeland Jago Douma <rullzer@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OC\Share20;
  22. use OCP\IAppConfig;
  23. use OCP\IUserManager;
  24. use OCP\IGroupManager;
  25. use OCP\IUser;
  26. use OCP\ILogger;
  27. use OCP\Files\Folder;
  28. use OC\Share20\Exception\ShareNotFound;
  29. /**
  30. * This class is the communication hub for all sharing related operations.
  31. */
  32. class Manager {
  33. /**
  34. * @var IShareProvider[]
  35. */
  36. private $defaultProvider;
  37. /** @var IUser */
  38. private $currentUser;
  39. /** @var IUserManager */
  40. private $userManager;
  41. /** @var IGroupManager */
  42. private $groupManager;
  43. /** @var ILogger */
  44. private $logger;
  45. /** @var IAppConfig */
  46. private $appConfig;
  47. /** @var IFolder */
  48. private $userFolder;
  49. public function __construct(IUser $user,
  50. IUserManager $userManager,
  51. IGroupManager $groupManager,
  52. ILogger $logger,
  53. IAppConfig $appConfig,
  54. Folder $userFolder,
  55. IShareProvider $defaultProvider) {
  56. $this->currentUser = $user;
  57. $this->userManager = $userManager;
  58. $this->groupManager = $groupManager;
  59. $this->logger = $logger;
  60. $this->appConfig = $appConfig;
  61. $this->userFolder = $userFolder;
  62. // TEMP SOLUTION JUST TO GET STARTED
  63. $this->defaultProvider = $defaultProvider;
  64. }
  65. /**
  66. * Share a path
  67. *
  68. * @param Share $share
  69. * @return Share The share object
  70. */
  71. public function createShare(Share $share) {
  72. throw new \Exception();
  73. }
  74. /**
  75. * Update a share
  76. *
  77. * @param Share $share
  78. * @return Share The share object
  79. */
  80. public function updateShare(Share $share) {
  81. throw new \Exception();
  82. }
  83. /**
  84. * Delete a share
  85. *
  86. * @param Share $share
  87. * @throws ShareNotFound
  88. * @throws \OC\Share20\Exception\BackendError
  89. */
  90. public function deleteShare(IShare $share) {
  91. if ($share->getId() === null) {
  92. throw new ShareNotFound();
  93. }
  94. $this->defaultProvider->delete($share);
  95. }
  96. /**
  97. * Retrieve all shares by the current user
  98. *
  99. * @param int $page
  100. * @param int $perPage
  101. * @return Share[]
  102. */
  103. public function getShares($page=0, $perPage=50) {
  104. throw new \Exception();
  105. }
  106. /**
  107. * Retrieve a share by the share id
  108. *
  109. * @param string $id
  110. * @return Share
  111. *
  112. * @throws ShareNotFound
  113. */
  114. public function getShareById($id) {
  115. $share = $this->defaultProvider->getShareById($id);
  116. if ($share->getSharedWith() !== $this->currentUser &&
  117. $share->getSharedBy() !== $this->currentUser &&
  118. $share->getShareOwner() !== $this->currentUser) {
  119. throw new ShareNotFound();
  120. }
  121. return $share;
  122. }
  123. /**
  124. * Get all the shares for a given path
  125. *
  126. * @param \OCP\Files\Node $path
  127. * @param int $page
  128. * @param int $perPage
  129. *
  130. * @return Share[]
  131. */
  132. public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) {
  133. throw new \Exception();
  134. }
  135. /**
  136. * Get all shares that are shared with the current user
  137. *
  138. * @param int $shareType
  139. * @param int $page
  140. * @param int $perPage
  141. *
  142. * @return Share[]
  143. */
  144. public function getSharedWithMe($shareType = null, $page=0, $perPage=50) {
  145. throw new \Exception();
  146. }
  147. /**
  148. * Get the share by token possible with password
  149. *
  150. * @param string $token
  151. * @param string $password
  152. *
  153. * @return Share
  154. *
  155. * @throws ShareNotFoundException
  156. */
  157. public function getShareByToken($token, $password=null) {
  158. throw new \Exception();
  159. }
  160. /**
  161. * Get access list to a path. This means
  162. * all the users and groups that can access a given path.
  163. *
  164. * Consider:
  165. * -root
  166. * |-folder1
  167. * |-folder2
  168. * |-fileA
  169. *
  170. * fileA is shared with user1
  171. * folder2 is shared with group2
  172. * folder1 is shared with user2
  173. *
  174. * Then the access list will to '/folder1/folder2/fileA' is:
  175. * [
  176. * 'users' => ['user1', 'user2'],
  177. * 'groups' => ['group2']
  178. * ]
  179. *
  180. * This is required for encryption
  181. *
  182. * @param \OCP\Files\Node $path
  183. */
  184. public function getAccessList(\OCP\Files\Node $path) {
  185. throw new \Exception();
  186. }
  187. }