@@ -34,172 +34,172 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | interface IShareProvider { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Return the identifier of this provider. |
|
| 39 | - * |
|
| 40 | - * @return string Containing only [a-zA-Z0-9] |
|
| 41 | - * @since 9.0.0 |
|
| 42 | - */ |
|
| 43 | - public function identifier(); |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Create a share |
|
| 47 | - * |
|
| 48 | - * @param \OCP\Share\IShare $share |
|
| 49 | - * @return \OCP\Share\IShare The share object |
|
| 50 | - * @since 9.0.0 |
|
| 51 | - */ |
|
| 52 | - public function create(\OCP\Share\IShare $share); |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Update a share |
|
| 56 | - * |
|
| 57 | - * @param \OCP\Share\IShare $share |
|
| 58 | - * @return \OCP\Share\IShare The share object |
|
| 59 | - * @since 9.0.0 |
|
| 60 | - */ |
|
| 61 | - public function update(\OCP\Share\IShare $share); |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Delete a share |
|
| 65 | - * |
|
| 66 | - * @param \OCP\Share\IShare $share |
|
| 67 | - * @since 9.0.0 |
|
| 68 | - */ |
|
| 69 | - public function delete(\OCP\Share\IShare $share); |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Unshare a file from self as recipient. |
|
| 73 | - * This may require special handling. If a user unshares a group |
|
| 74 | - * share from their self then the original group share should still exist. |
|
| 75 | - * |
|
| 76 | - * @param \OCP\Share\IShare $share |
|
| 77 | - * @param string $recipient UserId of the recipient |
|
| 78 | - * @since 9.0.0 |
|
| 79 | - */ |
|
| 80 | - public function deleteFromSelf(\OCP\Share\IShare $share, $recipient); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Move a share as a recipient. |
|
| 84 | - * This is updating the share target. Thus the mount point of the recipient. |
|
| 85 | - * This may require special handling. If a user moves a group share |
|
| 86 | - * the target should only be changed for them. |
|
| 87 | - * |
|
| 88 | - * @param \OCP\Share\IShare $share |
|
| 89 | - * @param string $recipient userId of recipient |
|
| 90 | - * @return \OCP\Share\IShare |
|
| 91 | - * @since 9.0.0 |
|
| 92 | - */ |
|
| 93 | - public function move(\OCP\Share\IShare $share, $recipient); |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Get all shares by the given user in a folder |
|
| 97 | - * |
|
| 98 | - * @param string $userId |
|
| 99 | - * @param Folder $node |
|
| 100 | - * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator |
|
| 101 | - * @return \OCP\Share\IShare[] |
|
| 102 | - * @since 11.0.0 |
|
| 103 | - */ |
|
| 104 | - public function getSharesInFolder($userId, Folder $node, $reshares); |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Get all shares by the given user |
|
| 108 | - * |
|
| 109 | - * @param string $userId |
|
| 110 | - * @param int $shareType |
|
| 111 | - * @param Node|null $node |
|
| 112 | - * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator |
|
| 113 | - * @param int $limit The maximum number of shares to be returned, -1 for all shares |
|
| 114 | - * @param int $offset |
|
| 115 | - * @return \OCP\Share\IShare[] |
|
| 116 | - * @since 9.0.0 |
|
| 117 | - */ |
|
| 118 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset); |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Get share by id |
|
| 122 | - * |
|
| 123 | - * @param int $id |
|
| 124 | - * @param string|null $recipientId |
|
| 125 | - * @return \OCP\Share\IShare |
|
| 126 | - * @throws ShareNotFound |
|
| 127 | - * @since 9.0.0 |
|
| 128 | - */ |
|
| 129 | - public function getShareById($id, $recipientId = null); |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Get shares for a given path |
|
| 133 | - * |
|
| 134 | - * @param Node $path |
|
| 135 | - * @return \OCP\Share\IShare[] |
|
| 136 | - * @since 9.0.0 |
|
| 137 | - */ |
|
| 138 | - public function getSharesByPath(Node $path); |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Get shared with the given user |
|
| 142 | - * |
|
| 143 | - * @param string $userId get shares where this user is the recipient |
|
| 144 | - * @param int $shareType |
|
| 145 | - * @param Node|null $node |
|
| 146 | - * @param int $limit The max number of entries returned, -1 for all |
|
| 147 | - * @param int $offset |
|
| 148 | - * @return \OCP\Share\IShare[] |
|
| 149 | - * @since 9.0.0 |
|
| 150 | - */ |
|
| 151 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Get a share by token |
|
| 155 | - * |
|
| 156 | - * @param string $token |
|
| 157 | - * @return \OCP\Share\IShare |
|
| 158 | - * @throws ShareNotFound |
|
| 159 | - * @since 9.0.0 |
|
| 160 | - */ |
|
| 161 | - public function getShareByToken($token); |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * A user is deleted from the system |
|
| 165 | - * So clean up the relevant shares. |
|
| 166 | - * |
|
| 167 | - * @param string $uid |
|
| 168 | - * @param int $shareType |
|
| 169 | - * @since 9.1.0 |
|
| 170 | - */ |
|
| 171 | - public function userDeleted($uid, $shareType); |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * A group is deleted from the system. |
|
| 175 | - * We have to clean up all shares to this group. |
|
| 176 | - * Providers not handling group shares should just return |
|
| 177 | - * |
|
| 178 | - * @param string $gid |
|
| 179 | - * @since 9.1.0 |
|
| 180 | - */ |
|
| 181 | - public function groupDeleted($gid); |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * A user is deleted from a group |
|
| 185 | - * We have to clean up all the related user specific group shares |
|
| 186 | - * Providers not handling group shares should just return |
|
| 187 | - * |
|
| 188 | - * @param string $uid |
|
| 189 | - * @param string $gid |
|
| 190 | - * @since 9.1.0 |
|
| 191 | - */ |
|
| 192 | - public function userDeletedFromGroup($uid, $gid); |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Get the access list to the array of provided nodes. |
|
| 196 | - * |
|
| 197 | - * @see IManager::getAccessList() for sample docs |
|
| 198 | - * |
|
| 199 | - * @param Node[] $nodes The list of nodes to get access for |
|
| 200 | - * @param bool $currentAccess If current access is required (like for removed shares that might get revived later) |
|
| 201 | - * @return array |
|
| 202 | - * @since 12 |
|
| 203 | - */ |
|
| 204 | - public function getAccessList($nodes, $currentAccess); |
|
| 37 | + /** |
|
| 38 | + * Return the identifier of this provider. |
|
| 39 | + * |
|
| 40 | + * @return string Containing only [a-zA-Z0-9] |
|
| 41 | + * @since 9.0.0 |
|
| 42 | + */ |
|
| 43 | + public function identifier(); |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Create a share |
|
| 47 | + * |
|
| 48 | + * @param \OCP\Share\IShare $share |
|
| 49 | + * @return \OCP\Share\IShare The share object |
|
| 50 | + * @since 9.0.0 |
|
| 51 | + */ |
|
| 52 | + public function create(\OCP\Share\IShare $share); |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Update a share |
|
| 56 | + * |
|
| 57 | + * @param \OCP\Share\IShare $share |
|
| 58 | + * @return \OCP\Share\IShare The share object |
|
| 59 | + * @since 9.0.0 |
|
| 60 | + */ |
|
| 61 | + public function update(\OCP\Share\IShare $share); |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Delete a share |
|
| 65 | + * |
|
| 66 | + * @param \OCP\Share\IShare $share |
|
| 67 | + * @since 9.0.0 |
|
| 68 | + */ |
|
| 69 | + public function delete(\OCP\Share\IShare $share); |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Unshare a file from self as recipient. |
|
| 73 | + * This may require special handling. If a user unshares a group |
|
| 74 | + * share from their self then the original group share should still exist. |
|
| 75 | + * |
|
| 76 | + * @param \OCP\Share\IShare $share |
|
| 77 | + * @param string $recipient UserId of the recipient |
|
| 78 | + * @since 9.0.0 |
|
| 79 | + */ |
|
| 80 | + public function deleteFromSelf(\OCP\Share\IShare $share, $recipient); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Move a share as a recipient. |
|
| 84 | + * This is updating the share target. Thus the mount point of the recipient. |
|
| 85 | + * This may require special handling. If a user moves a group share |
|
| 86 | + * the target should only be changed for them. |
|
| 87 | + * |
|
| 88 | + * @param \OCP\Share\IShare $share |
|
| 89 | + * @param string $recipient userId of recipient |
|
| 90 | + * @return \OCP\Share\IShare |
|
| 91 | + * @since 9.0.0 |
|
| 92 | + */ |
|
| 93 | + public function move(\OCP\Share\IShare $share, $recipient); |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Get all shares by the given user in a folder |
|
| 97 | + * |
|
| 98 | + * @param string $userId |
|
| 99 | + * @param Folder $node |
|
| 100 | + * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator |
|
| 101 | + * @return \OCP\Share\IShare[] |
|
| 102 | + * @since 11.0.0 |
|
| 103 | + */ |
|
| 104 | + public function getSharesInFolder($userId, Folder $node, $reshares); |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Get all shares by the given user |
|
| 108 | + * |
|
| 109 | + * @param string $userId |
|
| 110 | + * @param int $shareType |
|
| 111 | + * @param Node|null $node |
|
| 112 | + * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator |
|
| 113 | + * @param int $limit The maximum number of shares to be returned, -1 for all shares |
|
| 114 | + * @param int $offset |
|
| 115 | + * @return \OCP\Share\IShare[] |
|
| 116 | + * @since 9.0.0 |
|
| 117 | + */ |
|
| 118 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset); |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Get share by id |
|
| 122 | + * |
|
| 123 | + * @param int $id |
|
| 124 | + * @param string|null $recipientId |
|
| 125 | + * @return \OCP\Share\IShare |
|
| 126 | + * @throws ShareNotFound |
|
| 127 | + * @since 9.0.0 |
|
| 128 | + */ |
|
| 129 | + public function getShareById($id, $recipientId = null); |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Get shares for a given path |
|
| 133 | + * |
|
| 134 | + * @param Node $path |
|
| 135 | + * @return \OCP\Share\IShare[] |
|
| 136 | + * @since 9.0.0 |
|
| 137 | + */ |
|
| 138 | + public function getSharesByPath(Node $path); |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Get shared with the given user |
|
| 142 | + * |
|
| 143 | + * @param string $userId get shares where this user is the recipient |
|
| 144 | + * @param int $shareType |
|
| 145 | + * @param Node|null $node |
|
| 146 | + * @param int $limit The max number of entries returned, -1 for all |
|
| 147 | + * @param int $offset |
|
| 148 | + * @return \OCP\Share\IShare[] |
|
| 149 | + * @since 9.0.0 |
|
| 150 | + */ |
|
| 151 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Get a share by token |
|
| 155 | + * |
|
| 156 | + * @param string $token |
|
| 157 | + * @return \OCP\Share\IShare |
|
| 158 | + * @throws ShareNotFound |
|
| 159 | + * @since 9.0.0 |
|
| 160 | + */ |
|
| 161 | + public function getShareByToken($token); |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * A user is deleted from the system |
|
| 165 | + * So clean up the relevant shares. |
|
| 166 | + * |
|
| 167 | + * @param string $uid |
|
| 168 | + * @param int $shareType |
|
| 169 | + * @since 9.1.0 |
|
| 170 | + */ |
|
| 171 | + public function userDeleted($uid, $shareType); |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * A group is deleted from the system. |
|
| 175 | + * We have to clean up all shares to this group. |
|
| 176 | + * Providers not handling group shares should just return |
|
| 177 | + * |
|
| 178 | + * @param string $gid |
|
| 179 | + * @since 9.1.0 |
|
| 180 | + */ |
|
| 181 | + public function groupDeleted($gid); |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * A user is deleted from a group |
|
| 185 | + * We have to clean up all the related user specific group shares |
|
| 186 | + * Providers not handling group shares should just return |
|
| 187 | + * |
|
| 188 | + * @param string $uid |
|
| 189 | + * @param string $gid |
|
| 190 | + * @since 9.1.0 |
|
| 191 | + */ |
|
| 192 | + public function userDeletedFromGroup($uid, $gid); |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Get the access list to the array of provided nodes. |
|
| 196 | + * |
|
| 197 | + * @see IManager::getAccessList() for sample docs |
|
| 198 | + * |
|
| 199 | + * @param Node[] $nodes The list of nodes to get access for |
|
| 200 | + * @param bool $currentAccess If current access is required (like for removed shares that might get revived later) |
|
| 201 | + * @return array |
|
| 202 | + * @since 12 |
|
| 203 | + */ |
|
| 204 | + public function getAccessList($nodes, $currentAccess); |
|
| 205 | 205 | } |
@@ -31,187 +31,187 @@ |
||
| 31 | 31 | |
| 32 | 32 | class ShareHelper implements IShareHelper { |
| 33 | 33 | |
| 34 | - /** @var IManager */ |
|
| 35 | - private $shareManager; |
|
| 36 | - |
|
| 37 | - public function __construct(IManager $shareManager) { |
|
| 38 | - $this->shareManager = $shareManager; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @param Node $node |
|
| 43 | - * @return array [ users => [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]] |
|
| 44 | - */ |
|
| 45 | - public function getPathsForAccessList(Node $node) { |
|
| 46 | - $result = [ |
|
| 47 | - 'users' => [], |
|
| 48 | - 'remotes' => [], |
|
| 49 | - ]; |
|
| 50 | - |
|
| 51 | - $accessList = $this->shareManager->getAccessList($node, true, true); |
|
| 52 | - if (!empty($accessList['users'])) { |
|
| 53 | - $result['users'] = $this->getPathsForUsers($node, $accessList['users']); |
|
| 54 | - } |
|
| 55 | - if (!empty($accessList['remote'])) { |
|
| 56 | - $result['remotes'] = $this->getPathsForRemotes($node, $accessList['remote']); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - return $result; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Sample: |
|
| 64 | - * $users = [ |
|
| 65 | - * 'test1' => ['node_id' => 16, 'node_path' => '/foo'], |
|
| 66 | - * 'test2' => ['node_id' => 23, 'node_path' => '/bar'], |
|
| 67 | - * 'test3' => ['node_id' => 42, 'node_path' => '/cat'], |
|
| 68 | - * 'test4' => ['node_id' => 48, 'node_path' => '/dog'], |
|
| 69 | - * ]; |
|
| 70 | - * |
|
| 71 | - * Node tree: |
|
| 72 | - * - SixTeen is the parent of TwentyThree |
|
| 73 | - * - TwentyThree is the parent of FortyTwo |
|
| 74 | - * - FortyEight does not exist |
|
| 75 | - * |
|
| 76 | - * $return = [ |
|
| 77 | - * 'test1' => '/foo/TwentyThree/FortyTwo', |
|
| 78 | - * 'test2' => '/bar/FortyTwo', |
|
| 79 | - * 'test3' => '/cat', |
|
| 80 | - * ], |
|
| 81 | - * |
|
| 82 | - * @param Node $node |
|
| 83 | - * @param array[] $users |
|
| 84 | - * @return array |
|
| 85 | - */ |
|
| 86 | - protected function getPathsForUsers(Node $node, array $users) { |
|
| 87 | - /** @var array[] $byId */ |
|
| 88 | - $byId = []; |
|
| 89 | - /** @var array[] $results */ |
|
| 90 | - $results = []; |
|
| 91 | - |
|
| 92 | - foreach ($users as $uid => $info) { |
|
| 93 | - if (!isset($byId[$info['node_id']])) { |
|
| 94 | - $byId[$info['node_id']] = []; |
|
| 95 | - } |
|
| 96 | - $byId[$info['node_id']][$uid] = $info['node_path']; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - try { |
|
| 100 | - if (isset($byId[$node->getId()])) { |
|
| 101 | - foreach ($byId[$node->getId()] as $uid => $path) { |
|
| 102 | - $results[$uid] = $path; |
|
| 103 | - } |
|
| 104 | - unset($byId[$node->getId()]); |
|
| 105 | - } |
|
| 106 | - } catch (NotFoundException $e) { |
|
| 107 | - return $results; |
|
| 108 | - } catch (InvalidPathException $e) { |
|
| 109 | - return $results; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - if (empty($byId)) { |
|
| 113 | - return $results; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $item = $node; |
|
| 117 | - $appendix = '/' . $node->getName(); |
|
| 118 | - while (!empty($byId)) { |
|
| 119 | - try { |
|
| 120 | - /** @var Node $item */ |
|
| 121 | - $item = $item->getParent(); |
|
| 122 | - |
|
| 123 | - if (!empty($byId[$item->getId()])) { |
|
| 124 | - foreach ($byId[$item->getId()] as $uid => $path) { |
|
| 125 | - $results[$uid] = $path . $appendix; |
|
| 126 | - } |
|
| 127 | - unset($byId[$item->getId()]); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $appendix = '/' . $item->getName() . $appendix; |
|
| 131 | - } catch (NotFoundException $e) { |
|
| 132 | - return $results; |
|
| 133 | - } catch (InvalidPathException $e) { |
|
| 134 | - return $results; |
|
| 135 | - } catch (NotPermittedException $e) { |
|
| 136 | - return $results; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - return $results; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Sample: |
|
| 145 | - * $remotes = [ |
|
| 146 | - * 'test1' => ['node_id' => 16, 'token' => 't1'], |
|
| 147 | - * 'test2' => ['node_id' => 23, 'token' => 't2'], |
|
| 148 | - * 'test3' => ['node_id' => 42, 'token' => 't3'], |
|
| 149 | - * 'test4' => ['node_id' => 48, 'token' => 't4'], |
|
| 150 | - * ]; |
|
| 151 | - * |
|
| 152 | - * Node tree: |
|
| 153 | - * - SixTeen is the parent of TwentyThree |
|
| 154 | - * - TwentyThree is the parent of FortyTwo |
|
| 155 | - * - FortyEight does not exist |
|
| 156 | - * |
|
| 157 | - * $return = [ |
|
| 158 | - * 'test1' => ['token' => 't1', 'node_path' => '/SixTeen'], |
|
| 159 | - * 'test2' => ['token' => 't2', 'node_path' => '/SixTeen/TwentyThree'], |
|
| 160 | - * 'test3' => ['token' => 't3', 'node_path' => '/SixTeen/TwentyThree/FortyTwo'], |
|
| 161 | - * ], |
|
| 162 | - * |
|
| 163 | - * @param Node $node |
|
| 164 | - * @param array[] $remotes |
|
| 165 | - * @return array |
|
| 166 | - */ |
|
| 167 | - protected function getPathsForRemotes(Node $node, array $remotes) { |
|
| 168 | - /** @var array[] $byId */ |
|
| 169 | - $byId = []; |
|
| 170 | - /** @var array[] $results */ |
|
| 171 | - $results = []; |
|
| 172 | - |
|
| 173 | - foreach ($remotes as $cloudId => $info) { |
|
| 174 | - if (!isset($byId[$info['node_id']])) { |
|
| 175 | - $byId[$info['node_id']] = []; |
|
| 176 | - } |
|
| 177 | - $byId[$info['node_id']][$cloudId] = $info['token']; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - $item = $node; |
|
| 181 | - while (!empty($byId)) { |
|
| 182 | - try { |
|
| 183 | - if (!empty($byId[$item->getId()])) { |
|
| 184 | - $path = $this->getMountedPath($item); |
|
| 185 | - foreach ($byId[$item->getId()] as $uid => $token) { |
|
| 186 | - $results[$uid] = [ |
|
| 187 | - 'node_path' => $path, |
|
| 188 | - 'token' => $token, |
|
| 189 | - ]; |
|
| 190 | - } |
|
| 191 | - unset($byId[$item->getId()]); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** @var Node $item */ |
|
| 195 | - $item = $item->getParent(); |
|
| 196 | - } catch (NotFoundException $e) { |
|
| 197 | - return $results; |
|
| 198 | - } catch (InvalidPathException $e) { |
|
| 199 | - return $results; |
|
| 200 | - } catch (NotPermittedException $e) { |
|
| 201 | - return $results; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return $results; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param Node $node |
|
| 210 | - * @return string |
|
| 211 | - */ |
|
| 212 | - protected function getMountedPath(Node $node) { |
|
| 213 | - $path = $node->getPath(); |
|
| 214 | - $sections = explode('/', $path, 4); |
|
| 215 | - return '/' . $sections[3]; |
|
| 216 | - } |
|
| 34 | + /** @var IManager */ |
|
| 35 | + private $shareManager; |
|
| 36 | + |
|
| 37 | + public function __construct(IManager $shareManager) { |
|
| 38 | + $this->shareManager = $shareManager; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @param Node $node |
|
| 43 | + * @return array [ users => [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]] |
|
| 44 | + */ |
|
| 45 | + public function getPathsForAccessList(Node $node) { |
|
| 46 | + $result = [ |
|
| 47 | + 'users' => [], |
|
| 48 | + 'remotes' => [], |
|
| 49 | + ]; |
|
| 50 | + |
|
| 51 | + $accessList = $this->shareManager->getAccessList($node, true, true); |
|
| 52 | + if (!empty($accessList['users'])) { |
|
| 53 | + $result['users'] = $this->getPathsForUsers($node, $accessList['users']); |
|
| 54 | + } |
|
| 55 | + if (!empty($accessList['remote'])) { |
|
| 56 | + $result['remotes'] = $this->getPathsForRemotes($node, $accessList['remote']); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + return $result; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Sample: |
|
| 64 | + * $users = [ |
|
| 65 | + * 'test1' => ['node_id' => 16, 'node_path' => '/foo'], |
|
| 66 | + * 'test2' => ['node_id' => 23, 'node_path' => '/bar'], |
|
| 67 | + * 'test3' => ['node_id' => 42, 'node_path' => '/cat'], |
|
| 68 | + * 'test4' => ['node_id' => 48, 'node_path' => '/dog'], |
|
| 69 | + * ]; |
|
| 70 | + * |
|
| 71 | + * Node tree: |
|
| 72 | + * - SixTeen is the parent of TwentyThree |
|
| 73 | + * - TwentyThree is the parent of FortyTwo |
|
| 74 | + * - FortyEight does not exist |
|
| 75 | + * |
|
| 76 | + * $return = [ |
|
| 77 | + * 'test1' => '/foo/TwentyThree/FortyTwo', |
|
| 78 | + * 'test2' => '/bar/FortyTwo', |
|
| 79 | + * 'test3' => '/cat', |
|
| 80 | + * ], |
|
| 81 | + * |
|
| 82 | + * @param Node $node |
|
| 83 | + * @param array[] $users |
|
| 84 | + * @return array |
|
| 85 | + */ |
|
| 86 | + protected function getPathsForUsers(Node $node, array $users) { |
|
| 87 | + /** @var array[] $byId */ |
|
| 88 | + $byId = []; |
|
| 89 | + /** @var array[] $results */ |
|
| 90 | + $results = []; |
|
| 91 | + |
|
| 92 | + foreach ($users as $uid => $info) { |
|
| 93 | + if (!isset($byId[$info['node_id']])) { |
|
| 94 | + $byId[$info['node_id']] = []; |
|
| 95 | + } |
|
| 96 | + $byId[$info['node_id']][$uid] = $info['node_path']; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + try { |
|
| 100 | + if (isset($byId[$node->getId()])) { |
|
| 101 | + foreach ($byId[$node->getId()] as $uid => $path) { |
|
| 102 | + $results[$uid] = $path; |
|
| 103 | + } |
|
| 104 | + unset($byId[$node->getId()]); |
|
| 105 | + } |
|
| 106 | + } catch (NotFoundException $e) { |
|
| 107 | + return $results; |
|
| 108 | + } catch (InvalidPathException $e) { |
|
| 109 | + return $results; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + if (empty($byId)) { |
|
| 113 | + return $results; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $item = $node; |
|
| 117 | + $appendix = '/' . $node->getName(); |
|
| 118 | + while (!empty($byId)) { |
|
| 119 | + try { |
|
| 120 | + /** @var Node $item */ |
|
| 121 | + $item = $item->getParent(); |
|
| 122 | + |
|
| 123 | + if (!empty($byId[$item->getId()])) { |
|
| 124 | + foreach ($byId[$item->getId()] as $uid => $path) { |
|
| 125 | + $results[$uid] = $path . $appendix; |
|
| 126 | + } |
|
| 127 | + unset($byId[$item->getId()]); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $appendix = '/' . $item->getName() . $appendix; |
|
| 131 | + } catch (NotFoundException $e) { |
|
| 132 | + return $results; |
|
| 133 | + } catch (InvalidPathException $e) { |
|
| 134 | + return $results; |
|
| 135 | + } catch (NotPermittedException $e) { |
|
| 136 | + return $results; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + return $results; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Sample: |
|
| 145 | + * $remotes = [ |
|
| 146 | + * 'test1' => ['node_id' => 16, 'token' => 't1'], |
|
| 147 | + * 'test2' => ['node_id' => 23, 'token' => 't2'], |
|
| 148 | + * 'test3' => ['node_id' => 42, 'token' => 't3'], |
|
| 149 | + * 'test4' => ['node_id' => 48, 'token' => 't4'], |
|
| 150 | + * ]; |
|
| 151 | + * |
|
| 152 | + * Node tree: |
|
| 153 | + * - SixTeen is the parent of TwentyThree |
|
| 154 | + * - TwentyThree is the parent of FortyTwo |
|
| 155 | + * - FortyEight does not exist |
|
| 156 | + * |
|
| 157 | + * $return = [ |
|
| 158 | + * 'test1' => ['token' => 't1', 'node_path' => '/SixTeen'], |
|
| 159 | + * 'test2' => ['token' => 't2', 'node_path' => '/SixTeen/TwentyThree'], |
|
| 160 | + * 'test3' => ['token' => 't3', 'node_path' => '/SixTeen/TwentyThree/FortyTwo'], |
|
| 161 | + * ], |
|
| 162 | + * |
|
| 163 | + * @param Node $node |
|
| 164 | + * @param array[] $remotes |
|
| 165 | + * @return array |
|
| 166 | + */ |
|
| 167 | + protected function getPathsForRemotes(Node $node, array $remotes) { |
|
| 168 | + /** @var array[] $byId */ |
|
| 169 | + $byId = []; |
|
| 170 | + /** @var array[] $results */ |
|
| 171 | + $results = []; |
|
| 172 | + |
|
| 173 | + foreach ($remotes as $cloudId => $info) { |
|
| 174 | + if (!isset($byId[$info['node_id']])) { |
|
| 175 | + $byId[$info['node_id']] = []; |
|
| 176 | + } |
|
| 177 | + $byId[$info['node_id']][$cloudId] = $info['token']; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + $item = $node; |
|
| 181 | + while (!empty($byId)) { |
|
| 182 | + try { |
|
| 183 | + if (!empty($byId[$item->getId()])) { |
|
| 184 | + $path = $this->getMountedPath($item); |
|
| 185 | + foreach ($byId[$item->getId()] as $uid => $token) { |
|
| 186 | + $results[$uid] = [ |
|
| 187 | + 'node_path' => $path, |
|
| 188 | + 'token' => $token, |
|
| 189 | + ]; |
|
| 190 | + } |
|
| 191 | + unset($byId[$item->getId()]); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** @var Node $item */ |
|
| 195 | + $item = $item->getParent(); |
|
| 196 | + } catch (NotFoundException $e) { |
|
| 197 | + return $results; |
|
| 198 | + } catch (InvalidPathException $e) { |
|
| 199 | + return $results; |
|
| 200 | + } catch (NotPermittedException $e) { |
|
| 201 | + return $results; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return $results; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param Node $node |
|
| 210 | + * @return string |
|
| 211 | + */ |
|
| 212 | + protected function getMountedPath(Node $node) { |
|
| 213 | + $path = $node->getPath(); |
|
| 214 | + $sections = explode('/', $path, 4); |
|
| 215 | + return '/' . $sections[3]; |
|
| 216 | + } |
|
| 217 | 217 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | $item = $node; |
| 117 | - $appendix = '/' . $node->getName(); |
|
| 117 | + $appendix = '/'.$node->getName(); |
|
| 118 | 118 | while (!empty($byId)) { |
| 119 | 119 | try { |
| 120 | 120 | /** @var Node $item */ |
@@ -122,12 +122,12 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | if (!empty($byId[$item->getId()])) { |
| 124 | 124 | foreach ($byId[$item->getId()] as $uid => $path) { |
| 125 | - $results[$uid] = $path . $appendix; |
|
| 125 | + $results[$uid] = $path.$appendix; |
|
| 126 | 126 | } |
| 127 | 127 | unset($byId[$item->getId()]); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - $appendix = '/' . $item->getName() . $appendix; |
|
| 130 | + $appendix = '/'.$item->getName().$appendix; |
|
| 131 | 131 | } catch (NotFoundException $e) { |
| 132 | 132 | return $results; |
| 133 | 133 | } catch (InvalidPathException $e) { |
@@ -212,6 +212,6 @@ discard block |
||
| 212 | 212 | protected function getMountedPath(Node $node) { |
| 213 | 213 | $path = $node->getPath(); |
| 214 | 214 | $sections = explode('/', $path, 4); |
| 215 | - return '/' . $sections[3]; |
|
| 215 | + return '/'.$sections[3]; |
|
| 216 | 216 | } |
| 217 | 217 | } |
@@ -27,35 +27,35 @@ |
||
| 27 | 27 | |
| 28 | 28 | class SettingsManager { |
| 29 | 29 | |
| 30 | - /** @var IConfig */ |
|
| 31 | - private $config; |
|
| 32 | - |
|
| 33 | - private $sendPasswordByMailDefault = 'yes'; |
|
| 34 | - |
|
| 35 | - private $enforcePasswordProtectionDefault = 'no'; |
|
| 36 | - |
|
| 37 | - public function __construct(IConfig $config) { |
|
| 38 | - $this->config = $config; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * should the password for a mail share be send to the recipient |
|
| 43 | - * |
|
| 44 | - * @return bool |
|
| 45 | - */ |
|
| 46 | - public function sendPasswordByMail() { |
|
| 47 | - $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault); |
|
| 48 | - return $sendPasswordByMail === 'yes'; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * do we require a share by mail to be password protected |
|
| 53 | - * |
|
| 54 | - * @return bool |
|
| 55 | - */ |
|
| 56 | - public function enforcePasswordProtection() { |
|
| 57 | - $enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault); |
|
| 58 | - return $enforcePassword === 'yes'; |
|
| 59 | - } |
|
| 30 | + /** @var IConfig */ |
|
| 31 | + private $config; |
|
| 32 | + |
|
| 33 | + private $sendPasswordByMailDefault = 'yes'; |
|
| 34 | + |
|
| 35 | + private $enforcePasswordProtectionDefault = 'no'; |
|
| 36 | + |
|
| 37 | + public function __construct(IConfig $config) { |
|
| 38 | + $this->config = $config; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * should the password for a mail share be send to the recipient |
|
| 43 | + * |
|
| 44 | + * @return bool |
|
| 45 | + */ |
|
| 46 | + public function sendPasswordByMail() { |
|
| 47 | + $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault); |
|
| 48 | + return $sendPasswordByMail === 'yes'; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * do we require a share by mail to be password protected |
|
| 53 | + * |
|
| 54 | + * @return bool |
|
| 55 | + */ |
|
| 56 | + public function enforcePasswordProtection() { |
|
| 57 | + $enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault); |
|
| 58 | + return $enforcePassword === 'yes'; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | 61 | } |
@@ -27,42 +27,42 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Admin implements ISettings { |
| 29 | 29 | |
| 30 | - /** @var SettingsManager */ |
|
| 31 | - private $settingsManager; |
|
| 30 | + /** @var SettingsManager */ |
|
| 31 | + private $settingsManager; |
|
| 32 | 32 | |
| 33 | - public function __construct(SettingsManager $settingsManager) { |
|
| 34 | - $this->settingsManager = $settingsManager; |
|
| 35 | - } |
|
| 33 | + public function __construct(SettingsManager $settingsManager) { |
|
| 34 | + $this->settingsManager = $settingsManager; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return TemplateResponse |
|
| 39 | - */ |
|
| 40 | - public function getForm() { |
|
| 37 | + /** |
|
| 38 | + * @return TemplateResponse |
|
| 39 | + */ |
|
| 40 | + public function getForm() { |
|
| 41 | 41 | |
| 42 | - $parameters = [ |
|
| 43 | - 'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(), |
|
| 44 | - 'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection() |
|
| 45 | - ]; |
|
| 42 | + $parameters = [ |
|
| 43 | + 'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(), |
|
| 44 | + 'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection() |
|
| 45 | + ]; |
|
| 46 | 46 | |
| 47 | - return new TemplateResponse('sharebymail', 'settings-admin', $parameters, ''); |
|
| 48 | - } |
|
| 47 | + return new TemplateResponse('sharebymail', 'settings-admin', $parameters, ''); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @return string the section ID, e.g. 'sharing' |
|
| 52 | - */ |
|
| 53 | - public function getSection() { |
|
| 54 | - return 'sharing'; |
|
| 55 | - } |
|
| 50 | + /** |
|
| 51 | + * @return string the section ID, e.g. 'sharing' |
|
| 52 | + */ |
|
| 53 | + public function getSection() { |
|
| 54 | + return 'sharing'; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @return int whether the form should be rather on the top or bottom of |
|
| 59 | - * the admin section. The forms are arranged in ascending order of the |
|
| 60 | - * priority values. It is required to return a value between 0 and 100. |
|
| 61 | - * |
|
| 62 | - * E.g.: 70 |
|
| 63 | - */ |
|
| 64 | - public function getPriority() { |
|
| 65 | - return 40; |
|
| 66 | - } |
|
| 57 | + /** |
|
| 58 | + * @return int whether the form should be rather on the top or bottom of |
|
| 59 | + * the admin section. The forms are arranged in ascending order of the |
|
| 60 | + * priority values. It is required to return a value between 0 and 100. |
|
| 61 | + * |
|
| 62 | + * E.g.: 70 |
|
| 63 | + */ |
|
| 64 | + public function getPriority() { |
|
| 65 | + return 40; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | } |
@@ -27,27 +27,27 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Settings { |
| 29 | 29 | |
| 30 | - /** @var SettingsManager */ |
|
| 31 | - private $settingsManager; |
|
| 32 | - |
|
| 33 | - public function __construct(SettingsManager $settingsManager) { |
|
| 34 | - $this->settingsManager = $settingsManager; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * announce that the share-by-mail share provider is enabled |
|
| 39 | - * |
|
| 40 | - * @param array $settings |
|
| 41 | - */ |
|
| 42 | - public function announceShareProvider(array $settings) { |
|
| 43 | - $array = json_decode($settings['array']['oc_appconfig'], true); |
|
| 44 | - $array['shareByMailEnabled'] = true; |
|
| 45 | - $settings['array']['oc_appconfig'] = json_encode($array); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - public function announceShareByMailSettings(array $settings) { |
|
| 49 | - $array = json_decode($settings['array']['oc_appconfig'], true); |
|
| 50 | - $array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection(); |
|
| 51 | - $settings['array']['oc_appconfig'] = json_encode($array); |
|
| 52 | - } |
|
| 30 | + /** @var SettingsManager */ |
|
| 31 | + private $settingsManager; |
|
| 32 | + |
|
| 33 | + public function __construct(SettingsManager $settingsManager) { |
|
| 34 | + $this->settingsManager = $settingsManager; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * announce that the share-by-mail share provider is enabled |
|
| 39 | + * |
|
| 40 | + * @param array $settings |
|
| 41 | + */ |
|
| 42 | + public function announceShareProvider(array $settings) { |
|
| 43 | + $array = json_decode($settings['array']['oc_appconfig'], true); |
|
| 44 | + $array['shareByMailEnabled'] = true; |
|
| 45 | + $settings['array']['oc_appconfig'] = json_encode($array); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + public function announceShareByMailSettings(array $settings) { |
|
| 49 | + $array = json_decode($settings['array']['oc_appconfig'], true); |
|
| 50 | + $array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection(); |
|
| 51 | + $settings['array']['oc_appconfig'] = json_encode($array); |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -28,13 +28,13 @@ |
||
| 28 | 28 | * @brief wraps around static Nextcloud core methods |
| 29 | 29 | */ |
| 30 | 30 | class LogWrapper { |
| 31 | - protected $app = 'user_ldap'; |
|
| 31 | + protected $app = 'user_ldap'; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @brief states whether the filesystem was loaded |
|
| 35 | - * @return bool |
|
| 36 | - */ |
|
| 37 | - public function log($msg, $level) { |
|
| 38 | - \OCP\Util::writeLog($this->app, $msg, $level); |
|
| 39 | - } |
|
| 33 | + /** |
|
| 34 | + * @brief states whether the filesystem was loaded |
|
| 35 | + * @return bool |
|
| 36 | + */ |
|
| 37 | + public function log($msg, $level) { |
|
| 38 | + \OCP\Util::writeLog($this->app, $msg, $level); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * @brief states whether the filesystem was loaded |
| 35 | - * @return bool |
|
| 35 | + * @return boolean|null |
|
| 36 | 36 | */ |
| 37 | 37 | public function log($msg, $level) { |
| 38 | 38 | \OCP\Util::writeLog($this->app, $msg, $level); |
@@ -29,19 +29,19 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class FilesystemHelper { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @brief states whether the filesystem was loaded |
|
| 34 | - * @return bool |
|
| 35 | - */ |
|
| 36 | - public function isLoaded() { |
|
| 37 | - return \OC\Files\Filesystem::$loaded; |
|
| 38 | - } |
|
| 32 | + /** |
|
| 33 | + * @brief states whether the filesystem was loaded |
|
| 34 | + * @return bool |
|
| 35 | + */ |
|
| 36 | + public function isLoaded() { |
|
| 37 | + return \OC\Files\Filesystem::$loaded; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @brief initializes the filesystem for the given user |
|
| 42 | - * @param string $uid the Nextcloud username of the user |
|
| 43 | - */ |
|
| 44 | - public function setup($uid) { |
|
| 45 | - \OC_Util::setupFS($uid); |
|
| 46 | - } |
|
| 40 | + /** |
|
| 41 | + * @brief initializes the filesystem for the given user |
|
| 42 | + * @param string $uid the Nextcloud username of the user |
|
| 43 | + */ |
|
| 44 | + public function setup($uid) { |
|
| 45 | + \OC_Util::setupFS($uid); |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -34,91 +34,91 @@ |
||
| 34 | 34 | |
| 35 | 35 | class SettingsController extends Controller { |
| 36 | 36 | |
| 37 | - /** @var IL10N */ |
|
| 38 | - private $l; |
|
| 39 | - |
|
| 40 | - /** @var TrustedServers */ |
|
| 41 | - private $trustedServers; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @param string $AppName |
|
| 45 | - * @param IRequest $request |
|
| 46 | - * @param IL10N $l10n |
|
| 47 | - * @param TrustedServers $trustedServers |
|
| 48 | - */ |
|
| 49 | - public function __construct($AppName, |
|
| 50 | - IRequest $request, |
|
| 51 | - IL10N $l10n, |
|
| 52 | - TrustedServers $trustedServers |
|
| 53 | - ) { |
|
| 54 | - parent::__construct($AppName, $request); |
|
| 55 | - $this->l = $l10n; |
|
| 56 | - $this->trustedServers = $trustedServers; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * add server to the list of trusted Nextclouds |
|
| 62 | - * |
|
| 63 | - * @param string $url |
|
| 64 | - * @return DataResponse |
|
| 65 | - * @throws HintException |
|
| 66 | - */ |
|
| 67 | - public function addServer($url) { |
|
| 68 | - $this->checkServer($url); |
|
| 69 | - $id = $this->trustedServers->addServer($url); |
|
| 70 | - |
|
| 71 | - return new DataResponse( |
|
| 72 | - [ |
|
| 73 | - 'url' => $url, |
|
| 74 | - 'id' => $id, |
|
| 75 | - 'message' => (string) $this->l->t('Added to the list of trusted servers') |
|
| 76 | - ] |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * add server to the list of trusted Nextclouds |
|
| 82 | - * |
|
| 83 | - * @param int $id |
|
| 84 | - * @return DataResponse |
|
| 85 | - */ |
|
| 86 | - public function removeServer($id) { |
|
| 87 | - $this->trustedServers->removeServer($id); |
|
| 88 | - return new DataResponse(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * enable/disable to automatically add servers to the list of trusted servers |
|
| 93 | - * once a federated share was created and accepted successfully |
|
| 94 | - * |
|
| 95 | - * @param bool $autoAddServers |
|
| 96 | - */ |
|
| 97 | - public function autoAddServers($autoAddServers) { |
|
| 98 | - $this->trustedServers->setAutoAddServers($autoAddServers); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * check if the server should be added to the list of trusted servers or not |
|
| 103 | - * |
|
| 104 | - * @param string $url |
|
| 105 | - * @return bool |
|
| 106 | - * @throws HintException |
|
| 107 | - */ |
|
| 108 | - protected function checkServer($url) { |
|
| 109 | - if ($this->trustedServers->isTrustedServer($url) === true) { |
|
| 110 | - $message = 'Server is already in the list of trusted servers.'; |
|
| 111 | - $hint = $this->l->t('Server is already in the list of trusted servers.'); |
|
| 112 | - throw new HintException($message, $hint); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ($this->trustedServers->isOwnCloudServer($url) === false) { |
|
| 116 | - $message = 'No server to federate with found'; |
|
| 117 | - $hint = $this->l->t('No server to federate with found'); |
|
| 118 | - throw new HintException($message, $hint); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return true; |
|
| 122 | - } |
|
| 37 | + /** @var IL10N */ |
|
| 38 | + private $l; |
|
| 39 | + |
|
| 40 | + /** @var TrustedServers */ |
|
| 41 | + private $trustedServers; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @param string $AppName |
|
| 45 | + * @param IRequest $request |
|
| 46 | + * @param IL10N $l10n |
|
| 47 | + * @param TrustedServers $trustedServers |
|
| 48 | + */ |
|
| 49 | + public function __construct($AppName, |
|
| 50 | + IRequest $request, |
|
| 51 | + IL10N $l10n, |
|
| 52 | + TrustedServers $trustedServers |
|
| 53 | + ) { |
|
| 54 | + parent::__construct($AppName, $request); |
|
| 55 | + $this->l = $l10n; |
|
| 56 | + $this->trustedServers = $trustedServers; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * add server to the list of trusted Nextclouds |
|
| 62 | + * |
|
| 63 | + * @param string $url |
|
| 64 | + * @return DataResponse |
|
| 65 | + * @throws HintException |
|
| 66 | + */ |
|
| 67 | + public function addServer($url) { |
|
| 68 | + $this->checkServer($url); |
|
| 69 | + $id = $this->trustedServers->addServer($url); |
|
| 70 | + |
|
| 71 | + return new DataResponse( |
|
| 72 | + [ |
|
| 73 | + 'url' => $url, |
|
| 74 | + 'id' => $id, |
|
| 75 | + 'message' => (string) $this->l->t('Added to the list of trusted servers') |
|
| 76 | + ] |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * add server to the list of trusted Nextclouds |
|
| 82 | + * |
|
| 83 | + * @param int $id |
|
| 84 | + * @return DataResponse |
|
| 85 | + */ |
|
| 86 | + public function removeServer($id) { |
|
| 87 | + $this->trustedServers->removeServer($id); |
|
| 88 | + return new DataResponse(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * enable/disable to automatically add servers to the list of trusted servers |
|
| 93 | + * once a federated share was created and accepted successfully |
|
| 94 | + * |
|
| 95 | + * @param bool $autoAddServers |
|
| 96 | + */ |
|
| 97 | + public function autoAddServers($autoAddServers) { |
|
| 98 | + $this->trustedServers->setAutoAddServers($autoAddServers); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * check if the server should be added to the list of trusted servers or not |
|
| 103 | + * |
|
| 104 | + * @param string $url |
|
| 105 | + * @return bool |
|
| 106 | + * @throws HintException |
|
| 107 | + */ |
|
| 108 | + protected function checkServer($url) { |
|
| 109 | + if ($this->trustedServers->isTrustedServer($url) === true) { |
|
| 110 | + $message = 'Server is already in the list of trusted servers.'; |
|
| 111 | + $hint = $this->l->t('Server is already in the list of trusted servers.'); |
|
| 112 | + throw new HintException($message, $hint); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ($this->trustedServers->isOwnCloudServer($url) === false) { |
|
| 116 | + $message = 'No server to federate with found'; |
|
| 117 | + $hint = $this->l->t('No server to federate with found'); |
|
| 118 | + throw new HintException($message, $hint); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return true; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | 124 | } |
@@ -42,97 +42,97 @@ |
||
| 42 | 42 | * Migrate mount config from mount.json to the database |
| 43 | 43 | */ |
| 44 | 44 | class StorageMigrator { |
| 45 | - /** |
|
| 46 | - * @var BackendService |
|
| 47 | - */ |
|
| 48 | - private $backendService; |
|
| 45 | + /** |
|
| 46 | + * @var BackendService |
|
| 47 | + */ |
|
| 48 | + private $backendService; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var DBConfigService |
|
| 52 | - */ |
|
| 53 | - private $dbConfig; |
|
| 50 | + /** |
|
| 51 | + * @var DBConfigService |
|
| 52 | + */ |
|
| 53 | + private $dbConfig; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var IConfig |
|
| 57 | - */ |
|
| 58 | - private $config; |
|
| 55 | + /** |
|
| 56 | + * @var IConfig |
|
| 57 | + */ |
|
| 58 | + private $config; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @var IDBConnection |
|
| 62 | - */ |
|
| 63 | - private $connection; |
|
| 60 | + /** |
|
| 61 | + * @var IDBConnection |
|
| 62 | + */ |
|
| 63 | + private $connection; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @var ILogger |
|
| 67 | - */ |
|
| 68 | - private $logger; |
|
| 65 | + /** |
|
| 66 | + * @var ILogger |
|
| 67 | + */ |
|
| 68 | + private $logger; |
|
| 69 | 69 | |
| 70 | - /** @var IUserMountCache */ |
|
| 71 | - private $userMountCache; |
|
| 70 | + /** @var IUserMountCache */ |
|
| 71 | + private $userMountCache; |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * StorageMigrator constructor. |
|
| 75 | - * |
|
| 76 | - * @param BackendService $backendService |
|
| 77 | - * @param DBConfigService $dbConfig |
|
| 78 | - * @param IConfig $config |
|
| 79 | - * @param IDBConnection $connection |
|
| 80 | - * @param ILogger $logger |
|
| 81 | - * @param IUserMountCache $userMountCache |
|
| 82 | - */ |
|
| 83 | - public function __construct( |
|
| 84 | - BackendService $backendService, |
|
| 85 | - DBConfigService $dbConfig, |
|
| 86 | - IConfig $config, |
|
| 87 | - IDBConnection $connection, |
|
| 88 | - ILogger $logger, |
|
| 89 | - IUserMountCache $userMountCache |
|
| 90 | - ) { |
|
| 91 | - $this->backendService = $backendService; |
|
| 92 | - $this->dbConfig = $dbConfig; |
|
| 93 | - $this->config = $config; |
|
| 94 | - $this->connection = $connection; |
|
| 95 | - $this->logger = $logger; |
|
| 96 | - $this->userMountCache = $userMountCache; |
|
| 97 | - } |
|
| 73 | + /** |
|
| 74 | + * StorageMigrator constructor. |
|
| 75 | + * |
|
| 76 | + * @param BackendService $backendService |
|
| 77 | + * @param DBConfigService $dbConfig |
|
| 78 | + * @param IConfig $config |
|
| 79 | + * @param IDBConnection $connection |
|
| 80 | + * @param ILogger $logger |
|
| 81 | + * @param IUserMountCache $userMountCache |
|
| 82 | + */ |
|
| 83 | + public function __construct( |
|
| 84 | + BackendService $backendService, |
|
| 85 | + DBConfigService $dbConfig, |
|
| 86 | + IConfig $config, |
|
| 87 | + IDBConnection $connection, |
|
| 88 | + ILogger $logger, |
|
| 89 | + IUserMountCache $userMountCache |
|
| 90 | + ) { |
|
| 91 | + $this->backendService = $backendService; |
|
| 92 | + $this->dbConfig = $dbConfig; |
|
| 93 | + $this->config = $config; |
|
| 94 | + $this->connection = $connection; |
|
| 95 | + $this->logger = $logger; |
|
| 96 | + $this->userMountCache = $userMountCache; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService) { |
|
| 100 | - $existingStorage = $legacyService->getAllStorages(); |
|
| 99 | + private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService) { |
|
| 100 | + $existingStorage = $legacyService->getAllStorages(); |
|
| 101 | 101 | |
| 102 | - $this->connection->beginTransaction(); |
|
| 103 | - try { |
|
| 104 | - foreach ($existingStorage as $storage) { |
|
| 105 | - $mountOptions = $storage->getMountOptions(); |
|
| 106 | - if (!empty($mountOptions) && !isset($mountOptions['enable_sharing'])) { |
|
| 107 | - // existing mounts must have sharing enabled by default to avoid surprises |
|
| 108 | - $mountOptions['enable_sharing'] = true; |
|
| 109 | - $storage->setMountOptions($mountOptions); |
|
| 110 | - } |
|
| 111 | - $storageService->addStorage($storage); |
|
| 112 | - } |
|
| 113 | - $this->connection->commit(); |
|
| 114 | - } catch (\Exception $e) { |
|
| 115 | - $this->logger->logException($e); |
|
| 116 | - $this->connection->rollBack(); |
|
| 117 | - } |
|
| 118 | - } |
|
| 102 | + $this->connection->beginTransaction(); |
|
| 103 | + try { |
|
| 104 | + foreach ($existingStorage as $storage) { |
|
| 105 | + $mountOptions = $storage->getMountOptions(); |
|
| 106 | + if (!empty($mountOptions) && !isset($mountOptions['enable_sharing'])) { |
|
| 107 | + // existing mounts must have sharing enabled by default to avoid surprises |
|
| 108 | + $mountOptions['enable_sharing'] = true; |
|
| 109 | + $storage->setMountOptions($mountOptions); |
|
| 110 | + } |
|
| 111 | + $storageService->addStorage($storage); |
|
| 112 | + } |
|
| 113 | + $this->connection->commit(); |
|
| 114 | + } catch (\Exception $e) { |
|
| 115 | + $this->logger->logException($e); |
|
| 116 | + $this->connection->rollBack(); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Migrate personal storages configured by the current user |
|
| 122 | - * |
|
| 123 | - * @param IUser $user |
|
| 124 | - */ |
|
| 125 | - public function migrateUser(IUser $user) { |
|
| 126 | - $dummySession = new DummyUserSession(); |
|
| 127 | - $dummySession->setUser($user); |
|
| 128 | - $userId = $user->getUID(); |
|
| 129 | - $userVersion = $this->config->getUserValue($userId, 'files_external', 'config_version', '0.0.0'); |
|
| 130 | - if (version_compare($userVersion, '0.5.0', '<')) { |
|
| 131 | - $this->config->setUserValue($userId, 'files_external', 'config_version', '0.5.0'); |
|
| 132 | - $legacyService = new UserLegacyStoragesService($this->backendService, $dummySession); |
|
| 133 | - $storageService = new UserStoragesService($this->backendService, $this->dbConfig, $dummySession, $this->userMountCache); |
|
| 120 | + /** |
|
| 121 | + * Migrate personal storages configured by the current user |
|
| 122 | + * |
|
| 123 | + * @param IUser $user |
|
| 124 | + */ |
|
| 125 | + public function migrateUser(IUser $user) { |
|
| 126 | + $dummySession = new DummyUserSession(); |
|
| 127 | + $dummySession->setUser($user); |
|
| 128 | + $userId = $user->getUID(); |
|
| 129 | + $userVersion = $this->config->getUserValue($userId, 'files_external', 'config_version', '0.0.0'); |
|
| 130 | + if (version_compare($userVersion, '0.5.0', '<')) { |
|
| 131 | + $this->config->setUserValue($userId, 'files_external', 'config_version', '0.5.0'); |
|
| 132 | + $legacyService = new UserLegacyStoragesService($this->backendService, $dummySession); |
|
| 133 | + $storageService = new UserStoragesService($this->backendService, $this->dbConfig, $dummySession, $this->userMountCache); |
|
| 134 | 134 | |
| 135 | - $this->migrate($legacyService, $storageService); |
|
| 136 | - } |
|
| 137 | - } |
|
| 135 | + $this->migrate($legacyService, $storageService); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | 138 | } |
@@ -26,7 +26,6 @@ |
||
| 26 | 26 | |
| 27 | 27 | use OCA\Files_External\Service\BackendService; |
| 28 | 28 | use OCA\Files_External\Service\DBConfigService; |
| 29 | -use OCA\Files_External\Service\GlobalLegacyStoragesService; |
|
| 30 | 29 | use OCA\Files_External\Service\LegacyStoragesService; |
| 31 | 30 | use OCA\Files_External\Service\StoragesService; |
| 32 | 31 | use OCA\Files_External\Service\UserLegacyStoragesService; |