@@ -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 | }  | 
                                                        
@@ -121,7 +121,7 @@  | 
                                                    ||
| 121 | 121 | * share received from another server  | 
                                                        
| 122 | 122 | *  | 
                                                        
| 123 | 123 | * @param ICloudFederationShare $share  | 
                                                        
| 124 | - * @return string provider specific unique ID of the share  | 
                                                        |
| 124 | + * @return integer provider specific unique ID of the share  | 
                                                        |
| 125 | 125 | *  | 
                                                        
| 126 | 126 | * @throws ProviderCouldNotAddShareException  | 
                                                        
| 127 | 127 | * @throws \OCP\AppFramework\QueryException  | 
                                                        
@@ -50,713 +50,713 @@  | 
                                                    ||
| 50 | 50 | |
| 51 | 51 |  class CloudFederationProviderFiles implements ICloudFederationProvider { | 
                                                        
| 52 | 52 | |
| 53 | - /** @var IAppManager */  | 
                                                        |
| 54 | - private $appManager;  | 
                                                        |
| 55 | -  | 
                                                        |
| 56 | - /** @var FederatedShareProvider */  | 
                                                        |
| 57 | - private $federatedShareProvider;  | 
                                                        |
| 58 | -  | 
                                                        |
| 59 | - /** @var AddressHandler */  | 
                                                        |
| 60 | - private $addressHandler;  | 
                                                        |
| 61 | -  | 
                                                        |
| 62 | - /** @var ILogger */  | 
                                                        |
| 63 | - private $logger;  | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | - /** @var IUserManager */  | 
                                                        |
| 66 | - private $userManager;  | 
                                                        |
| 67 | -  | 
                                                        |
| 68 | - /** @var ICloudIdManager */  | 
                                                        |
| 69 | - private $cloudIdManager;  | 
                                                        |
| 70 | -  | 
                                                        |
| 71 | - /** @var IActivityManager */  | 
                                                        |
| 72 | - private $activityManager;  | 
                                                        |
| 73 | -  | 
                                                        |
| 74 | - /** @var INotificationManager */  | 
                                                        |
| 75 | - private $notificationManager;  | 
                                                        |
| 76 | -  | 
                                                        |
| 77 | - /** @var IURLGenerator */  | 
                                                        |
| 78 | - private $urlGenerator;  | 
                                                        |
| 79 | -  | 
                                                        |
| 80 | - /** @var ICloudFederationFactory */  | 
                                                        |
| 81 | - private $cloudFederationFactory;  | 
                                                        |
| 82 | -  | 
                                                        |
| 83 | - /** @var ICloudFederationProviderManager */  | 
                                                        |
| 84 | - private $cloudFederationProviderManager;  | 
                                                        |
| 85 | -  | 
                                                        |
| 86 | - /** @var IDBConnection */  | 
                                                        |
| 87 | - private $connection;  | 
                                                        |
| 88 | -  | 
                                                        |
| 89 | - /**  | 
                                                        |
| 90 | - * CloudFederationProvider constructor.  | 
                                                        |
| 91 | - *  | 
                                                        |
| 92 | - * @param IAppManager $appManager  | 
                                                        |
| 93 | - * @param FederatedShareProvider $federatedShareProvider  | 
                                                        |
| 94 | - * @param AddressHandler $addressHandler  | 
                                                        |
| 95 | - * @param ILogger $logger  | 
                                                        |
| 96 | - * @param IUserManager $userManager  | 
                                                        |
| 97 | - * @param ICloudIdManager $cloudIdManager  | 
                                                        |
| 98 | - * @param IActivityManager $activityManager  | 
                                                        |
| 99 | - * @param INotificationManager $notificationManager  | 
                                                        |
| 100 | - * @param IURLGenerator $urlGenerator  | 
                                                        |
| 101 | - * @param ICloudFederationFactory $cloudFederationFactory  | 
                                                        |
| 102 | - * @param ICloudFederationProviderManager $cloudFederationProviderManager  | 
                                                        |
| 103 | - * @param IDBConnection $connection  | 
                                                        |
| 104 | - */  | 
                                                        |
| 105 | - public function __construct(IAppManager $appManager,  | 
                                                        |
| 106 | - FederatedShareProvider $federatedShareProvider,  | 
                                                        |
| 107 | - AddressHandler $addressHandler,  | 
                                                        |
| 108 | - ILogger $logger,  | 
                                                        |
| 109 | - IUserManager $userManager,  | 
                                                        |
| 110 | - ICloudIdManager $cloudIdManager,  | 
                                                        |
| 111 | - IActivityManager $activityManager,  | 
                                                        |
| 112 | - INotificationManager $notificationManager,  | 
                                                        |
| 113 | - IURLGenerator $urlGenerator,  | 
                                                        |
| 114 | - ICloudFederationFactory $cloudFederationFactory,  | 
                                                        |
| 115 | - ICloudFederationProviderManager $cloudFederationProviderManager,  | 
                                                        |
| 116 | - IDBConnection $connection  | 
                                                        |
| 117 | -	) { | 
                                                        |
| 118 | - $this->appManager = $appManager;  | 
                                                        |
| 119 | - $this->federatedShareProvider = $federatedShareProvider;  | 
                                                        |
| 120 | - $this->addressHandler = $addressHandler;  | 
                                                        |
| 121 | - $this->logger = $logger;  | 
                                                        |
| 122 | - $this->userManager = $userManager;  | 
                                                        |
| 123 | - $this->cloudIdManager = $cloudIdManager;  | 
                                                        |
| 124 | - $this->activityManager = $activityManager;  | 
                                                        |
| 125 | - $this->notificationManager = $notificationManager;  | 
                                                        |
| 126 | - $this->urlGenerator = $urlGenerator;  | 
                                                        |
| 127 | - $this->cloudFederationFactory = $cloudFederationFactory;  | 
                                                        |
| 128 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager;  | 
                                                        |
| 129 | - $this->connection = $connection;  | 
                                                        |
| 130 | - }  | 
                                                        |
| 131 | -  | 
                                                        |
| 132 | -  | 
                                                        |
| 133 | -  | 
                                                        |
| 134 | - /**  | 
                                                        |
| 135 | - * @return string  | 
                                                        |
| 136 | - */  | 
                                                        |
| 137 | -	public function getShareType() { | 
                                                        |
| 138 | - return 'file';  | 
                                                        |
| 139 | - }  | 
                                                        |
| 140 | -  | 
                                                        |
| 141 | - /**  | 
                                                        |
| 142 | - * share received from another server  | 
                                                        |
| 143 | - *  | 
                                                        |
| 144 | - * @param ICloudFederationShare $share  | 
                                                        |
| 145 | - * @return string provider specific unique ID of the share  | 
                                                        |
| 146 | - *  | 
                                                        |
| 147 | - * @throws ProviderCouldNotAddShareException  | 
                                                        |
| 148 | - * @throws \OCP\AppFramework\QueryException  | 
                                                        |
| 149 | - * @throws \OC\HintException  | 
                                                        |
| 150 | - * @since 14.0.0  | 
                                                        |
| 151 | - */  | 
                                                        |
| 152 | -	public function shareReceived(ICloudFederationShare $share) { | 
                                                        |
| 153 | -  | 
                                                        |
| 154 | -		if (!$this->isS2SEnabled(true)) { | 
                                                        |
| 155 | -			throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE); | 
                                                        |
| 156 | - }  | 
                                                        |
| 157 | -  | 
                                                        |
| 158 | - $protocol = $share->getProtocol();  | 
                                                        |
| 159 | -		if ($protocol['name'] !== 'webdav') { | 
                                                        |
| 160 | -			throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED); | 
                                                        |
| 161 | - }  | 
                                                        |
| 162 | -  | 
                                                        |
| 163 | - list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner());  | 
                                                        |
| 164 | -  | 
                                                        |
| 165 | - $token = $share->getShareSecret();  | 
                                                        |
| 166 | - $name = $share->getResourceName();  | 
                                                        |
| 167 | - $owner = $share->getOwnerDisplayName();  | 
                                                        |
| 168 | - $sharedBy = $share->getSharedByDisplayName();  | 
                                                        |
| 169 | - $shareWith = $share->getShareWith();  | 
                                                        |
| 170 | - $remoteId = $share->getProviderId();  | 
                                                        |
| 171 | - $sharedByFederatedId = $share->getSharedBy();  | 
                                                        |
| 172 | - $ownerFederatedId = $share->getOwner();  | 
                                                        |
| 173 | -  | 
                                                        |
| 174 | - // if no explicit information about the person who created the share was send  | 
                                                        |
| 175 | - // we assume that the share comes from the owner  | 
                                                        |
| 176 | -		if ($sharedByFederatedId === null) { | 
                                                        |
| 177 | - $sharedBy = $owner;  | 
                                                        |
| 178 | - $sharedByFederatedId = $ownerFederatedId;  | 
                                                        |
| 179 | - }  | 
                                                        |
| 180 | -  | 
                                                        |
| 181 | -		if ($remote && $token && $name && $owner && $remoteId && $shareWith) { | 
                                                        |
| 182 | -  | 
                                                        |
| 183 | -			if (!Util::isValidFileName($name)) { | 
                                                        |
| 184 | -				throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST); | 
                                                        |
| 185 | - }  | 
                                                        |
| 186 | -  | 
                                                        |
| 187 | - // FIXME this should be a method in the user management instead  | 
                                                        |
| 188 | -			$this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); | 
                                                        |
| 189 | - Util::emitHook(  | 
                                                        |
| 190 | - '\OCA\Files_Sharing\API\Server2Server',  | 
                                                        |
| 191 | - 'preLoginNameUsedAsUserName',  | 
                                                        |
| 192 | -				array('uid' => &$shareWith) | 
                                                        |
| 193 | - );  | 
                                                        |
| 194 | -			$this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); | 
                                                        |
| 195 | -  | 
                                                        |
| 196 | -			if (!$this->userManager->userExists($shareWith)) { | 
                                                        |
| 197 | -				throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); | 
                                                        |
| 198 | - }  | 
                                                        |
| 199 | -  | 
                                                        |
| 200 | - \OC_Util::setupFS($shareWith);  | 
                                                        |
| 201 | -  | 
                                                        |
| 202 | - $externalManager = new \OCA\Files_Sharing\External\Manager(  | 
                                                        |
| 203 | - \OC::$server->getDatabaseConnection(),  | 
                                                        |
| 204 | - Filesystem::getMountManager(),  | 
                                                        |
| 205 | - Filesystem::getLoader(),  | 
                                                        |
| 206 | - \OC::$server->getHTTPClientService(),  | 
                                                        |
| 207 | - \OC::$server->getNotificationManager(),  | 
                                                        |
| 208 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class),  | 
                                                        |
| 209 | - \OC::$server->getCloudFederationProviderManager(),  | 
                                                        |
| 210 | - \OC::$server->getCloudFederationFactory(),  | 
                                                        |
| 211 | - $shareWith  | 
                                                        |
| 212 | - );  | 
                                                        |
| 213 | -  | 
                                                        |
| 214 | -			try { | 
                                                        |
| 215 | - $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);  | 
                                                        |
| 216 | -				$shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); | 
                                                        |
| 217 | -  | 
                                                        |
| 218 | - $event = $this->activityManager->generateEvent();  | 
                                                        |
| 219 | -				$event->setApp('files_sharing') | 
                                                        |
| 220 | -					->setType('remote_share') | 
                                                        |
| 221 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')])  | 
                                                        |
| 222 | - ->setAffectedUser($shareWith)  | 
                                                        |
| 223 | -					->setObject('remote_share', (int)$shareId, $name); | 
                                                        |
| 224 | - \OC::$server->getActivityManager()->publish($event);  | 
                                                        |
| 225 | -  | 
                                                        |
| 226 | - $notification = $this->notificationManager->createNotification();  | 
                                                        |
| 227 | -				$notification->setApp('files_sharing') | 
                                                        |
| 228 | - ->setUser($shareWith)  | 
                                                        |
| 229 | - ->setDateTime(new \DateTime())  | 
                                                        |
| 230 | -					->setObject('remote_share', $shareId) | 
                                                        |
| 231 | -					->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); | 
                                                        |
| 232 | -  | 
                                                        |
| 233 | - $declineAction = $notification->createAction();  | 
                                                        |
| 234 | -				$declineAction->setLabel('decline') | 
                                                        |
| 235 | -					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); | 
                                                        |
| 236 | - $notification->addAction($declineAction);  | 
                                                        |
| 237 | -  | 
                                                        |
| 238 | - $acceptAction = $notification->createAction();  | 
                                                        |
| 239 | -				$acceptAction->setLabel('accept') | 
                                                        |
| 240 | -					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); | 
                                                        |
| 241 | - $notification->addAction($acceptAction);  | 
                                                        |
| 242 | -  | 
                                                        |
| 243 | - $this->notificationManager->notify($notification);  | 
                                                        |
| 244 | -  | 
                                                        |
| 245 | - return $shareId;  | 
                                                        |
| 246 | -			} catch (\Exception $e) { | 
                                                        |
| 247 | - $this->logger->logException($e, [  | 
                                                        |
| 248 | - 'message' => 'Server can not add remote share.',  | 
                                                        |
| 249 | - 'level' => ILogger::ERROR,  | 
                                                        |
| 250 | - 'app' => 'files_sharing'  | 
                                                        |
| 251 | - ]);  | 
                                                        |
| 252 | -				throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); | 
                                                        |
| 253 | - }  | 
                                                        |
| 254 | - }  | 
                                                        |
| 255 | -  | 
                                                        |
| 256 | -		throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST); | 
                                                        |
| 257 | -  | 
                                                        |
| 258 | - }  | 
                                                        |
| 259 | -  | 
                                                        |
| 260 | - /**  | 
                                                        |
| 261 | - * notification received from another server  | 
                                                        |
| 262 | - *  | 
                                                        |
| 263 | - * @param string $notificationType (e.g. SHARE_ACCEPTED)  | 
                                                        |
| 264 | - * @param string $providerId id of the share  | 
                                                        |
| 265 | - * @param array $notification payload of the notification  | 
                                                        |
| 266 | - * @return array data send back to the sender  | 
                                                        |
| 267 | - *  | 
                                                        |
| 268 | - * @throws ActionNotSupportedException  | 
                                                        |
| 269 | - * @throws AuthenticationFailedException  | 
                                                        |
| 270 | - * @throws BadRequestException  | 
                                                        |
| 271 | - * @throws \OC\HintException  | 
                                                        |
| 272 | - * @since 14.0.0  | 
                                                        |
| 273 | - */  | 
                                                        |
| 274 | -	public function notificationReceived($notificationType, $providerId, array $notification) { | 
                                                        |
| 275 | -  | 
                                                        |
| 276 | -		switch ($notificationType) { | 
                                                        |
| 277 | - case 'SHARE_ACCEPTED':  | 
                                                        |
| 278 | - return $this->shareAccepted($providerId, $notification);  | 
                                                        |
| 279 | - case 'SHARE_DECLINED':  | 
                                                        |
| 280 | - return $this->shareDeclined($providerId, $notification);  | 
                                                        |
| 281 | - case 'SHARE_UNSHARED':  | 
                                                        |
| 282 | - return $this->unshare($providerId, $notification);  | 
                                                        |
| 283 | - case 'REQUEST_RESHARE':  | 
                                                        |
| 284 | - return $this->reshareRequested($providerId, $notification);  | 
                                                        |
| 285 | - case 'RESHARE_UNDO':  | 
                                                        |
| 286 | - return $this->undoReshare($providerId, $notification);  | 
                                                        |
| 287 | - case 'RESHARE_CHANGE_PERMISSION':  | 
                                                        |
| 288 | - return $this->updateResharePermissions($providerId, $notification);  | 
                                                        |
| 289 | - }  | 
                                                        |
| 290 | -  | 
                                                        |
| 291 | -  | 
                                                        |
| 292 | - throw new BadRequestException([$notificationType]);  | 
                                                        |
| 293 | - }  | 
                                                        |
| 294 | -  | 
                                                        |
| 295 | - /**  | 
                                                        |
| 296 | - * process notification that the recipient accepted a share  | 
                                                        |
| 297 | - *  | 
                                                        |
| 298 | - * @param string $id  | 
                                                        |
| 299 | - * @param array $notification  | 
                                                        |
| 300 | - * @return array  | 
                                                        |
| 301 | - * @throws ActionNotSupportedException  | 
                                                        |
| 302 | - * @throws AuthenticationFailedException  | 
                                                        |
| 303 | - * @throws BadRequestException  | 
                                                        |
| 304 | - * @throws \OC\HintException  | 
                                                        |
| 305 | - */  | 
                                                        |
| 306 | -	private function shareAccepted($id, array $notification) { | 
                                                        |
| 307 | -  | 
                                                        |
| 308 | -		if (!$this->isS2SEnabled()) { | 
                                                        |
| 309 | -			throw new ActionNotSupportedException('Server does not support federated cloud sharing'); | 
                                                        |
| 310 | - }  | 
                                                        |
| 311 | -  | 
                                                        |
| 312 | -		if (!isset($notification['sharedSecret'])) { | 
                                                        |
| 313 | - throw new BadRequestException(['sharedSecret']);  | 
                                                        |
| 314 | - }  | 
                                                        |
| 315 | -  | 
                                                        |
| 316 | - $token = $notification['sharedSecret'];  | 
                                                        |
| 317 | -  | 
                                                        |
| 318 | - $share = $this->federatedShareProvider->getShareById($id);  | 
                                                        |
| 319 | -  | 
                                                        |
| 320 | - $this->verifyShare($share, $token);  | 
                                                        |
| 321 | - $this->executeAcceptShare($share);  | 
                                                        |
| 322 | -		if ($share->getShareOwner() !== $share->getSharedBy()) { | 
                                                        |
| 323 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());  | 
                                                        |
| 324 | - $remoteId = $this->federatedShareProvider->getRemoteId($share);  | 
                                                        |
| 325 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification();  | 
                                                        |
| 326 | - $notification->setMessage(  | 
                                                        |
| 327 | - 'SHARE_ACCEPTED',  | 
                                                        |
| 328 | - 'file',  | 
                                                        |
| 329 | - $remoteId,  | 
                                                        |
| 330 | - [  | 
                                                        |
| 331 | - 'sharedSecret' => $token,  | 
                                                        |
| 332 | - 'message' => 'Recipient accepted the re-share'  | 
                                                        |
| 333 | - ]  | 
                                                        |
| 334 | -  | 
                                                        |
| 335 | - );  | 
                                                        |
| 336 | - $this->cloudFederationProviderManager->sendNotification($remote, $notification);  | 
                                                        |
| 337 | -  | 
                                                        |
| 338 | - }  | 
                                                        |
| 339 | -  | 
                                                        |
| 340 | - return [];  | 
                                                        |
| 341 | - }  | 
                                                        |
| 342 | -  | 
                                                        |
| 343 | - /**  | 
                                                        |
| 344 | - * @param IShare $share  | 
                                                        |
| 345 | - * @throws ShareNotFound  | 
                                                        |
| 346 | - */  | 
                                                        |
| 347 | -	protected function executeAcceptShare(IShare $share) { | 
                                                        |
| 348 | -		try { | 
                                                        |
| 349 | - $fileId = (int)$share->getNode()->getId();  | 
                                                        |
| 350 | - list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);  | 
                                                        |
| 351 | -		} catch (\Exception $e) { | 
                                                        |
| 352 | - throw new ShareNotFound();  | 
                                                        |
| 353 | - }  | 
                                                        |
| 354 | -  | 
                                                        |
| 355 | - $event = $this->activityManager->generateEvent();  | 
                                                        |
| 356 | -		$event->setApp('files_sharing') | 
                                                        |
| 357 | -			->setType('remote_share') | 
                                                        |
| 358 | - ->setAffectedUser($this->getCorrectUid($share))  | 
                                                        |
| 359 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]])  | 
                                                        |
| 360 | -			->setObject('files', $fileId, $file) | 
                                                        |
| 361 | - ->setLink($link);  | 
                                                        |
| 362 | - $this->activityManager->publish($event);  | 
                                                        |
| 363 | - }  | 
                                                        |
| 364 | -  | 
                                                        |
| 365 | - /**  | 
                                                        |
| 366 | - * process notification that the recipient declined a share  | 
                                                        |
| 367 | - *  | 
                                                        |
| 368 | - * @param string $id  | 
                                                        |
| 369 | - * @param array $notification  | 
                                                        |
| 370 | - * @return array  | 
                                                        |
| 371 | - * @throws ActionNotSupportedException  | 
                                                        |
| 372 | - * @throws AuthenticationFailedException  | 
                                                        |
| 373 | - * @throws BadRequestException  | 
                                                        |
| 374 | - * @throws ShareNotFound  | 
                                                        |
| 375 | - * @throws \OC\HintException  | 
                                                        |
| 376 | - *  | 
                                                        |
| 377 | - */  | 
                                                        |
| 378 | -	protected function shareDeclined($id, array $notification) { | 
                                                        |
| 379 | -  | 
                                                        |
| 380 | -		if (!$this->isS2SEnabled()) { | 
                                                        |
| 381 | -			throw new ActionNotSupportedException('Server does not support federated cloud sharing'); | 
                                                        |
| 382 | - }  | 
                                                        |
| 383 | -  | 
                                                        |
| 384 | -		if (!isset($notification['sharedSecret'])) { | 
                                                        |
| 385 | - throw new BadRequestException(['sharedSecret']);  | 
                                                        |
| 386 | - }  | 
                                                        |
| 387 | -  | 
                                                        |
| 388 | - $token = $notification['sharedSecret'];  | 
                                                        |
| 389 | -  | 
                                                        |
| 390 | - $share = $this->federatedShareProvider->getShareById($id);  | 
                                                        |
| 391 | -  | 
                                                        |
| 392 | - $this->verifyShare($share, $token);  | 
                                                        |
| 393 | -  | 
                                                        |
| 394 | -		if ($share->getShareOwner() !== $share->getSharedBy()) { | 
                                                        |
| 395 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());  | 
                                                        |
| 396 | - $remoteId = $this->federatedShareProvider->getRemoteId($share);  | 
                                                        |
| 397 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification();  | 
                                                        |
| 398 | - $notification->setMessage(  | 
                                                        |
| 399 | - 'SHARE_DECLINED',  | 
                                                        |
| 400 | - 'file',  | 
                                                        |
| 401 | - $remoteId,  | 
                                                        |
| 402 | - [  | 
                                                        |
| 403 | - 'sharedSecret' => $token,  | 
                                                        |
| 404 | - 'message' => 'Recipient declined the re-share'  | 
                                                        |
| 405 | - ]  | 
                                                        |
| 406 | -  | 
                                                        |
| 407 | - );  | 
                                                        |
| 408 | - $this->cloudFederationProviderManager->sendNotification($remote, $notification);  | 
                                                        |
| 409 | - }  | 
                                                        |
| 410 | -  | 
                                                        |
| 411 | - $this->executeDeclineShare($share);  | 
                                                        |
| 412 | -  | 
                                                        |
| 413 | - return [];  | 
                                                        |
| 414 | -  | 
                                                        |
| 415 | - }  | 
                                                        |
| 416 | -  | 
                                                        |
| 417 | - /**  | 
                                                        |
| 418 | - * delete declined share and create a activity  | 
                                                        |
| 419 | - *  | 
                                                        |
| 420 | - * @param IShare $share  | 
                                                        |
| 421 | - * @throws ShareNotFound  | 
                                                        |
| 422 | - */  | 
                                                        |
| 423 | -	protected function executeDeclineShare(IShare $share) { | 
                                                        |
| 424 | - $this->federatedShareProvider->removeShareFromTable($share);  | 
                                                        |
| 425 | -  | 
                                                        |
| 426 | -		try { | 
                                                        |
| 427 | - $fileId = (int)$share->getNode()->getId();  | 
                                                        |
| 428 | - list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);  | 
                                                        |
| 429 | -		} catch (\Exception $e) { | 
                                                        |
| 430 | - throw new ShareNotFound();  | 
                                                        |
| 431 | - }  | 
                                                        |
| 432 | -  | 
                                                        |
| 433 | - $event = $this->activityManager->generateEvent();  | 
                                                        |
| 434 | -		$event->setApp('files_sharing') | 
                                                        |
| 435 | -			->setType('remote_share') | 
                                                        |
| 436 | - ->setAffectedUser($this->getCorrectUid($share))  | 
                                                        |
| 437 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), [$fileId => $file]])  | 
                                                        |
| 438 | -			->setObject('files', $fileId, $file) | 
                                                        |
| 439 | - ->setLink($link);  | 
                                                        |
| 440 | - $this->activityManager->publish($event);  | 
                                                        |
| 441 | -  | 
                                                        |
| 442 | - }  | 
                                                        |
| 443 | -  | 
                                                        |
| 444 | - /**  | 
                                                        |
| 445 | - * received the notification that the owner unshared a file from you  | 
                                                        |
| 446 | - *  | 
                                                        |
| 447 | - * @param string $id  | 
                                                        |
| 448 | - * @param array $notification  | 
                                                        |
| 449 | - * @return array  | 
                                                        |
| 450 | - * @throws AuthenticationFailedException  | 
                                                        |
| 451 | - * @throws BadRequestException  | 
                                                        |
| 452 | - */  | 
                                                        |
| 453 | -	private function undoReshare($id, array $notification) { | 
                                                        |
| 454 | -		if (!isset($notification['sharedSecret'])) { | 
                                                        |
| 455 | - throw new BadRequestException(['sharedSecret']);  | 
                                                        |
| 456 | - }  | 
                                                        |
| 457 | - $token = $notification['sharedSecret'];  | 
                                                        |
| 458 | -  | 
                                                        |
| 459 | - $share = $this->federatedShareProvider->getShareById($id);  | 
                                                        |
| 460 | -  | 
                                                        |
| 461 | - $this->verifyShare($share, $token);  | 
                                                        |
| 462 | - $this->federatedShareProvider->removeShareFromTable($share);  | 
                                                        |
| 463 | - return [];  | 
                                                        |
| 464 | - }  | 
                                                        |
| 465 | -  | 
                                                        |
| 466 | - /**  | 
                                                        |
| 467 | - * unshare file from self  | 
                                                        |
| 468 | - *  | 
                                                        |
| 469 | - * @param string $id  | 
                                                        |
| 470 | - * @param array $notification  | 
                                                        |
| 471 | - * @return array  | 
                                                        |
| 472 | - * @throws ActionNotSupportedException  | 
                                                        |
| 473 | - * @throws BadRequestException  | 
                                                        |
| 474 | - */  | 
                                                        |
| 475 | -	private function unshare($id, array $notification) { | 
                                                        |
| 476 | -  | 
                                                        |
| 477 | -		if (!$this->isS2SEnabled(true)) { | 
                                                        |
| 478 | -			throw new ActionNotSupportedException("incoming shares disabled!"); | 
                                                        |
| 479 | - }  | 
                                                        |
| 480 | -  | 
                                                        |
| 481 | -		if (!isset($notification['sharedSecret'])) { | 
                                                        |
| 482 | - throw new BadRequestException(['sharedSecret']);  | 
                                                        |
| 483 | - }  | 
                                                        |
| 484 | - $token = $notification['sharedSecret'];  | 
                                                        |
| 485 | -  | 
                                                        |
| 486 | - $qb = $this->connection->getQueryBuilder();  | 
                                                        |
| 487 | -		$qb->select('*') | 
                                                        |
| 488 | -			->from('share_external') | 
                                                        |
| 489 | - ->where(  | 
                                                        |
| 490 | - $qb->expr()->andX(  | 
                                                        |
| 491 | -					$qb->expr()->eq('remote_id', $qb->createNamedParameter($id)), | 
                                                        |
| 492 | -					$qb->expr()->eq('share_token', $qb->createNamedParameter($token)) | 
                                                        |
| 493 | - )  | 
                                                        |
| 494 | - );  | 
                                                        |
| 495 | -  | 
                                                        |
| 496 | - $result = $qb->execute();  | 
                                                        |
| 497 | - $share = $result->fetch();  | 
                                                        |
| 498 | - $result->closeCursor();  | 
                                                        |
| 499 | -  | 
                                                        |
| 500 | -		if ($token && $id && !empty($share)) { | 
                                                        |
| 501 | -  | 
                                                        |
| 502 | - $remote = $this->cleanupRemote($share['remote']);  | 
                                                        |
| 503 | -  | 
                                                        |
| 504 | - $owner = $this->cloudIdManager->getCloudId($share['owner'], $remote);  | 
                                                        |
| 505 | - $mountpoint = $share['mountpoint'];  | 
                                                        |
| 506 | - $user = $share['user'];  | 
                                                        |
| 507 | -  | 
                                                        |
| 508 | - $qb = $this->connection->getQueryBuilder();  | 
                                                        |
| 509 | -			$qb->delete('share_external') | 
                                                        |
| 510 | - ->where(  | 
                                                        |
| 511 | - $qb->expr()->andX(  | 
                                                        |
| 512 | -						$qb->expr()->eq('remote_id', $qb->createNamedParameter($id)), | 
                                                        |
| 513 | -						$qb->expr()->eq('share_token', $qb->createNamedParameter($token)) | 
                                                        |
| 514 | - )  | 
                                                        |
| 515 | - );  | 
                                                        |
| 516 | -  | 
                                                        |
| 517 | - $qb->execute();  | 
                                                        |
| 518 | -  | 
                                                        |
| 519 | -			if ($share['accepted']) { | 
                                                        |
| 520 | - $path = trim($mountpoint, '/');  | 
                                                        |
| 521 | -			} else { | 
                                                        |
| 522 | - $path = trim($share['name'], '/');  | 
                                                        |
| 523 | - }  | 
                                                        |
| 524 | -  | 
                                                        |
| 525 | - $notification = $this->notificationManager->createNotification();  | 
                                                        |
| 526 | -			$notification->setApp('files_sharing') | 
                                                        |
| 527 | - ->setUser($share['user'])  | 
                                                        |
| 528 | -				->setObject('remote_share', (int)$share['id']); | 
                                                        |
| 529 | - $this->notificationManager->markProcessed($notification);  | 
                                                        |
| 530 | -  | 
                                                        |
| 531 | - $event = $this->activityManager->generateEvent();  | 
                                                        |
| 532 | -			$event->setApp('files_sharing') | 
                                                        |
| 533 | -				->setType('remote_share') | 
                                                        |
| 534 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path])  | 
                                                        |
| 535 | - ->setAffectedUser($user)  | 
                                                        |
| 536 | -				->setObject('remote_share', (int)$share['id'], $path); | 
                                                        |
| 537 | - \OC::$server->getActivityManager()->publish($event);  | 
                                                        |
| 538 | - }  | 
                                                        |
| 539 | -  | 
                                                        |
| 540 | - return [];  | 
                                                        |
| 541 | - }  | 
                                                        |
| 542 | -  | 
                                                        |
| 543 | -	private function cleanupRemote($remote) { | 
                                                        |
| 544 | - $remote = substr($remote, strpos($remote, '://') + 3);  | 
                                                        |
| 545 | -  | 
                                                        |
| 546 | - return rtrim($remote, '/');  | 
                                                        |
| 547 | - }  | 
                                                        |
| 548 | -  | 
                                                        |
| 549 | - /**  | 
                                                        |
| 550 | - * recipient of a share request to re-share the file with another user  | 
                                                        |
| 551 | - *  | 
                                                        |
| 552 | - * @param string $id  | 
                                                        |
| 553 | - * @param array $notification  | 
                                                        |
| 554 | - * @return array  | 
                                                        |
| 555 | - * @throws AuthenticationFailedException  | 
                                                        |
| 556 | - * @throws BadRequestException  | 
                                                        |
| 557 | - * @throws ProviderCouldNotAddShareException  | 
                                                        |
| 558 | - * @throws ShareNotFound  | 
                                                        |
| 559 | - */  | 
                                                        |
| 560 | -	protected function reshareRequested($id, array $notification) { | 
                                                        |
| 561 | -  | 
                                                        |
| 562 | -		if (!isset($notification['sharedSecret'])) { | 
                                                        |
| 563 | - throw new BadRequestException(['sharedSecret']);  | 
                                                        |
| 564 | - }  | 
                                                        |
| 565 | - $token = $notification['sharedSecret'];  | 
                                                        |
| 566 | -  | 
                                                        |
| 567 | -		if (!isset($notification['shareWith'])) { | 
                                                        |
| 568 | - throw new BadRequestException(['shareWith']);  | 
                                                        |
| 569 | - }  | 
                                                        |
| 570 | - $shareWith = $notification['shareWith'];  | 
                                                        |
| 571 | -  | 
                                                        |
| 572 | -		if (!isset($notification['senderId'])) { | 
                                                        |
| 573 | - throw new BadRequestException(['senderId']);  | 
                                                        |
| 574 | - }  | 
                                                        |
| 575 | - $senderId = $notification['senderId'];  | 
                                                        |
| 576 | -  | 
                                                        |
| 577 | - $share = $this->federatedShareProvider->getShareById($id);  | 
                                                        |
| 578 | - // don't allow to share a file back to the owner  | 
                                                        |
| 579 | -		try { | 
                                                        |
| 580 | - list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);  | 
                                                        |
| 581 | - $owner = $share->getShareOwner();  | 
                                                        |
| 582 | - $currentServer = $this->addressHandler->generateRemoteURL();  | 
                                                        |
| 583 | -			if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) { | 
                                                        |
| 584 | -				throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id); | 
                                                        |
| 585 | - }  | 
                                                        |
| 586 | -		} catch (\Exception $e) { | 
                                                        |
| 587 | - throw new ProviderCouldNotAddShareException($e->getMessage());  | 
                                                        |
| 588 | - }  | 
                                                        |
| 589 | -  | 
                                                        |
| 590 | - $this->verifyShare($share, $token);  | 
                                                        |
| 591 | -  | 
                                                        |
| 592 | - // check if re-sharing is allowed  | 
                                                        |
| 593 | -		if ($share->getPermissions() & Constants::PERMISSION_SHARE) { | 
                                                        |
| 594 | - // the recipient of the initial share is now the initiator for the re-share  | 
                                                        |
| 595 | - $share->setSharedBy($share->getSharedWith());  | 
                                                        |
| 596 | - $share->setSharedWith($shareWith);  | 
                                                        |
| 597 | - $result = $this->federatedShareProvider->create($share);  | 
                                                        |
| 598 | - $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId);  | 
                                                        |
| 599 | - return ['token' => $result->getToken(), 'providerId' => $result->getId()];  | 
                                                        |
| 600 | -		} else { | 
                                                        |
| 601 | -			throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id); | 
                                                        |
| 602 | - }  | 
                                                        |
| 603 | -  | 
                                                        |
| 604 | - }  | 
                                                        |
| 605 | -  | 
                                                        |
| 606 | - /**  | 
                                                        |
| 607 | - * update permission of a re-share so that the share dialog shows the right  | 
                                                        |
| 608 | - * permission if the owner or the sender changes the permission  | 
                                                        |
| 609 | - *  | 
                                                        |
| 610 | - * @param string $id  | 
                                                        |
| 611 | - * @param array $notification  | 
                                                        |
| 612 | - * @return array  | 
                                                        |
| 613 | - * @throws AuthenticationFailedException  | 
                                                        |
| 614 | - * @throws BadRequestException  | 
                                                        |
| 615 | - */  | 
                                                        |
| 616 | -	protected function updateResharePermissions($id, array $notification) { | 
                                                        |
| 617 | -  | 
                                                        |
| 618 | -		if (!isset($notification['sharedSecret'])) { | 
                                                        |
| 619 | - throw new BadRequestException(['sharedSecret']);  | 
                                                        |
| 620 | - }  | 
                                                        |
| 621 | - $token = $notification['sharedSecret'];  | 
                                                        |
| 622 | -  | 
                                                        |
| 623 | -		if (!isset($notification['permission'])) { | 
                                                        |
| 624 | - throw new BadRequestException(['permission']);  | 
                                                        |
| 625 | - }  | 
                                                        |
| 626 | - $ocmPermissions = $notification['permission'];  | 
                                                        |
| 627 | -  | 
                                                        |
| 628 | - $share = $this->federatedShareProvider->getShareById($id);  | 
                                                        |
| 629 | -  | 
                                                        |
| 630 | - $ncPermission = $this->ocmPermissions2ncPermissions($ocmPermissions);  | 
                                                        |
| 631 | -  | 
                                                        |
| 632 | - $this->verifyShare($share, $token);  | 
                                                        |
| 633 | - $this->updatePermissionsInDatabase($share, $ncPermission);  | 
                                                        |
| 634 | -  | 
                                                        |
| 635 | - return [];  | 
                                                        |
| 636 | - }  | 
                                                        |
| 637 | -  | 
                                                        |
| 638 | - /**  | 
                                                        |
| 639 | - * translate OCM Permissions to Nextcloud permissions  | 
                                                        |
| 640 | - *  | 
                                                        |
| 641 | - * @param array $ocmPermissions  | 
                                                        |
| 642 | - * @return int  | 
                                                        |
| 643 | - * @throws BadRequestException  | 
                                                        |
| 644 | - */  | 
                                                        |
| 645 | -	protected function ocmPermissions2ncPermissions(array $ocmPermissions) { | 
                                                        |
| 646 | - $ncPermissions = 0;  | 
                                                        |
| 647 | -		foreach($ocmPermissions as $permission) { | 
                                                        |
| 648 | -			switch (strtolower($permission)) { | 
                                                        |
| 649 | - case 'read':  | 
                                                        |
| 650 | - $ncPermissions += Constants::PERMISSION_READ;  | 
                                                        |
| 651 | - break;  | 
                                                        |
| 652 | - case 'write':  | 
                                                        |
| 653 | - $ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE;  | 
                                                        |
| 654 | - break;  | 
                                                        |
| 655 | - case 'share':  | 
                                                        |
| 656 | - $ncPermissions += Constants::PERMISSION_SHARE;  | 
                                                        |
| 657 | - break;  | 
                                                        |
| 658 | - default:  | 
                                                        |
| 659 | - throw new BadRequestException(['permission']);  | 
                                                        |
| 660 | - }  | 
                                                        |
| 661 | -  | 
                                                        |
| 662 | -			error_log("new permissions: " . $ncPermissions); | 
                                                        |
| 663 | - }  | 
                                                        |
| 664 | -  | 
                                                        |
| 665 | - return $ncPermissions;  | 
                                                        |
| 666 | - }  | 
                                                        |
| 667 | -  | 
                                                        |
| 668 | - /**  | 
                                                        |
| 669 | - * update permissions in database  | 
                                                        |
| 670 | - *  | 
                                                        |
| 671 | - * @param IShare $share  | 
                                                        |
| 672 | - * @param int $permissions  | 
                                                        |
| 673 | - */  | 
                                                        |
| 674 | -	protected function updatePermissionsInDatabase(IShare $share, $permissions) { | 
                                                        |
| 675 | - $query = $this->connection->getQueryBuilder();  | 
                                                        |
| 676 | -		$query->update('share') | 
                                                        |
| 677 | -			->where($query->expr()->eq('id', $query->createNamedParameter($share->getId()))) | 
                                                        |
| 678 | -			->set('permissions', $query->createNamedParameter($permissions)) | 
                                                        |
| 679 | - ->execute();  | 
                                                        |
| 680 | - }  | 
                                                        |
| 681 | -  | 
                                                        |
| 682 | -  | 
                                                        |
| 683 | - /**  | 
                                                        |
| 684 | - * get file  | 
                                                        |
| 685 | - *  | 
                                                        |
| 686 | - * @param string $user  | 
                                                        |
| 687 | - * @param int $fileSource  | 
                                                        |
| 688 | - * @return array with internal path of the file and a absolute link to it  | 
                                                        |
| 689 | - */  | 
                                                        |
| 690 | -	private function getFile($user, $fileSource) { | 
                                                        |
| 691 | - \OC_Util::setupFS($user);  | 
                                                        |
| 692 | -  | 
                                                        |
| 693 | -		try { | 
                                                        |
| 694 | - $file = Filesystem::getPath($fileSource);  | 
                                                        |
| 695 | -		} catch (NotFoundException $e) { | 
                                                        |
| 696 | - $file = null;  | 
                                                        |
| 697 | - }  | 
                                                        |
| 698 | -		$args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); | 
                                                        |
| 699 | -		$link = Util::linkToAbsolute('files', 'index.php', $args); | 
                                                        |
| 700 | -  | 
                                                        |
| 701 | - return [$file, $link];  | 
                                                        |
| 702 | -  | 
                                                        |
| 703 | - }  | 
                                                        |
| 704 | -  | 
                                                        |
| 705 | - /**  | 
                                                        |
| 706 | - * check if we are the initiator or the owner of a re-share and return the correct UID  | 
                                                        |
| 707 | - *  | 
                                                        |
| 708 | - * @param IShare $share  | 
                                                        |
| 709 | - * @return string  | 
                                                        |
| 710 | - */  | 
                                                        |
| 711 | -	protected function getCorrectUid(IShare $share) { | 
                                                        |
| 712 | -		if ($this->userManager->userExists($share->getShareOwner())) { | 
                                                        |
| 713 | - return $share->getShareOwner();  | 
                                                        |
| 714 | - }  | 
                                                        |
| 715 | -  | 
                                                        |
| 716 | - return $share->getSharedBy();  | 
                                                        |
| 717 | - }  | 
                                                        |
| 718 | -  | 
                                                        |
| 719 | -  | 
                                                        |
| 720 | -  | 
                                                        |
| 721 | - /**  | 
                                                        |
| 722 | - * check if we got the right share  | 
                                                        |
| 723 | - *  | 
                                                        |
| 724 | - * @param IShare $share  | 
                                                        |
| 725 | - * @param string $token  | 
                                                        |
| 726 | - * @return bool  | 
                                                        |
| 727 | - * @throws AuthenticationFailedException  | 
                                                        |
| 728 | - */  | 
                                                        |
| 729 | -	protected function verifyShare(IShare $share, $token) { | 
                                                        |
| 730 | - if (  | 
                                                        |
| 731 | - $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE &&  | 
                                                        |
| 732 | - $share->getToken() === $token  | 
                                                        |
| 733 | -		) { | 
                                                        |
| 734 | - return true;  | 
                                                        |
| 735 | - }  | 
                                                        |
| 736 | -  | 
                                                        |
| 737 | - throw new AuthenticationFailedException();  | 
                                                        |
| 738 | - }  | 
                                                        |
| 739 | -  | 
                                                        |
| 740 | -  | 
                                                        |
| 741 | -  | 
                                                        |
| 742 | - /**  | 
                                                        |
| 743 | - * check if server-to-server sharing is enabled  | 
                                                        |
| 744 | - *  | 
                                                        |
| 745 | - * @param bool $incoming  | 
                                                        |
| 746 | - * @return bool  | 
                                                        |
| 747 | - */  | 
                                                        |
| 748 | -	private function isS2SEnabled($incoming = false) { | 
                                                        |
| 749 | -  | 
                                                        |
| 750 | -		$result = $this->appManager->isEnabledForUser('files_sharing'); | 
                                                        |
| 751 | -  | 
                                                        |
| 752 | -		if ($incoming) { | 
                                                        |
| 753 | - $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled();  | 
                                                        |
| 754 | -		} else { | 
                                                        |
| 755 | - $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();  | 
                                                        |
| 756 | - }  | 
                                                        |
| 757 | -  | 
                                                        |
| 758 | - return $result;  | 
                                                        |
| 759 | - }  | 
                                                        |
| 53 | + /** @var IAppManager */  | 
                                                        |
| 54 | + private $appManager;  | 
                                                        |
| 55 | +  | 
                                                        |
| 56 | + /** @var FederatedShareProvider */  | 
                                                        |
| 57 | + private $federatedShareProvider;  | 
                                                        |
| 58 | +  | 
                                                        |
| 59 | + /** @var AddressHandler */  | 
                                                        |
| 60 | + private $addressHandler;  | 
                                                        |
| 61 | +  | 
                                                        |
| 62 | + /** @var ILogger */  | 
                                                        |
| 63 | + private $logger;  | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | + /** @var IUserManager */  | 
                                                        |
| 66 | + private $userManager;  | 
                                                        |
| 67 | +  | 
                                                        |
| 68 | + /** @var ICloudIdManager */  | 
                                                        |
| 69 | + private $cloudIdManager;  | 
                                                        |
| 70 | +  | 
                                                        |
| 71 | + /** @var IActivityManager */  | 
                                                        |
| 72 | + private $activityManager;  | 
                                                        |
| 73 | +  | 
                                                        |
| 74 | + /** @var INotificationManager */  | 
                                                        |
| 75 | + private $notificationManager;  | 
                                                        |
| 76 | +  | 
                                                        |
| 77 | + /** @var IURLGenerator */  | 
                                                        |
| 78 | + private $urlGenerator;  | 
                                                        |
| 79 | +  | 
                                                        |
| 80 | + /** @var ICloudFederationFactory */  | 
                                                        |
| 81 | + private $cloudFederationFactory;  | 
                                                        |
| 82 | +  | 
                                                        |
| 83 | + /** @var ICloudFederationProviderManager */  | 
                                                        |
| 84 | + private $cloudFederationProviderManager;  | 
                                                        |
| 85 | +  | 
                                                        |
| 86 | + /** @var IDBConnection */  | 
                                                        |
| 87 | + private $connection;  | 
                                                        |
| 88 | +  | 
                                                        |
| 89 | + /**  | 
                                                        |
| 90 | + * CloudFederationProvider constructor.  | 
                                                        |
| 91 | + *  | 
                                                        |
| 92 | + * @param IAppManager $appManager  | 
                                                        |
| 93 | + * @param FederatedShareProvider $federatedShareProvider  | 
                                                        |
| 94 | + * @param AddressHandler $addressHandler  | 
                                                        |
| 95 | + * @param ILogger $logger  | 
                                                        |
| 96 | + * @param IUserManager $userManager  | 
                                                        |
| 97 | + * @param ICloudIdManager $cloudIdManager  | 
                                                        |
| 98 | + * @param IActivityManager $activityManager  | 
                                                        |
| 99 | + * @param INotificationManager $notificationManager  | 
                                                        |
| 100 | + * @param IURLGenerator $urlGenerator  | 
                                                        |
| 101 | + * @param ICloudFederationFactory $cloudFederationFactory  | 
                                                        |
| 102 | + * @param ICloudFederationProviderManager $cloudFederationProviderManager  | 
                                                        |
| 103 | + * @param IDBConnection $connection  | 
                                                        |
| 104 | + */  | 
                                                        |
| 105 | + public function __construct(IAppManager $appManager,  | 
                                                        |
| 106 | + FederatedShareProvider $federatedShareProvider,  | 
                                                        |
| 107 | + AddressHandler $addressHandler,  | 
                                                        |
| 108 | + ILogger $logger,  | 
                                                        |
| 109 | + IUserManager $userManager,  | 
                                                        |
| 110 | + ICloudIdManager $cloudIdManager,  | 
                                                        |
| 111 | + IActivityManager $activityManager,  | 
                                                        |
| 112 | + INotificationManager $notificationManager,  | 
                                                        |
| 113 | + IURLGenerator $urlGenerator,  | 
                                                        |
| 114 | + ICloudFederationFactory $cloudFederationFactory,  | 
                                                        |
| 115 | + ICloudFederationProviderManager $cloudFederationProviderManager,  | 
                                                        |
| 116 | + IDBConnection $connection  | 
                                                        |
| 117 | +    ) { | 
                                                        |
| 118 | + $this->appManager = $appManager;  | 
                                                        |
| 119 | + $this->federatedShareProvider = $federatedShareProvider;  | 
                                                        |
| 120 | + $this->addressHandler = $addressHandler;  | 
                                                        |
| 121 | + $this->logger = $logger;  | 
                                                        |
| 122 | + $this->userManager = $userManager;  | 
                                                        |
| 123 | + $this->cloudIdManager = $cloudIdManager;  | 
                                                        |
| 124 | + $this->activityManager = $activityManager;  | 
                                                        |
| 125 | + $this->notificationManager = $notificationManager;  | 
                                                        |
| 126 | + $this->urlGenerator = $urlGenerator;  | 
                                                        |
| 127 | + $this->cloudFederationFactory = $cloudFederationFactory;  | 
                                                        |
| 128 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager;  | 
                                                        |
| 129 | + $this->connection = $connection;  | 
                                                        |
| 130 | + }  | 
                                                        |
| 131 | +  | 
                                                        |
| 132 | +  | 
                                                        |
| 133 | +  | 
                                                        |
| 134 | + /**  | 
                                                        |
| 135 | + * @return string  | 
                                                        |
| 136 | + */  | 
                                                        |
| 137 | +    public function getShareType() { | 
                                                        |
| 138 | + return 'file';  | 
                                                        |
| 139 | + }  | 
                                                        |
| 140 | +  | 
                                                        |
| 141 | + /**  | 
                                                        |
| 142 | + * share received from another server  | 
                                                        |
| 143 | + *  | 
                                                        |
| 144 | + * @param ICloudFederationShare $share  | 
                                                        |
| 145 | + * @return string provider specific unique ID of the share  | 
                                                        |
| 146 | + *  | 
                                                        |
| 147 | + * @throws ProviderCouldNotAddShareException  | 
                                                        |
| 148 | + * @throws \OCP\AppFramework\QueryException  | 
                                                        |
| 149 | + * @throws \OC\HintException  | 
                                                        |
| 150 | + * @since 14.0.0  | 
                                                        |
| 151 | + */  | 
                                                        |
| 152 | +    public function shareReceived(ICloudFederationShare $share) { | 
                                                        |
| 153 | +  | 
                                                        |
| 154 | +        if (!$this->isS2SEnabled(true)) { | 
                                                        |
| 155 | +            throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE); | 
                                                        |
| 156 | + }  | 
                                                        |
| 157 | +  | 
                                                        |
| 158 | + $protocol = $share->getProtocol();  | 
                                                        |
| 159 | +        if ($protocol['name'] !== 'webdav') { | 
                                                        |
| 160 | +            throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED); | 
                                                        |
| 161 | + }  | 
                                                        |
| 162 | +  | 
                                                        |
| 163 | + list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner());  | 
                                                        |
| 164 | +  | 
                                                        |
| 165 | + $token = $share->getShareSecret();  | 
                                                        |
| 166 | + $name = $share->getResourceName();  | 
                                                        |
| 167 | + $owner = $share->getOwnerDisplayName();  | 
                                                        |
| 168 | + $sharedBy = $share->getSharedByDisplayName();  | 
                                                        |
| 169 | + $shareWith = $share->getShareWith();  | 
                                                        |
| 170 | + $remoteId = $share->getProviderId();  | 
                                                        |
| 171 | + $sharedByFederatedId = $share->getSharedBy();  | 
                                                        |
| 172 | + $ownerFederatedId = $share->getOwner();  | 
                                                        |
| 173 | +  | 
                                                        |
| 174 | + // if no explicit information about the person who created the share was send  | 
                                                        |
| 175 | + // we assume that the share comes from the owner  | 
                                                        |
| 176 | +        if ($sharedByFederatedId === null) { | 
                                                        |
| 177 | + $sharedBy = $owner;  | 
                                                        |
| 178 | + $sharedByFederatedId = $ownerFederatedId;  | 
                                                        |
| 179 | + }  | 
                                                        |
| 180 | +  | 
                                                        |
| 181 | +        if ($remote && $token && $name && $owner && $remoteId && $shareWith) { | 
                                                        |
| 182 | +  | 
                                                        |
| 183 | +            if (!Util::isValidFileName($name)) { | 
                                                        |
| 184 | +                throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST); | 
                                                        |
| 185 | + }  | 
                                                        |
| 186 | +  | 
                                                        |
| 187 | + // FIXME this should be a method in the user management instead  | 
                                                        |
| 188 | +            $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); | 
                                                        |
| 189 | + Util::emitHook(  | 
                                                        |
| 190 | + '\OCA\Files_Sharing\API\Server2Server',  | 
                                                        |
| 191 | + 'preLoginNameUsedAsUserName',  | 
                                                        |
| 192 | +                array('uid' => &$shareWith) | 
                                                        |
| 193 | + );  | 
                                                        |
| 194 | +            $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); | 
                                                        |
| 195 | +  | 
                                                        |
| 196 | +            if (!$this->userManager->userExists($shareWith)) { | 
                                                        |
| 197 | +                throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); | 
                                                        |
| 198 | + }  | 
                                                        |
| 199 | +  | 
                                                        |
| 200 | + \OC_Util::setupFS($shareWith);  | 
                                                        |
| 201 | +  | 
                                                        |
| 202 | + $externalManager = new \OCA\Files_Sharing\External\Manager(  | 
                                                        |
| 203 | + \OC::$server->getDatabaseConnection(),  | 
                                                        |
| 204 | + Filesystem::getMountManager(),  | 
                                                        |
| 205 | + Filesystem::getLoader(),  | 
                                                        |
| 206 | + \OC::$server->getHTTPClientService(),  | 
                                                        |
| 207 | + \OC::$server->getNotificationManager(),  | 
                                                        |
| 208 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class),  | 
                                                        |
| 209 | + \OC::$server->getCloudFederationProviderManager(),  | 
                                                        |
| 210 | + \OC::$server->getCloudFederationFactory(),  | 
                                                        |
| 211 | + $shareWith  | 
                                                        |
| 212 | + );  | 
                                                        |
| 213 | +  | 
                                                        |
| 214 | +            try { | 
                                                        |
| 215 | + $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);  | 
                                                        |
| 216 | +                $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); | 
                                                        |
| 217 | +  | 
                                                        |
| 218 | + $event = $this->activityManager->generateEvent();  | 
                                                        |
| 219 | +                $event->setApp('files_sharing') | 
                                                        |
| 220 | +                    ->setType('remote_share') | 
                                                        |
| 221 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')])  | 
                                                        |
| 222 | + ->setAffectedUser($shareWith)  | 
                                                        |
| 223 | +                    ->setObject('remote_share', (int)$shareId, $name); | 
                                                        |
| 224 | + \OC::$server->getActivityManager()->publish($event);  | 
                                                        |
| 225 | +  | 
                                                        |
| 226 | + $notification = $this->notificationManager->createNotification();  | 
                                                        |
| 227 | +                $notification->setApp('files_sharing') | 
                                                        |
| 228 | + ->setUser($shareWith)  | 
                                                        |
| 229 | + ->setDateTime(new \DateTime())  | 
                                                        |
| 230 | +                    ->setObject('remote_share', $shareId) | 
                                                        |
| 231 | +                    ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); | 
                                                        |
| 232 | +  | 
                                                        |
| 233 | + $declineAction = $notification->createAction();  | 
                                                        |
| 234 | +                $declineAction->setLabel('decline') | 
                                                        |
| 235 | +                    ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); | 
                                                        |
| 236 | + $notification->addAction($declineAction);  | 
                                                        |
| 237 | +  | 
                                                        |
| 238 | + $acceptAction = $notification->createAction();  | 
                                                        |
| 239 | +                $acceptAction->setLabel('accept') | 
                                                        |
| 240 | +                    ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); | 
                                                        |
| 241 | + $notification->addAction($acceptAction);  | 
                                                        |
| 242 | +  | 
                                                        |
| 243 | + $this->notificationManager->notify($notification);  | 
                                                        |
| 244 | +  | 
                                                        |
| 245 | + return $shareId;  | 
                                                        |
| 246 | +            } catch (\Exception $e) { | 
                                                        |
| 247 | + $this->logger->logException($e, [  | 
                                                        |
| 248 | + 'message' => 'Server can not add remote share.',  | 
                                                        |
| 249 | + 'level' => ILogger::ERROR,  | 
                                                        |
| 250 | + 'app' => 'files_sharing'  | 
                                                        |
| 251 | + ]);  | 
                                                        |
| 252 | +                throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); | 
                                                        |
| 253 | + }  | 
                                                        |
| 254 | + }  | 
                                                        |
| 255 | +  | 
                                                        |
| 256 | +        throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST); | 
                                                        |
| 257 | +  | 
                                                        |
| 258 | + }  | 
                                                        |
| 259 | +  | 
                                                        |
| 260 | + /**  | 
                                                        |
| 261 | + * notification received from another server  | 
                                                        |
| 262 | + *  | 
                                                        |
| 263 | + * @param string $notificationType (e.g. SHARE_ACCEPTED)  | 
                                                        |
| 264 | + * @param string $providerId id of the share  | 
                                                        |
| 265 | + * @param array $notification payload of the notification  | 
                                                        |
| 266 | + * @return array data send back to the sender  | 
                                                        |
| 267 | + *  | 
                                                        |
| 268 | + * @throws ActionNotSupportedException  | 
                                                        |
| 269 | + * @throws AuthenticationFailedException  | 
                                                        |
| 270 | + * @throws BadRequestException  | 
                                                        |
| 271 | + * @throws \OC\HintException  | 
                                                        |
| 272 | + * @since 14.0.0  | 
                                                        |
| 273 | + */  | 
                                                        |
| 274 | +    public function notificationReceived($notificationType, $providerId, array $notification) { | 
                                                        |
| 275 | +  | 
                                                        |
| 276 | +        switch ($notificationType) { | 
                                                        |
| 277 | + case 'SHARE_ACCEPTED':  | 
                                                        |
| 278 | + return $this->shareAccepted($providerId, $notification);  | 
                                                        |
| 279 | + case 'SHARE_DECLINED':  | 
                                                        |
| 280 | + return $this->shareDeclined($providerId, $notification);  | 
                                                        |
| 281 | + case 'SHARE_UNSHARED':  | 
                                                        |
| 282 | + return $this->unshare($providerId, $notification);  | 
                                                        |
| 283 | + case 'REQUEST_RESHARE':  | 
                                                        |
| 284 | + return $this->reshareRequested($providerId, $notification);  | 
                                                        |
| 285 | + case 'RESHARE_UNDO':  | 
                                                        |
| 286 | + return $this->undoReshare($providerId, $notification);  | 
                                                        |
| 287 | + case 'RESHARE_CHANGE_PERMISSION':  | 
                                                        |
| 288 | + return $this->updateResharePermissions($providerId, $notification);  | 
                                                        |
| 289 | + }  | 
                                                        |
| 290 | +  | 
                                                        |
| 291 | +  | 
                                                        |
| 292 | + throw new BadRequestException([$notificationType]);  | 
                                                        |
| 293 | + }  | 
                                                        |
| 294 | +  | 
                                                        |
| 295 | + /**  | 
                                                        |
| 296 | + * process notification that the recipient accepted a share  | 
                                                        |
| 297 | + *  | 
                                                        |
| 298 | + * @param string $id  | 
                                                        |
| 299 | + * @param array $notification  | 
                                                        |
| 300 | + * @return array  | 
                                                        |
| 301 | + * @throws ActionNotSupportedException  | 
                                                        |
| 302 | + * @throws AuthenticationFailedException  | 
                                                        |
| 303 | + * @throws BadRequestException  | 
                                                        |
| 304 | + * @throws \OC\HintException  | 
                                                        |
| 305 | + */  | 
                                                        |
| 306 | +    private function shareAccepted($id, array $notification) { | 
                                                        |
| 307 | +  | 
                                                        |
| 308 | +        if (!$this->isS2SEnabled()) { | 
                                                        |
| 309 | +            throw new ActionNotSupportedException('Server does not support federated cloud sharing'); | 
                                                        |
| 310 | + }  | 
                                                        |
| 311 | +  | 
                                                        |
| 312 | +        if (!isset($notification['sharedSecret'])) { | 
                                                        |
| 313 | + throw new BadRequestException(['sharedSecret']);  | 
                                                        |
| 314 | + }  | 
                                                        |
| 315 | +  | 
                                                        |
| 316 | + $token = $notification['sharedSecret'];  | 
                                                        |
| 317 | +  | 
                                                        |
| 318 | + $share = $this->federatedShareProvider->getShareById($id);  | 
                                                        |
| 319 | +  | 
                                                        |
| 320 | + $this->verifyShare($share, $token);  | 
                                                        |
| 321 | + $this->executeAcceptShare($share);  | 
                                                        |
| 322 | +        if ($share->getShareOwner() !== $share->getSharedBy()) { | 
                                                        |
| 323 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());  | 
                                                        |
| 324 | + $remoteId = $this->federatedShareProvider->getRemoteId($share);  | 
                                                        |
| 325 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification();  | 
                                                        |
| 326 | + $notification->setMessage(  | 
                                                        |
| 327 | + 'SHARE_ACCEPTED',  | 
                                                        |
| 328 | + 'file',  | 
                                                        |
| 329 | + $remoteId,  | 
                                                        |
| 330 | + [  | 
                                                        |
| 331 | + 'sharedSecret' => $token,  | 
                                                        |
| 332 | + 'message' => 'Recipient accepted the re-share'  | 
                                                        |
| 333 | + ]  | 
                                                        |
| 334 | +  | 
                                                        |
| 335 | + );  | 
                                                        |
| 336 | + $this->cloudFederationProviderManager->sendNotification($remote, $notification);  | 
                                                        |
| 337 | +  | 
                                                        |
| 338 | + }  | 
                                                        |
| 339 | +  | 
                                                        |
| 340 | + return [];  | 
                                                        |
| 341 | + }  | 
                                                        |
| 342 | +  | 
                                                        |
| 343 | + /**  | 
                                                        |
| 344 | + * @param IShare $share  | 
                                                        |
| 345 | + * @throws ShareNotFound  | 
                                                        |
| 346 | + */  | 
                                                        |
| 347 | +    protected function executeAcceptShare(IShare $share) { | 
                                                        |
| 348 | +        try { | 
                                                        |
| 349 | + $fileId = (int)$share->getNode()->getId();  | 
                                                        |
| 350 | + list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);  | 
                                                        |
| 351 | +        } catch (\Exception $e) { | 
                                                        |
| 352 | + throw new ShareNotFound();  | 
                                                        |
| 353 | + }  | 
                                                        |
| 354 | +  | 
                                                        |
| 355 | + $event = $this->activityManager->generateEvent();  | 
                                                        |
| 356 | +        $event->setApp('files_sharing') | 
                                                        |
| 357 | +            ->setType('remote_share') | 
                                                        |
| 358 | + ->setAffectedUser($this->getCorrectUid($share))  | 
                                                        |
| 359 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]])  | 
                                                        |
| 360 | +            ->setObject('files', $fileId, $file) | 
                                                        |
| 361 | + ->setLink($link);  | 
                                                        |
| 362 | + $this->activityManager->publish($event);  | 
                                                        |
| 363 | + }  | 
                                                        |
| 364 | +  | 
                                                        |
| 365 | + /**  | 
                                                        |
| 366 | + * process notification that the recipient declined a share  | 
                                                        |
| 367 | + *  | 
                                                        |
| 368 | + * @param string $id  | 
                                                        |
| 369 | + * @param array $notification  | 
                                                        |
| 370 | + * @return array  | 
                                                        |
| 371 | + * @throws ActionNotSupportedException  | 
                                                        |
| 372 | + * @throws AuthenticationFailedException  | 
                                                        |
| 373 | + * @throws BadRequestException  | 
                                                        |
| 374 | + * @throws ShareNotFound  | 
                                                        |
| 375 | + * @throws \OC\HintException  | 
                                                        |
| 376 | + *  | 
                                                        |
| 377 | + */  | 
                                                        |
| 378 | +    protected function shareDeclined($id, array $notification) { | 
                                                        |
| 379 | +  | 
                                                        |
| 380 | +        if (!$this->isS2SEnabled()) { | 
                                                        |
| 381 | +            throw new ActionNotSupportedException('Server does not support federated cloud sharing'); | 
                                                        |
| 382 | + }  | 
                                                        |
| 383 | +  | 
                                                        |
| 384 | +        if (!isset($notification['sharedSecret'])) { | 
                                                        |
| 385 | + throw new BadRequestException(['sharedSecret']);  | 
                                                        |
| 386 | + }  | 
                                                        |
| 387 | +  | 
                                                        |
| 388 | + $token = $notification['sharedSecret'];  | 
                                                        |
| 389 | +  | 
                                                        |
| 390 | + $share = $this->federatedShareProvider->getShareById($id);  | 
                                                        |
| 391 | +  | 
                                                        |
| 392 | + $this->verifyShare($share, $token);  | 
                                                        |
| 393 | +  | 
                                                        |
| 394 | +        if ($share->getShareOwner() !== $share->getSharedBy()) { | 
                                                        |
| 395 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());  | 
                                                        |
| 396 | + $remoteId = $this->federatedShareProvider->getRemoteId($share);  | 
                                                        |
| 397 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification();  | 
                                                        |
| 398 | + $notification->setMessage(  | 
                                                        |
| 399 | + 'SHARE_DECLINED',  | 
                                                        |
| 400 | + 'file',  | 
                                                        |
| 401 | + $remoteId,  | 
                                                        |
| 402 | + [  | 
                                                        |
| 403 | + 'sharedSecret' => $token,  | 
                                                        |
| 404 | + 'message' => 'Recipient declined the re-share'  | 
                                                        |
| 405 | + ]  | 
                                                        |
| 406 | +  | 
                                                        |
| 407 | + );  | 
                                                        |
| 408 | + $this->cloudFederationProviderManager->sendNotification($remote, $notification);  | 
                                                        |
| 409 | + }  | 
                                                        |
| 410 | +  | 
                                                        |
| 411 | + $this->executeDeclineShare($share);  | 
                                                        |
| 412 | +  | 
                                                        |
| 413 | + return [];  | 
                                                        |
| 414 | +  | 
                                                        |
| 415 | + }  | 
                                                        |
| 416 | +  | 
                                                        |
| 417 | + /**  | 
                                                        |
| 418 | + * delete declined share and create a activity  | 
                                                        |
| 419 | + *  | 
                                                        |
| 420 | + * @param IShare $share  | 
                                                        |
| 421 | + * @throws ShareNotFound  | 
                                                        |
| 422 | + */  | 
                                                        |
| 423 | +    protected function executeDeclineShare(IShare $share) { | 
                                                        |
| 424 | + $this->federatedShareProvider->removeShareFromTable($share);  | 
                                                        |
| 425 | +  | 
                                                        |
| 426 | +        try { | 
                                                        |
| 427 | + $fileId = (int)$share->getNode()->getId();  | 
                                                        |
| 428 | + list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);  | 
                                                        |
| 429 | +        } catch (\Exception $e) { | 
                                                        |
| 430 | + throw new ShareNotFound();  | 
                                                        |
| 431 | + }  | 
                                                        |
| 432 | +  | 
                                                        |
| 433 | + $event = $this->activityManager->generateEvent();  | 
                                                        |
| 434 | +        $event->setApp('files_sharing') | 
                                                        |
| 435 | +            ->setType('remote_share') | 
                                                        |
| 436 | + ->setAffectedUser($this->getCorrectUid($share))  | 
                                                        |
| 437 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), [$fileId => $file]])  | 
                                                        |
| 438 | +            ->setObject('files', $fileId, $file) | 
                                                        |
| 439 | + ->setLink($link);  | 
                                                        |
| 440 | + $this->activityManager->publish($event);  | 
                                                        |
| 441 | +  | 
                                                        |
| 442 | + }  | 
                                                        |
| 443 | +  | 
                                                        |
| 444 | + /**  | 
                                                        |
| 445 | + * received the notification that the owner unshared a file from you  | 
                                                        |
| 446 | + *  | 
                                                        |
| 447 | + * @param string $id  | 
                                                        |
| 448 | + * @param array $notification  | 
                                                        |
| 449 | + * @return array  | 
                                                        |
| 450 | + * @throws AuthenticationFailedException  | 
                                                        |
| 451 | + * @throws BadRequestException  | 
                                                        |
| 452 | + */  | 
                                                        |
| 453 | +    private function undoReshare($id, array $notification) { | 
                                                        |
| 454 | +        if (!isset($notification['sharedSecret'])) { | 
                                                        |
| 455 | + throw new BadRequestException(['sharedSecret']);  | 
                                                        |
| 456 | + }  | 
                                                        |
| 457 | + $token = $notification['sharedSecret'];  | 
                                                        |
| 458 | +  | 
                                                        |
| 459 | + $share = $this->federatedShareProvider->getShareById($id);  | 
                                                        |
| 460 | +  | 
                                                        |
| 461 | + $this->verifyShare($share, $token);  | 
                                                        |
| 462 | + $this->federatedShareProvider->removeShareFromTable($share);  | 
                                                        |
| 463 | + return [];  | 
                                                        |
| 464 | + }  | 
                                                        |
| 465 | +  | 
                                                        |
| 466 | + /**  | 
                                                        |
| 467 | + * unshare file from self  | 
                                                        |
| 468 | + *  | 
                                                        |
| 469 | + * @param string $id  | 
                                                        |
| 470 | + * @param array $notification  | 
                                                        |
| 471 | + * @return array  | 
                                                        |
| 472 | + * @throws ActionNotSupportedException  | 
                                                        |
| 473 | + * @throws BadRequestException  | 
                                                        |
| 474 | + */  | 
                                                        |
| 475 | +    private function unshare($id, array $notification) { | 
                                                        |
| 476 | +  | 
                                                        |
| 477 | +        if (!$this->isS2SEnabled(true)) { | 
                                                        |
| 478 | +            throw new ActionNotSupportedException("incoming shares disabled!"); | 
                                                        |
| 479 | + }  | 
                                                        |
| 480 | +  | 
                                                        |
| 481 | +        if (!isset($notification['sharedSecret'])) { | 
                                                        |
| 482 | + throw new BadRequestException(['sharedSecret']);  | 
                                                        |
| 483 | + }  | 
                                                        |
| 484 | + $token = $notification['sharedSecret'];  | 
                                                        |
| 485 | +  | 
                                                        |
| 486 | + $qb = $this->connection->getQueryBuilder();  | 
                                                        |
| 487 | +        $qb->select('*') | 
                                                        |
| 488 | +            ->from('share_external') | 
                                                        |
| 489 | + ->where(  | 
                                                        |
| 490 | + $qb->expr()->andX(  | 
                                                        |
| 491 | +                    $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)), | 
                                                        |
| 492 | +                    $qb->expr()->eq('share_token', $qb->createNamedParameter($token)) | 
                                                        |
| 493 | + )  | 
                                                        |
| 494 | + );  | 
                                                        |
| 495 | +  | 
                                                        |
| 496 | + $result = $qb->execute();  | 
                                                        |
| 497 | + $share = $result->fetch();  | 
                                                        |
| 498 | + $result->closeCursor();  | 
                                                        |
| 499 | +  | 
                                                        |
| 500 | +        if ($token && $id && !empty($share)) { | 
                                                        |
| 501 | +  | 
                                                        |
| 502 | + $remote = $this->cleanupRemote($share['remote']);  | 
                                                        |
| 503 | +  | 
                                                        |
| 504 | + $owner = $this->cloudIdManager->getCloudId($share['owner'], $remote);  | 
                                                        |
| 505 | + $mountpoint = $share['mountpoint'];  | 
                                                        |
| 506 | + $user = $share['user'];  | 
                                                        |
| 507 | +  | 
                                                        |
| 508 | + $qb = $this->connection->getQueryBuilder();  | 
                                                        |
| 509 | +            $qb->delete('share_external') | 
                                                        |
| 510 | + ->where(  | 
                                                        |
| 511 | + $qb->expr()->andX(  | 
                                                        |
| 512 | +                        $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)), | 
                                                        |
| 513 | +                        $qb->expr()->eq('share_token', $qb->createNamedParameter($token)) | 
                                                        |
| 514 | + )  | 
                                                        |
| 515 | + );  | 
                                                        |
| 516 | +  | 
                                                        |
| 517 | + $qb->execute();  | 
                                                        |
| 518 | +  | 
                                                        |
| 519 | +            if ($share['accepted']) { | 
                                                        |
| 520 | + $path = trim($mountpoint, '/');  | 
                                                        |
| 521 | +            } else { | 
                                                        |
| 522 | + $path = trim($share['name'], '/');  | 
                                                        |
| 523 | + }  | 
                                                        |
| 524 | +  | 
                                                        |
| 525 | + $notification = $this->notificationManager->createNotification();  | 
                                                        |
| 526 | +            $notification->setApp('files_sharing') | 
                                                        |
| 527 | + ->setUser($share['user'])  | 
                                                        |
| 528 | +                ->setObject('remote_share', (int)$share['id']); | 
                                                        |
| 529 | + $this->notificationManager->markProcessed($notification);  | 
                                                        |
| 530 | +  | 
                                                        |
| 531 | + $event = $this->activityManager->generateEvent();  | 
                                                        |
| 532 | +            $event->setApp('files_sharing') | 
                                                        |
| 533 | +                ->setType('remote_share') | 
                                                        |
| 534 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path])  | 
                                                        |
| 535 | + ->setAffectedUser($user)  | 
                                                        |
| 536 | +                ->setObject('remote_share', (int)$share['id'], $path); | 
                                                        |
| 537 | + \OC::$server->getActivityManager()->publish($event);  | 
                                                        |
| 538 | + }  | 
                                                        |
| 539 | +  | 
                                                        |
| 540 | + return [];  | 
                                                        |
| 541 | + }  | 
                                                        |
| 542 | +  | 
                                                        |
| 543 | +    private function cleanupRemote($remote) { | 
                                                        |
| 544 | + $remote = substr($remote, strpos($remote, '://') + 3);  | 
                                                        |
| 545 | +  | 
                                                        |
| 546 | + return rtrim($remote, '/');  | 
                                                        |
| 547 | + }  | 
                                                        |
| 548 | +  | 
                                                        |
| 549 | + /**  | 
                                                        |
| 550 | + * recipient of a share request to re-share the file with another user  | 
                                                        |
| 551 | + *  | 
                                                        |
| 552 | + * @param string $id  | 
                                                        |
| 553 | + * @param array $notification  | 
                                                        |
| 554 | + * @return array  | 
                                                        |
| 555 | + * @throws AuthenticationFailedException  | 
                                                        |
| 556 | + * @throws BadRequestException  | 
                                                        |
| 557 | + * @throws ProviderCouldNotAddShareException  | 
                                                        |
| 558 | + * @throws ShareNotFound  | 
                                                        |
| 559 | + */  | 
                                                        |
| 560 | +    protected function reshareRequested($id, array $notification) { | 
                                                        |
| 561 | +  | 
                                                        |
| 562 | +        if (!isset($notification['sharedSecret'])) { | 
                                                        |
| 563 | + throw new BadRequestException(['sharedSecret']);  | 
                                                        |
| 564 | + }  | 
                                                        |
| 565 | + $token = $notification['sharedSecret'];  | 
                                                        |
| 566 | +  | 
                                                        |
| 567 | +        if (!isset($notification['shareWith'])) { | 
                                                        |
| 568 | + throw new BadRequestException(['shareWith']);  | 
                                                        |
| 569 | + }  | 
                                                        |
| 570 | + $shareWith = $notification['shareWith'];  | 
                                                        |
| 571 | +  | 
                                                        |
| 572 | +        if (!isset($notification['senderId'])) { | 
                                                        |
| 573 | + throw new BadRequestException(['senderId']);  | 
                                                        |
| 574 | + }  | 
                                                        |
| 575 | + $senderId = $notification['senderId'];  | 
                                                        |
| 576 | +  | 
                                                        |
| 577 | + $share = $this->federatedShareProvider->getShareById($id);  | 
                                                        |
| 578 | + // don't allow to share a file back to the owner  | 
                                                        |
| 579 | +        try { | 
                                                        |
| 580 | + list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);  | 
                                                        |
| 581 | + $owner = $share->getShareOwner();  | 
                                                        |
| 582 | + $currentServer = $this->addressHandler->generateRemoteURL();  | 
                                                        |
| 583 | +            if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) { | 
                                                        |
| 584 | +                throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id); | 
                                                        |
| 585 | + }  | 
                                                        |
| 586 | +        } catch (\Exception $e) { | 
                                                        |
| 587 | + throw new ProviderCouldNotAddShareException($e->getMessage());  | 
                                                        |
| 588 | + }  | 
                                                        |
| 589 | +  | 
                                                        |
| 590 | + $this->verifyShare($share, $token);  | 
                                                        |
| 591 | +  | 
                                                        |
| 592 | + // check if re-sharing is allowed  | 
                                                        |
| 593 | +        if ($share->getPermissions() & Constants::PERMISSION_SHARE) { | 
                                                        |
| 594 | + // the recipient of the initial share is now the initiator for the re-share  | 
                                                        |
| 595 | + $share->setSharedBy($share->getSharedWith());  | 
                                                        |
| 596 | + $share->setSharedWith($shareWith);  | 
                                                        |
| 597 | + $result = $this->federatedShareProvider->create($share);  | 
                                                        |
| 598 | + $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId);  | 
                                                        |
| 599 | + return ['token' => $result->getToken(), 'providerId' => $result->getId()];  | 
                                                        |
| 600 | +        } else { | 
                                                        |
| 601 | +            throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id); | 
                                                        |
| 602 | + }  | 
                                                        |
| 603 | +  | 
                                                        |
| 604 | + }  | 
                                                        |
| 605 | +  | 
                                                        |
| 606 | + /**  | 
                                                        |
| 607 | + * update permission of a re-share so that the share dialog shows the right  | 
                                                        |
| 608 | + * permission if the owner or the sender changes the permission  | 
                                                        |
| 609 | + *  | 
                                                        |
| 610 | + * @param string $id  | 
                                                        |
| 611 | + * @param array $notification  | 
                                                        |
| 612 | + * @return array  | 
                                                        |
| 613 | + * @throws AuthenticationFailedException  | 
                                                        |
| 614 | + * @throws BadRequestException  | 
                                                        |
| 615 | + */  | 
                                                        |
| 616 | +    protected function updateResharePermissions($id, array $notification) { | 
                                                        |
| 617 | +  | 
                                                        |
| 618 | +        if (!isset($notification['sharedSecret'])) { | 
                                                        |
| 619 | + throw new BadRequestException(['sharedSecret']);  | 
                                                        |
| 620 | + }  | 
                                                        |
| 621 | + $token = $notification['sharedSecret'];  | 
                                                        |
| 622 | +  | 
                                                        |
| 623 | +        if (!isset($notification['permission'])) { | 
                                                        |
| 624 | + throw new BadRequestException(['permission']);  | 
                                                        |
| 625 | + }  | 
                                                        |
| 626 | + $ocmPermissions = $notification['permission'];  | 
                                                        |
| 627 | +  | 
                                                        |
| 628 | + $share = $this->federatedShareProvider->getShareById($id);  | 
                                                        |
| 629 | +  | 
                                                        |
| 630 | + $ncPermission = $this->ocmPermissions2ncPermissions($ocmPermissions);  | 
                                                        |
| 631 | +  | 
                                                        |
| 632 | + $this->verifyShare($share, $token);  | 
                                                        |
| 633 | + $this->updatePermissionsInDatabase($share, $ncPermission);  | 
                                                        |
| 634 | +  | 
                                                        |
| 635 | + return [];  | 
                                                        |
| 636 | + }  | 
                                                        |
| 637 | +  | 
                                                        |
| 638 | + /**  | 
                                                        |
| 639 | + * translate OCM Permissions to Nextcloud permissions  | 
                                                        |
| 640 | + *  | 
                                                        |
| 641 | + * @param array $ocmPermissions  | 
                                                        |
| 642 | + * @return int  | 
                                                        |
| 643 | + * @throws BadRequestException  | 
                                                        |
| 644 | + */  | 
                                                        |
| 645 | +    protected function ocmPermissions2ncPermissions(array $ocmPermissions) { | 
                                                        |
| 646 | + $ncPermissions = 0;  | 
                                                        |
| 647 | +        foreach($ocmPermissions as $permission) { | 
                                                        |
| 648 | +            switch (strtolower($permission)) { | 
                                                        |
| 649 | + case 'read':  | 
                                                        |
| 650 | + $ncPermissions += Constants::PERMISSION_READ;  | 
                                                        |
| 651 | + break;  | 
                                                        |
| 652 | + case 'write':  | 
                                                        |
| 653 | + $ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE;  | 
                                                        |
| 654 | + break;  | 
                                                        |
| 655 | + case 'share':  | 
                                                        |
| 656 | + $ncPermissions += Constants::PERMISSION_SHARE;  | 
                                                        |
| 657 | + break;  | 
                                                        |
| 658 | + default:  | 
                                                        |
| 659 | + throw new BadRequestException(['permission']);  | 
                                                        |
| 660 | + }  | 
                                                        |
| 661 | +  | 
                                                        |
| 662 | +            error_log("new permissions: " . $ncPermissions); | 
                                                        |
| 663 | + }  | 
                                                        |
| 664 | +  | 
                                                        |
| 665 | + return $ncPermissions;  | 
                                                        |
| 666 | + }  | 
                                                        |
| 667 | +  | 
                                                        |
| 668 | + /**  | 
                                                        |
| 669 | + * update permissions in database  | 
                                                        |
| 670 | + *  | 
                                                        |
| 671 | + * @param IShare $share  | 
                                                        |
| 672 | + * @param int $permissions  | 
                                                        |
| 673 | + */  | 
                                                        |
| 674 | +    protected function updatePermissionsInDatabase(IShare $share, $permissions) { | 
                                                        |
| 675 | + $query = $this->connection->getQueryBuilder();  | 
                                                        |
| 676 | +        $query->update('share') | 
                                                        |
| 677 | +            ->where($query->expr()->eq('id', $query->createNamedParameter($share->getId()))) | 
                                                        |
| 678 | +            ->set('permissions', $query->createNamedParameter($permissions)) | 
                                                        |
| 679 | + ->execute();  | 
                                                        |
| 680 | + }  | 
                                                        |
| 681 | +  | 
                                                        |
| 682 | +  | 
                                                        |
| 683 | + /**  | 
                                                        |
| 684 | + * get file  | 
                                                        |
| 685 | + *  | 
                                                        |
| 686 | + * @param string $user  | 
                                                        |
| 687 | + * @param int $fileSource  | 
                                                        |
| 688 | + * @return array with internal path of the file and a absolute link to it  | 
                                                        |
| 689 | + */  | 
                                                        |
| 690 | +    private function getFile($user, $fileSource) { | 
                                                        |
| 691 | + \OC_Util::setupFS($user);  | 
                                                        |
| 692 | +  | 
                                                        |
| 693 | +        try { | 
                                                        |
| 694 | + $file = Filesystem::getPath($fileSource);  | 
                                                        |
| 695 | +        } catch (NotFoundException $e) { | 
                                                        |
| 696 | + $file = null;  | 
                                                        |
| 697 | + }  | 
                                                        |
| 698 | +        $args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); | 
                                                        |
| 699 | +        $link = Util::linkToAbsolute('files', 'index.php', $args); | 
                                                        |
| 700 | +  | 
                                                        |
| 701 | + return [$file, $link];  | 
                                                        |
| 702 | +  | 
                                                        |
| 703 | + }  | 
                                                        |
| 704 | +  | 
                                                        |
| 705 | + /**  | 
                                                        |
| 706 | + * check if we are the initiator or the owner of a re-share and return the correct UID  | 
                                                        |
| 707 | + *  | 
                                                        |
| 708 | + * @param IShare $share  | 
                                                        |
| 709 | + * @return string  | 
                                                        |
| 710 | + */  | 
                                                        |
| 711 | +    protected function getCorrectUid(IShare $share) { | 
                                                        |
| 712 | +        if ($this->userManager->userExists($share->getShareOwner())) { | 
                                                        |
| 713 | + return $share->getShareOwner();  | 
                                                        |
| 714 | + }  | 
                                                        |
| 715 | +  | 
                                                        |
| 716 | + return $share->getSharedBy();  | 
                                                        |
| 717 | + }  | 
                                                        |
| 718 | +  | 
                                                        |
| 719 | +  | 
                                                        |
| 720 | +  | 
                                                        |
| 721 | + /**  | 
                                                        |
| 722 | + * check if we got the right share  | 
                                                        |
| 723 | + *  | 
                                                        |
| 724 | + * @param IShare $share  | 
                                                        |
| 725 | + * @param string $token  | 
                                                        |
| 726 | + * @return bool  | 
                                                        |
| 727 | + * @throws AuthenticationFailedException  | 
                                                        |
| 728 | + */  | 
                                                        |
| 729 | +    protected function verifyShare(IShare $share, $token) { | 
                                                        |
| 730 | + if (  | 
                                                        |
| 731 | + $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE &&  | 
                                                        |
| 732 | + $share->getToken() === $token  | 
                                                        |
| 733 | +        ) { | 
                                                        |
| 734 | + return true;  | 
                                                        |
| 735 | + }  | 
                                                        |
| 736 | +  | 
                                                        |
| 737 | + throw new AuthenticationFailedException();  | 
                                                        |
| 738 | + }  | 
                                                        |
| 739 | +  | 
                                                        |
| 740 | +  | 
                                                        |
| 741 | +  | 
                                                        |
| 742 | + /**  | 
                                                        |
| 743 | + * check if server-to-server sharing is enabled  | 
                                                        |
| 744 | + *  | 
                                                        |
| 745 | + * @param bool $incoming  | 
                                                        |
| 746 | + * @return bool  | 
                                                        |
| 747 | + */  | 
                                                        |
| 748 | +    private function isS2SEnabled($incoming = false) { | 
                                                        |
| 749 | +  | 
                                                        |
| 750 | +        $result = $this->appManager->isEnabledForUser('files_sharing'); | 
                                                        |
| 751 | +  | 
                                                        |
| 752 | +        if ($incoming) { | 
                                                        |
| 753 | + $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled();  | 
                                                        |
| 754 | +        } else { | 
                                                        |
| 755 | + $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();  | 
                                                        |
| 756 | + }  | 
                                                        |
| 757 | +  | 
                                                        |
| 758 | + return $result;  | 
                                                        |
| 759 | + }  | 
                                                        |
| 760 | 760 | |
| 761 | 761 | |
| 762 | 762 | }  | 
                                                        
@@ -185,16 +185,16 @@ discard block  | 
                                                    ||
| 185 | 185 | }  | 
                                                        
| 186 | 186 | |
| 187 | 187 | // FIXME this should be a method in the user management instead  | 
                                                        
| 188 | -			$this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); | 
                                                        |
| 188 | +			$this->logger->debug('shareWith before, '.$shareWith, ['app' => 'files_sharing']); | 
                                                        |
| 189 | 189 | Util::emitHook(  | 
                                                        
| 190 | 190 | '\OCA\Files_Sharing\API\Server2Server',  | 
                                                        
| 191 | 191 | 'preLoginNameUsedAsUserName',  | 
                                                        
| 192 | 192 |  				array('uid' => &$shareWith) | 
                                                        
| 193 | 193 | );  | 
                                                        
| 194 | -			$this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); | 
                                                        |
| 194 | +			$this->logger->debug('shareWith after, '.$shareWith, ['app' => 'files_sharing']); | 
                                                        |
| 195 | 195 | |
| 196 | 196 |  			if (!$this->userManager->userExists($shareWith)) { | 
                                                        
| 197 | -				throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); | 
                                                        |
| 197 | +				throw new ProviderCouldNotAddShareException('User does not exists', '', Http::STATUS_BAD_REQUEST); | 
                                                        |
| 198 | 198 | }  | 
                                                        
| 199 | 199 | |
| 200 | 200 | \OC_Util::setupFS($shareWith);  | 
                                                        
@@ -220,7 +220,7 @@ discard block  | 
                                                    ||
| 220 | 220 |  					->setType('remote_share') | 
                                                        
| 221 | 221 | ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')])  | 
                                                        
| 222 | 222 | ->setAffectedUser($shareWith)  | 
                                                        
| 223 | -					->setObject('remote_share', (int)$shareId, $name); | 
                                                        |
| 223 | +					->setObject('remote_share', (int) $shareId, $name); | 
                                                        |
| 224 | 224 | \OC::$server->getActivityManager()->publish($event);  | 
                                                        
| 225 | 225 | |
| 226 | 226 | $notification = $this->notificationManager->createNotification();  | 
                                                        
@@ -232,12 +232,12 @@ discard block  | 
                                                    ||
| 232 | 232 | |
| 233 | 233 | $declineAction = $notification->createAction();  | 
                                                        
| 234 | 234 |  				$declineAction->setLabel('decline') | 
                                                        
| 235 | -					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); | 
                                                        |
| 235 | +					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/'.$shareId)), 'DELETE'); | 
                                                        |
| 236 | 236 | $notification->addAction($declineAction);  | 
                                                        
| 237 | 237 | |
| 238 | 238 | $acceptAction = $notification->createAction();  | 
                                                        
| 239 | 239 |  				$acceptAction->setLabel('accept') | 
                                                        
| 240 | -					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); | 
                                                        |
| 240 | +					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/'.$shareId)), 'POST'); | 
                                                        |
| 241 | 241 | $notification->addAction($acceptAction);  | 
                                                        
| 242 | 242 | |
| 243 | 243 | $this->notificationManager->notify($notification);  | 
                                                        
@@ -249,7 +249,7 @@ discard block  | 
                                                    ||
| 249 | 249 | 'level' => ILogger::ERROR,  | 
                                                        
| 250 | 250 | 'app' => 'files_sharing'  | 
                                                        
| 251 | 251 | ]);  | 
                                                        
| 252 | -				throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); | 
                                                        |
| 252 | +				throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from '.$remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); | 
                                                        |
| 253 | 253 | }  | 
                                                        
| 254 | 254 | }  | 
                                                        
| 255 | 255 | |
@@ -346,7 +346,7 @@ discard block  | 
                                                    ||
| 346 | 346 | */  | 
                                                        
| 347 | 347 |  	protected function executeAcceptShare(IShare $share) { | 
                                                        
| 348 | 348 |  		try { | 
                                                        
| 349 | - $fileId = (int)$share->getNode()->getId();  | 
                                                        |
| 349 | + $fileId = (int) $share->getNode()->getId();  | 
                                                        |
| 350 | 350 | list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);  | 
                                                        
| 351 | 351 |  		} catch (\Exception $e) { | 
                                                        
| 352 | 352 | throw new ShareNotFound();  | 
                                                        
@@ -424,7 +424,7 @@ discard block  | 
                                                    ||
| 424 | 424 | $this->federatedShareProvider->removeShareFromTable($share);  | 
                                                        
| 425 | 425 | |
| 426 | 426 |  		try { | 
                                                        
| 427 | - $fileId = (int)$share->getNode()->getId();  | 
                                                        |
| 427 | + $fileId = (int) $share->getNode()->getId();  | 
                                                        |
| 428 | 428 | list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);  | 
                                                        
| 429 | 429 |  		} catch (\Exception $e) { | 
                                                        
| 430 | 430 | throw new ShareNotFound();  | 
                                                        
@@ -525,7 +525,7 @@ discard block  | 
                                                    ||
| 525 | 525 | $notification = $this->notificationManager->createNotification();  | 
                                                        
| 526 | 526 |  			$notification->setApp('files_sharing') | 
                                                        
| 527 | 527 | ->setUser($share['user'])  | 
                                                        
| 528 | -				->setObject('remote_share', (int)$share['id']); | 
                                                        |
| 528 | +				->setObject('remote_share', (int) $share['id']); | 
                                                        |
| 529 | 529 | $this->notificationManager->markProcessed($notification);  | 
                                                        
| 530 | 530 | |
| 531 | 531 | $event = $this->activityManager->generateEvent();  | 
                                                        
@@ -533,7 +533,7 @@ discard block  | 
                                                    ||
| 533 | 533 |  				->setType('remote_share') | 
                                                        
| 534 | 534 | ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path])  | 
                                                        
| 535 | 535 | ->setAffectedUser($user)  | 
                                                        
| 536 | -				->setObject('remote_share', (int)$share['id'], $path); | 
                                                        |
| 536 | +				->setObject('remote_share', (int) $share['id'], $path); | 
                                                        |
| 537 | 537 | \OC::$server->getActivityManager()->publish($event);  | 
                                                        
| 538 | 538 | }  | 
                                                        
| 539 | 539 | |
@@ -581,7 +581,7 @@ discard block  | 
                                                    ||
| 581 | 581 | $owner = $share->getShareOwner();  | 
                                                        
| 582 | 582 | $currentServer = $this->addressHandler->generateRemoteURL();  | 
                                                        
| 583 | 583 |  			if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) { | 
                                                        
| 584 | -				throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id); | 
                                                        |
| 584 | +				throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: '.$id); | 
                                                        |
| 585 | 585 | }  | 
                                                        
| 586 | 586 |  		} catch (\Exception $e) { | 
                                                        
| 587 | 587 | throw new ProviderCouldNotAddShareException($e->getMessage());  | 
                                                        
@@ -595,10 +595,10 @@ discard block  | 
                                                    ||
| 595 | 595 | $share->setSharedBy($share->getSharedWith());  | 
                                                        
| 596 | 596 | $share->setSharedWith($shareWith);  | 
                                                        
| 597 | 597 | $result = $this->federatedShareProvider->create($share);  | 
                                                        
| 598 | - $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId);  | 
                                                        |
| 598 | + $this->federatedShareProvider->storeRemoteId((int) $result->getId(), $senderId);  | 
                                                        |
| 599 | 599 | return ['token' => $result->getToken(), 'providerId' => $result->getId()];  | 
                                                        
| 600 | 600 |  		} else { | 
                                                        
| 601 | -			throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id); | 
                                                        |
| 601 | +			throw new ProviderCouldNotAddShareException('resharing not allowed for share: '.$id); | 
                                                        |
| 602 | 602 | }  | 
                                                        
| 603 | 603 | |
| 604 | 604 | }  | 
                                                        
@@ -644,7 +644,7 @@ discard block  | 
                                                    ||
| 644 | 644 | */  | 
                                                        
| 645 | 645 |  	protected function ocmPermissions2ncPermissions(array $ocmPermissions) { | 
                                                        
| 646 | 646 | $ncPermissions = 0;  | 
                                                        
| 647 | -		foreach($ocmPermissions as $permission) { | 
                                                        |
| 647 | +		foreach ($ocmPermissions as $permission) { | 
                                                        |
| 648 | 648 |  			switch (strtolower($permission)) { | 
                                                        
| 649 | 649 | case 'read':  | 
                                                        
| 650 | 650 | $ncPermissions += Constants::PERMISSION_READ;  | 
                                                        
@@ -659,7 +659,7 @@ discard block  | 
                                                    ||
| 659 | 659 | throw new BadRequestException(['permission']);  | 
                                                        
| 660 | 660 | }  | 
                                                        
| 661 | 661 | |
| 662 | -			error_log("new permissions: " . $ncPermissions); | 
                                                        |
| 662 | +			error_log("new permissions: ".$ncPermissions); | 
                                                        |
| 663 | 663 | }  | 
                                                        
| 664 | 664 | |
| 665 | 665 | return $ncPermissions;  | 
                                                        
@@ -32,7 +32,6 @@  | 
                                                    ||
| 32 | 32 | use OCA\FederatedFileSharing\AddressHandler;  | 
                                                        
| 33 | 33 | use OCA\FederatedFileSharing\FederatedShareProvider;  | 
                                                        
| 34 | 34 | use OCA\FederatedFileSharing\Notifications;  | 
                                                        
| 35 | -use OCA\FederatedFileSharing\OCM\CloudFederationProvider;  | 
                                                        |
| 36 | 35 | use OCA\FederatedFileSharing\TokenHandler;  | 
                                                        
| 37 | 36 | use OCA\ShareByMail\Settings\SettingsManager;  | 
                                                        
| 38 | 37 | use OCA\ShareByMail\ShareByMailProvider;  | 
                                                        
@@ -48,235 +48,235 @@  | 
                                                    ||
| 48 | 48 | */  | 
                                                        
| 49 | 49 |  class ProviderFactory implements IProviderFactory { | 
                                                        
| 50 | 50 | |
| 51 | - /** @var IServerContainer */  | 
                                                        |
| 52 | - private $serverContainer;  | 
                                                        |
| 53 | - /** @var DefaultShareProvider */  | 
                                                        |
| 54 | - private $defaultProvider = null;  | 
                                                        |
| 55 | - /** @var FederatedShareProvider */  | 
                                                        |
| 56 | - private $federatedProvider = null;  | 
                                                        |
| 57 | - /** @var ShareByMailProvider */  | 
                                                        |
| 58 | - private $shareByMailProvider;  | 
                                                        |
| 59 | - /** @var \OCA\Circles\ShareByCircleProvider */  | 
                                                        |
| 60 | - private $shareByCircleProvider = null;  | 
                                                        |
| 61 | - /** @var bool */  | 
                                                        |
| 62 | - private $circlesAreNotAvailable = false;  | 
                                                        |
| 63 | -  | 
                                                        |
| 64 | - /**  | 
                                                        |
| 65 | - * IProviderFactory constructor.  | 
                                                        |
| 66 | - *  | 
                                                        |
| 67 | - * @param IServerContainer $serverContainer  | 
                                                        |
| 68 | - */  | 
                                                        |
| 69 | -	public function __construct(IServerContainer $serverContainer) { | 
                                                        |
| 70 | - $this->serverContainer = $serverContainer;  | 
                                                        |
| 71 | - }  | 
                                                        |
| 72 | -  | 
                                                        |
| 73 | - /**  | 
                                                        |
| 74 | - * Create the default share provider.  | 
                                                        |
| 75 | - *  | 
                                                        |
| 76 | - * @return DefaultShareProvider  | 
                                                        |
| 77 | - */  | 
                                                        |
| 78 | -	protected function defaultShareProvider() { | 
                                                        |
| 79 | -		if ($this->defaultProvider === null) { | 
                                                        |
| 80 | - $this->defaultProvider = new DefaultShareProvider(  | 
                                                        |
| 81 | - $this->serverContainer->getDatabaseConnection(),  | 
                                                        |
| 82 | - $this->serverContainer->getUserManager(),  | 
                                                        |
| 83 | - $this->serverContainer->getGroupManager(),  | 
                                                        |
| 84 | - $this->serverContainer->getLazyRootFolder()  | 
                                                        |
| 85 | - );  | 
                                                        |
| 86 | - }  | 
                                                        |
| 87 | -  | 
                                                        |
| 88 | - return $this->defaultProvider;  | 
                                                        |
| 89 | - }  | 
                                                        |
| 90 | -  | 
                                                        |
| 91 | - /**  | 
                                                        |
| 92 | - * Create the federated share provider  | 
                                                        |
| 93 | - *  | 
                                                        |
| 94 | - * @return FederatedShareProvider  | 
                                                        |
| 95 | - */  | 
                                                        |
| 96 | -	protected function federatedShareProvider() { | 
                                                        |
| 97 | -		if ($this->federatedProvider === null) { | 
                                                        |
| 98 | - /*  | 
                                                        |
| 51 | + /** @var IServerContainer */  | 
                                                        |
| 52 | + private $serverContainer;  | 
                                                        |
| 53 | + /** @var DefaultShareProvider */  | 
                                                        |
| 54 | + private $defaultProvider = null;  | 
                                                        |
| 55 | + /** @var FederatedShareProvider */  | 
                                                        |
| 56 | + private $federatedProvider = null;  | 
                                                        |
| 57 | + /** @var ShareByMailProvider */  | 
                                                        |
| 58 | + private $shareByMailProvider;  | 
                                                        |
| 59 | + /** @var \OCA\Circles\ShareByCircleProvider */  | 
                                                        |
| 60 | + private $shareByCircleProvider = null;  | 
                                                        |
| 61 | + /** @var bool */  | 
                                                        |
| 62 | + private $circlesAreNotAvailable = false;  | 
                                                        |
| 63 | +  | 
                                                        |
| 64 | + /**  | 
                                                        |
| 65 | + * IProviderFactory constructor.  | 
                                                        |
| 66 | + *  | 
                                                        |
| 67 | + * @param IServerContainer $serverContainer  | 
                                                        |
| 68 | + */  | 
                                                        |
| 69 | +    public function __construct(IServerContainer $serverContainer) { | 
                                                        |
| 70 | + $this->serverContainer = $serverContainer;  | 
                                                        |
| 71 | + }  | 
                                                        |
| 72 | +  | 
                                                        |
| 73 | + /**  | 
                                                        |
| 74 | + * Create the default share provider.  | 
                                                        |
| 75 | + *  | 
                                                        |
| 76 | + * @return DefaultShareProvider  | 
                                                        |
| 77 | + */  | 
                                                        |
| 78 | +    protected function defaultShareProvider() { | 
                                                        |
| 79 | +        if ($this->defaultProvider === null) { | 
                                                        |
| 80 | + $this->defaultProvider = new DefaultShareProvider(  | 
                                                        |
| 81 | + $this->serverContainer->getDatabaseConnection(),  | 
                                                        |
| 82 | + $this->serverContainer->getUserManager(),  | 
                                                        |
| 83 | + $this->serverContainer->getGroupManager(),  | 
                                                        |
| 84 | + $this->serverContainer->getLazyRootFolder()  | 
                                                        |
| 85 | + );  | 
                                                        |
| 86 | + }  | 
                                                        |
| 87 | +  | 
                                                        |
| 88 | + return $this->defaultProvider;  | 
                                                        |
| 89 | + }  | 
                                                        |
| 90 | +  | 
                                                        |
| 91 | + /**  | 
                                                        |
| 92 | + * Create the federated share provider  | 
                                                        |
| 93 | + *  | 
                                                        |
| 94 | + * @return FederatedShareProvider  | 
                                                        |
| 95 | + */  | 
                                                        |
| 96 | +    protected function federatedShareProvider() { | 
                                                        |
| 97 | +        if ($this->federatedProvider === null) { | 
                                                        |
| 98 | + /*  | 
                                                        |
| 99 | 99 | * Check if the app is enabled  | 
                                                        
| 100 | 100 | */  | 
                                                        
| 101 | - $appManager = $this->serverContainer->getAppManager();  | 
                                                        |
| 102 | -			if (!$appManager->isEnabledForUser('federatedfilesharing')) { | 
                                                        |
| 103 | - return null;  | 
                                                        |
| 104 | - }  | 
                                                        |
| 101 | + $appManager = $this->serverContainer->getAppManager();  | 
                                                        |
| 102 | +            if (!$appManager->isEnabledForUser('federatedfilesharing')) { | 
                                                        |
| 103 | + return null;  | 
                                                        |
| 104 | + }  | 
                                                        |
| 105 | 105 | |
| 106 | - /*  | 
                                                        |
| 106 | + /*  | 
                                                        |
| 107 | 107 | * TODO: add factory to federated sharing app  | 
                                                        
| 108 | 108 | */  | 
                                                        
| 109 | -			$l = $this->serverContainer->getL10N('federatedfilessharing'); | 
                                                        |
| 110 | - $addressHandler = new AddressHandler(  | 
                                                        |
| 111 | - $this->serverContainer->getURLGenerator(),  | 
                                                        |
| 112 | - $l,  | 
                                                        |
| 113 | - $this->serverContainer->getCloudIdManager()  | 
                                                        |
| 114 | - );  | 
                                                        |
| 115 | - $notifications = new Notifications(  | 
                                                        |
| 116 | - $addressHandler,  | 
                                                        |
| 117 | - $this->serverContainer->getHTTPClientService(),  | 
                                                        |
| 118 | - $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class),  | 
                                                        |
| 119 | - $this->serverContainer->getJobList(),  | 
                                                        |
| 120 | - \OC::$server->getCloudFederationProviderManager(),  | 
                                                        |
| 121 | - \OC::$server->getCloudFederationFactory()  | 
                                                        |
| 122 | - );  | 
                                                        |
| 123 | - $tokenHandler = new TokenHandler(  | 
                                                        |
| 124 | - $this->serverContainer->getSecureRandom()  | 
                                                        |
| 125 | - );  | 
                                                        |
| 126 | -  | 
                                                        |
| 127 | - $this->federatedProvider = new FederatedShareProvider(  | 
                                                        |
| 128 | - $this->serverContainer->getDatabaseConnection(),  | 
                                                        |
| 129 | - $addressHandler,  | 
                                                        |
| 130 | - $notifications,  | 
                                                        |
| 131 | - $tokenHandler,  | 
                                                        |
| 132 | - $l,  | 
                                                        |
| 133 | - $this->serverContainer->getLogger(),  | 
                                                        |
| 134 | - $this->serverContainer->getLazyRootFolder(),  | 
                                                        |
| 135 | - $this->serverContainer->getConfig(),  | 
                                                        |
| 136 | - $this->serverContainer->getUserManager(),  | 
                                                        |
| 137 | - $this->serverContainer->getCloudIdManager(),  | 
                                                        |
| 138 | - $this->serverContainer->getGlobalScaleConfig()  | 
                                                        |
| 139 | - );  | 
                                                        |
| 140 | - }  | 
                                                        |
| 141 | -  | 
                                                        |
| 142 | - return $this->federatedProvider;  | 
                                                        |
| 143 | - }  | 
                                                        |
| 144 | -  | 
                                                        |
| 145 | - /**  | 
                                                        |
| 146 | - * Create the federated share provider  | 
                                                        |
| 147 | - *  | 
                                                        |
| 148 | - * @return ShareByMailProvider  | 
                                                        |
| 149 | - */  | 
                                                        |
| 150 | -	protected function getShareByMailProvider() { | 
                                                        |
| 151 | -		if ($this->shareByMailProvider === null) { | 
                                                        |
| 152 | - /*  | 
                                                        |
| 109 | +            $l = $this->serverContainer->getL10N('federatedfilessharing'); | 
                                                        |
| 110 | + $addressHandler = new AddressHandler(  | 
                                                        |
| 111 | + $this->serverContainer->getURLGenerator(),  | 
                                                        |
| 112 | + $l,  | 
                                                        |
| 113 | + $this->serverContainer->getCloudIdManager()  | 
                                                        |
| 114 | + );  | 
                                                        |
| 115 | + $notifications = new Notifications(  | 
                                                        |
| 116 | + $addressHandler,  | 
                                                        |
| 117 | + $this->serverContainer->getHTTPClientService(),  | 
                                                        |
| 118 | + $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class),  | 
                                                        |
| 119 | + $this->serverContainer->getJobList(),  | 
                                                        |
| 120 | + \OC::$server->getCloudFederationProviderManager(),  | 
                                                        |
| 121 | + \OC::$server->getCloudFederationFactory()  | 
                                                        |
| 122 | + );  | 
                                                        |
| 123 | + $tokenHandler = new TokenHandler(  | 
                                                        |
| 124 | + $this->serverContainer->getSecureRandom()  | 
                                                        |
| 125 | + );  | 
                                                        |
| 126 | +  | 
                                                        |
| 127 | + $this->federatedProvider = new FederatedShareProvider(  | 
                                                        |
| 128 | + $this->serverContainer->getDatabaseConnection(),  | 
                                                        |
| 129 | + $addressHandler,  | 
                                                        |
| 130 | + $notifications,  | 
                                                        |
| 131 | + $tokenHandler,  | 
                                                        |
| 132 | + $l,  | 
                                                        |
| 133 | + $this->serverContainer->getLogger(),  | 
                                                        |
| 134 | + $this->serverContainer->getLazyRootFolder(),  | 
                                                        |
| 135 | + $this->serverContainer->getConfig(),  | 
                                                        |
| 136 | + $this->serverContainer->getUserManager(),  | 
                                                        |
| 137 | + $this->serverContainer->getCloudIdManager(),  | 
                                                        |
| 138 | + $this->serverContainer->getGlobalScaleConfig()  | 
                                                        |
| 139 | + );  | 
                                                        |
| 140 | + }  | 
                                                        |
| 141 | +  | 
                                                        |
| 142 | + return $this->federatedProvider;  | 
                                                        |
| 143 | + }  | 
                                                        |
| 144 | +  | 
                                                        |
| 145 | + /**  | 
                                                        |
| 146 | + * Create the federated share provider  | 
                                                        |
| 147 | + *  | 
                                                        |
| 148 | + * @return ShareByMailProvider  | 
                                                        |
| 149 | + */  | 
                                                        |
| 150 | +    protected function getShareByMailProvider() { | 
                                                        |
| 151 | +        if ($this->shareByMailProvider === null) { | 
                                                        |
| 152 | + /*  | 
                                                        |
| 153 | 153 | * Check if the app is enabled  | 
                                                        
| 154 | 154 | */  | 
                                                        
| 155 | - $appManager = $this->serverContainer->getAppManager();  | 
                                                        |
| 156 | -			if (!$appManager->isEnabledForUser('sharebymail')) { | 
                                                        |
| 157 | - return null;  | 
                                                        |
| 158 | - }  | 
                                                        |
| 159 | -  | 
                                                        |
| 160 | - $settingsManager = new SettingsManager($this->serverContainer->getConfig());  | 
                                                        |
| 161 | -  | 
                                                        |
| 162 | - $this->shareByMailProvider = new ShareByMailProvider(  | 
                                                        |
| 163 | - $this->serverContainer->getDatabaseConnection(),  | 
                                                        |
| 164 | - $this->serverContainer->getSecureRandom(),  | 
                                                        |
| 165 | - $this->serverContainer->getUserManager(),  | 
                                                        |
| 166 | - $this->serverContainer->getLazyRootFolder(),  | 
                                                        |
| 167 | -				$this->serverContainer->getL10N('sharebymail'), | 
                                                        |
| 168 | - $this->serverContainer->getLogger(),  | 
                                                        |
| 169 | - $this->serverContainer->getMailer(),  | 
                                                        |
| 170 | - $this->serverContainer->getURLGenerator(),  | 
                                                        |
| 171 | - $this->serverContainer->getActivityManager(),  | 
                                                        |
| 172 | - $settingsManager,  | 
                                                        |
| 173 | - $this->serverContainer->query(Defaults::class),  | 
                                                        |
| 174 | - $this->serverContainer->getHasher(),  | 
                                                        |
| 175 | - $this->serverContainer->query(CapabilitiesManager::class)  | 
                                                        |
| 176 | - );  | 
                                                        |
| 177 | - }  | 
                                                        |
| 178 | -  | 
                                                        |
| 179 | - return $this->shareByMailProvider;  | 
                                                        |
| 180 | - }  | 
                                                        |
| 181 | -  | 
                                                        |
| 182 | -  | 
                                                        |
| 183 | - /**  | 
                                                        |
| 184 | - * Create the circle share provider  | 
                                                        |
| 185 | - *  | 
                                                        |
| 186 | - * @return FederatedShareProvider  | 
                                                        |
| 187 | - *  | 
                                                        |
| 188 | - * @suppress PhanUndeclaredClassMethod  | 
                                                        |
| 189 | - */  | 
                                                        |
| 190 | -	protected function getShareByCircleProvider() { | 
                                                        |
| 191 | -  | 
                                                        |
| 192 | -		if ($this->circlesAreNotAvailable) { | 
                                                        |
| 193 | - return null;  | 
                                                        |
| 194 | - }  | 
                                                        |
| 195 | -  | 
                                                        |
| 196 | -		if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') || | 
                                                        |
| 197 | -			!class_exists('\OCA\Circles\ShareByCircleProvider') | 
                                                        |
| 198 | -		) { | 
                                                        |
| 199 | - $this->circlesAreNotAvailable = true;  | 
                                                        |
| 200 | - return null;  | 
                                                        |
| 201 | - }  | 
                                                        |
| 202 | -  | 
                                                        |
| 203 | -		if ($this->shareByCircleProvider === null) { | 
                                                        |
| 204 | -  | 
                                                        |
| 205 | - $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider(  | 
                                                        |
| 206 | - $this->serverContainer->getDatabaseConnection(),  | 
                                                        |
| 207 | - $this->serverContainer->getSecureRandom(),  | 
                                                        |
| 208 | - $this->serverContainer->getUserManager(),  | 
                                                        |
| 209 | - $this->serverContainer->getLazyRootFolder(),  | 
                                                        |
| 210 | -				$this->serverContainer->getL10N('circles'), | 
                                                        |
| 211 | - $this->serverContainer->getLogger(),  | 
                                                        |
| 212 | - $this->serverContainer->getURLGenerator()  | 
                                                        |
| 213 | - );  | 
                                                        |
| 214 | - }  | 
                                                        |
| 215 | -  | 
                                                        |
| 216 | - return $this->shareByCircleProvider;  | 
                                                        |
| 217 | - }  | 
                                                        |
| 218 | -  | 
                                                        |
| 219 | -  | 
                                                        |
| 220 | - /**  | 
                                                        |
| 221 | - * @inheritdoc  | 
                                                        |
| 222 | - */  | 
                                                        |
| 223 | -	public function getProvider($id) { | 
                                                        |
| 224 | - $provider = null;  | 
                                                        |
| 225 | -		if ($id === 'ocinternal') { | 
                                                        |
| 226 | - $provider = $this->defaultShareProvider();  | 
                                                        |
| 227 | -		} else if ($id === 'ocFederatedSharing') { | 
                                                        |
| 228 | - $provider = $this->federatedShareProvider();  | 
                                                        |
| 229 | -		} else if ($id === 'ocMailShare') { | 
                                                        |
| 230 | - $provider = $this->getShareByMailProvider();  | 
                                                        |
| 231 | -		} else if ($id === 'ocCircleShare') { | 
                                                        |
| 232 | - $provider = $this->getShareByCircleProvider();  | 
                                                        |
| 233 | - }  | 
                                                        |
| 234 | -  | 
                                                        |
| 235 | -		if ($provider === null) { | 
                                                        |
| 236 | -			throw new ProviderException('No provider with id .' . $id . ' found.'); | 
                                                        |
| 237 | - }  | 
                                                        |
| 238 | -  | 
                                                        |
| 239 | - return $provider;  | 
                                                        |
| 240 | - }  | 
                                                        |
| 241 | -  | 
                                                        |
| 242 | - /**  | 
                                                        |
| 243 | - * @inheritdoc  | 
                                                        |
| 244 | - */  | 
                                                        |
| 245 | -	public function getProviderForType($shareType) { | 
                                                        |
| 246 | - $provider = null;  | 
                                                        |
| 247 | -  | 
                                                        |
| 248 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER ||  | 
                                                        |
| 249 | - $shareType === \OCP\Share::SHARE_TYPE_GROUP ||  | 
                                                        |
| 250 | - $shareType === \OCP\Share::SHARE_TYPE_LINK  | 
                                                        |
| 251 | -		) { | 
                                                        |
| 252 | - $provider = $this->defaultShareProvider();  | 
                                                        |
| 253 | -		} else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { | 
                                                        |
| 254 | - $provider = $this->federatedShareProvider();  | 
                                                        |
| 255 | -		} else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { | 
                                                        |
| 256 | - $provider = $this->getShareByMailProvider();  | 
                                                        |
| 257 | -		} else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { | 
                                                        |
| 258 | - $provider = $this->getShareByCircleProvider();  | 
                                                        |
| 259 | - }  | 
                                                        |
| 260 | -  | 
                                                        |
| 261 | -  | 
                                                        |
| 262 | -		if ($provider === null) { | 
                                                        |
| 263 | -			throw new ProviderException('No share provider for share type ' . $shareType); | 
                                                        |
| 264 | - }  | 
                                                        |
| 265 | -  | 
                                                        |
| 266 | - return $provider;  | 
                                                        |
| 267 | - }  | 
                                                        |
| 268 | -  | 
                                                        |
| 269 | -	public function getAllProviders() { | 
                                                        |
| 270 | - $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()];  | 
                                                        |
| 271 | - $shareByMail = $this->getShareByMailProvider();  | 
                                                        |
| 272 | -		if ($shareByMail !== null) { | 
                                                        |
| 273 | - $shares[] = $shareByMail;  | 
                                                        |
| 274 | - }  | 
                                                        |
| 275 | - $shareByCircle = $this->getShareByCircleProvider();  | 
                                                        |
| 276 | -		if ($shareByCircle !== null) { | 
                                                        |
| 277 | - $shares[] = $shareByCircle;  | 
                                                        |
| 278 | - }  | 
                                                        |
| 279 | -  | 
                                                        |
| 280 | - return $shares;  | 
                                                        |
| 281 | - }  | 
                                                        |
| 155 | + $appManager = $this->serverContainer->getAppManager();  | 
                                                        |
| 156 | +            if (!$appManager->isEnabledForUser('sharebymail')) { | 
                                                        |
| 157 | + return null;  | 
                                                        |
| 158 | + }  | 
                                                        |
| 159 | +  | 
                                                        |
| 160 | + $settingsManager = new SettingsManager($this->serverContainer->getConfig());  | 
                                                        |
| 161 | +  | 
                                                        |
| 162 | + $this->shareByMailProvider = new ShareByMailProvider(  | 
                                                        |
| 163 | + $this->serverContainer->getDatabaseConnection(),  | 
                                                        |
| 164 | + $this->serverContainer->getSecureRandom(),  | 
                                                        |
| 165 | + $this->serverContainer->getUserManager(),  | 
                                                        |
| 166 | + $this->serverContainer->getLazyRootFolder(),  | 
                                                        |
| 167 | +                $this->serverContainer->getL10N('sharebymail'), | 
                                                        |
| 168 | + $this->serverContainer->getLogger(),  | 
                                                        |
| 169 | + $this->serverContainer->getMailer(),  | 
                                                        |
| 170 | + $this->serverContainer->getURLGenerator(),  | 
                                                        |
| 171 | + $this->serverContainer->getActivityManager(),  | 
                                                        |
| 172 | + $settingsManager,  | 
                                                        |
| 173 | + $this->serverContainer->query(Defaults::class),  | 
                                                        |
| 174 | + $this->serverContainer->getHasher(),  | 
                                                        |
| 175 | + $this->serverContainer->query(CapabilitiesManager::class)  | 
                                                        |
| 176 | + );  | 
                                                        |
| 177 | + }  | 
                                                        |
| 178 | +  | 
                                                        |
| 179 | + return $this->shareByMailProvider;  | 
                                                        |
| 180 | + }  | 
                                                        |
| 181 | +  | 
                                                        |
| 182 | +  | 
                                                        |
| 183 | + /**  | 
                                                        |
| 184 | + * Create the circle share provider  | 
                                                        |
| 185 | + *  | 
                                                        |
| 186 | + * @return FederatedShareProvider  | 
                                                        |
| 187 | + *  | 
                                                        |
| 188 | + * @suppress PhanUndeclaredClassMethod  | 
                                                        |
| 189 | + */  | 
                                                        |
| 190 | +    protected function getShareByCircleProvider() { | 
                                                        |
| 191 | +  | 
                                                        |
| 192 | +        if ($this->circlesAreNotAvailable) { | 
                                                        |
| 193 | + return null;  | 
                                                        |
| 194 | + }  | 
                                                        |
| 195 | +  | 
                                                        |
| 196 | +        if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') || | 
                                                        |
| 197 | +            !class_exists('\OCA\Circles\ShareByCircleProvider') | 
                                                        |
| 198 | +        ) { | 
                                                        |
| 199 | + $this->circlesAreNotAvailable = true;  | 
                                                        |
| 200 | + return null;  | 
                                                        |
| 201 | + }  | 
                                                        |
| 202 | +  | 
                                                        |
| 203 | +        if ($this->shareByCircleProvider === null) { | 
                                                        |
| 204 | +  | 
                                                        |
| 205 | + $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider(  | 
                                                        |
| 206 | + $this->serverContainer->getDatabaseConnection(),  | 
                                                        |
| 207 | + $this->serverContainer->getSecureRandom(),  | 
                                                        |
| 208 | + $this->serverContainer->getUserManager(),  | 
                                                        |
| 209 | + $this->serverContainer->getLazyRootFolder(),  | 
                                                        |
| 210 | +                $this->serverContainer->getL10N('circles'), | 
                                                        |
| 211 | + $this->serverContainer->getLogger(),  | 
                                                        |
| 212 | + $this->serverContainer->getURLGenerator()  | 
                                                        |
| 213 | + );  | 
                                                        |
| 214 | + }  | 
                                                        |
| 215 | +  | 
                                                        |
| 216 | + return $this->shareByCircleProvider;  | 
                                                        |
| 217 | + }  | 
                                                        |
| 218 | +  | 
                                                        |
| 219 | +  | 
                                                        |
| 220 | + /**  | 
                                                        |
| 221 | + * @inheritdoc  | 
                                                        |
| 222 | + */  | 
                                                        |
| 223 | +    public function getProvider($id) { | 
                                                        |
| 224 | + $provider = null;  | 
                                                        |
| 225 | +        if ($id === 'ocinternal') { | 
                                                        |
| 226 | + $provider = $this->defaultShareProvider();  | 
                                                        |
| 227 | +        } else if ($id === 'ocFederatedSharing') { | 
                                                        |
| 228 | + $provider = $this->federatedShareProvider();  | 
                                                        |
| 229 | +        } else if ($id === 'ocMailShare') { | 
                                                        |
| 230 | + $provider = $this->getShareByMailProvider();  | 
                                                        |
| 231 | +        } else if ($id === 'ocCircleShare') { | 
                                                        |
| 232 | + $provider = $this->getShareByCircleProvider();  | 
                                                        |
| 233 | + }  | 
                                                        |
| 234 | +  | 
                                                        |
| 235 | +        if ($provider === null) { | 
                                                        |
| 236 | +            throw new ProviderException('No provider with id .' . $id . ' found.'); | 
                                                        |
| 237 | + }  | 
                                                        |
| 238 | +  | 
                                                        |
| 239 | + return $provider;  | 
                                                        |
| 240 | + }  | 
                                                        |
| 241 | +  | 
                                                        |
| 242 | + /**  | 
                                                        |
| 243 | + * @inheritdoc  | 
                                                        |
| 244 | + */  | 
                                                        |
| 245 | +    public function getProviderForType($shareType) { | 
                                                        |
| 246 | + $provider = null;  | 
                                                        |
| 247 | +  | 
                                                        |
| 248 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER ||  | 
                                                        |
| 249 | + $shareType === \OCP\Share::SHARE_TYPE_GROUP ||  | 
                                                        |
| 250 | + $shareType === \OCP\Share::SHARE_TYPE_LINK  | 
                                                        |
| 251 | +        ) { | 
                                                        |
| 252 | + $provider = $this->defaultShareProvider();  | 
                                                        |
| 253 | +        } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { | 
                                                        |
| 254 | + $provider = $this->federatedShareProvider();  | 
                                                        |
| 255 | +        } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { | 
                                                        |
| 256 | + $provider = $this->getShareByMailProvider();  | 
                                                        |
| 257 | +        } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { | 
                                                        |
| 258 | + $provider = $this->getShareByCircleProvider();  | 
                                                        |
| 259 | + }  | 
                                                        |
| 260 | +  | 
                                                        |
| 261 | +  | 
                                                        |
| 262 | +        if ($provider === null) { | 
                                                        |
| 263 | +            throw new ProviderException('No share provider for share type ' . $shareType); | 
                                                        |
| 264 | + }  | 
                                                        |
| 265 | +  | 
                                                        |
| 266 | + return $provider;  | 
                                                        |
| 267 | + }  | 
                                                        |
| 268 | +  | 
                                                        |
| 269 | +    public function getAllProviders() { | 
                                                        |
| 270 | + $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()];  | 
                                                        |
| 271 | + $shareByMail = $this->getShareByMailProvider();  | 
                                                        |
| 272 | +        if ($shareByMail !== null) { | 
                                                        |
| 273 | + $shares[] = $shareByMail;  | 
                                                        |
| 274 | + }  | 
                                                        |
| 275 | + $shareByCircle = $this->getShareByCircleProvider();  | 
                                                        |
| 276 | +        if ($shareByCircle !== null) { | 
                                                        |
| 277 | + $shares[] = $shareByCircle;  | 
                                                        |
| 278 | + }  | 
                                                        |
| 279 | +  | 
                                                        |
| 280 | + return $shares;  | 
                                                        |
| 281 | + }  | 
                                                        |
| 282 | 282 | }  | 
                                                        
@@ -29,11 +29,11 @@  | 
                                                    ||
| 29 | 29 |  $isEnabled = $server->getAppManager()->isEnabledForUser('cloud_federation_api'); | 
                                                        
| 30 | 30 | |
| 31 | 31 |  if ($isEnabled) { | 
                                                        
| 32 | - $capabilities = new OCA\CloudFederationAPI\Capabilities($server->getURLGenerator());  | 
                                                        |
| 33 | -	header('Content-Type: application/json'); | 
                                                        |
| 34 | - echo json_encode($capabilities->getCapabilities()['ocm']);  | 
                                                        |
| 32 | + $capabilities = new OCA\CloudFederationAPI\Capabilities($server->getURLGenerator());  | 
                                                        |
| 33 | +    header('Content-Type: application/json'); | 
                                                        |
| 34 | + echo json_encode($capabilities->getCapabilities()['ocm']);  | 
                                                        |
| 35 | 35 |  } else { | 
                                                        
| 36 | - header($_SERVER["SERVER_PROTOCOL"]." 501 Not Implemented", true, 501);  | 
                                                        |
| 37 | -	exit("501 Not Implemented"); | 
                                                        |
| 36 | + header($_SERVER["SERVER_PROTOCOL"]." 501 Not Implemented", true, 501);  | 
                                                        |
| 37 | +    exit("501 Not Implemented"); | 
                                                        |
| 38 | 38 | }  | 
                                                        
| 39 | 39 | |
@@ -20,7 +20,7 @@  | 
                                                    ||
| 20 | 20 | */  | 
                                                        
| 21 | 21 | |
| 22 | 22 | |
| 23 | -require_once __DIR__ . '/../lib/base.php';  | 
                                                        |
| 23 | +require_once __DIR__.'/../lib/base.php';  | 
                                                        |
| 24 | 24 | |
| 25 | 25 |  header('Content-Type: application/json'); | 
                                                        
| 26 | 26 | |
@@ -6,39 +6,39 @@  | 
                                                    ||
| 6 | 6 | |
| 7 | 7 | class ComposerStaticInitFederatedFileSharing  | 
                                                        
| 8 | 8 |  { | 
                                                        
| 9 | - public static $prefixLengthsPsr4 = array (  | 
                                                        |
| 9 | + public static $prefixLengthsPsr4 = array(  | 
                                                        |
| 10 | 10 | 'O' =>  | 
                                                        
| 11 | - array (  | 
                                                        |
| 11 | + array(  | 
                                                        |
| 12 | 12 | 'OCA\\FederatedFileSharing\\' => 25,  | 
                                                        
| 13 | 13 | ),  | 
                                                        
| 14 | 14 | );  | 
                                                        
| 15 | 15 | |
| 16 | - public static $prefixDirsPsr4 = array (  | 
                                                        |
| 16 | + public static $prefixDirsPsr4 = array(  | 
                                                        |
| 17 | 17 | 'OCA\\FederatedFileSharing\\' =>  | 
                                                        
| 18 | - array (  | 
                                                        |
| 19 | - 0 => __DIR__ . '/..' . '/../lib',  | 
                                                        |
| 18 | + array(  | 
                                                        |
| 19 | + 0 => __DIR__.'/..'.'/../lib',  | 
                                                        |
| 20 | 20 | ),  | 
                                                        
| 21 | 21 | );  | 
                                                        
| 22 | 22 | |
| 23 | - public static $classMap = array (  | 
                                                        |
| 24 | - 'OCA\\FederatedFileSharing\\AddressHandler' => __DIR__ . '/..' . '/../lib/AddressHandler.php',  | 
                                                        |
| 25 | - 'OCA\\FederatedFileSharing\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',  | 
                                                        |
| 26 | - 'OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/RetryJob.php',  | 
                                                        |
| 27 | - 'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => __DIR__ . '/..' . '/../lib/Controller/MountPublicLinkController.php',  | 
                                                        |
| 28 | - 'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => __DIR__ . '/..' . '/../lib/Controller/RequestHandlerController.php',  | 
                                                        |
| 29 | - 'OCA\\FederatedFileSharing\\FederatedShareProvider' => __DIR__ . '/..' . '/../lib/FederatedShareProvider.php',  | 
                                                        |
| 30 | - 'OCA\\FederatedFileSharing\\Notifications' => __DIR__ . '/..' . '/../lib/Notifications.php',  | 
                                                        |
| 31 | - 'OCA\\FederatedFileSharing\\Notifier' => __DIR__ . '/..' . '/../lib/Notifier.php',  | 
                                                        |
| 32 | - 'OCA\\FederatedFileSharing\\OCM\\CloudFederationProviderFiles' => __DIR__ . '/..' . '/../lib/ocm/CloudFederationProviderFiles.php',  | 
                                                        |
| 33 | - 'OCA\\FederatedFileSharing\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',  | 
                                                        |
| 34 | - 'OCA\\FederatedFileSharing\\Settings\\Personal' => __DIR__ . '/..' . '/../lib/Settings/Personal.php',  | 
                                                        |
| 35 | - 'OCA\\FederatedFileSharing\\Settings\\PersonalSection' => __DIR__ . '/..' . '/../lib/Settings/PersonalSection.php',  | 
                                                        |
| 36 | - 'OCA\\FederatedFileSharing\\TokenHandler' => __DIR__ . '/..' . '/../lib/TokenHandler.php',  | 
                                                        |
| 23 | + public static $classMap = array(  | 
                                                        |
| 24 | + 'OCA\\FederatedFileSharing\\AddressHandler' => __DIR__.'/..'.'/../lib/AddressHandler.php',  | 
                                                        |
| 25 | + 'OCA\\FederatedFileSharing\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php',  | 
                                                        |
| 26 | + 'OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob' => __DIR__.'/..'.'/../lib/BackgroundJob/RetryJob.php',  | 
                                                        |
| 27 | + 'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => __DIR__.'/..'.'/../lib/Controller/MountPublicLinkController.php',  | 
                                                        |
| 28 | + 'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => __DIR__.'/..'.'/../lib/Controller/RequestHandlerController.php',  | 
                                                        |
| 29 | + 'OCA\\FederatedFileSharing\\FederatedShareProvider' => __DIR__.'/..'.'/../lib/FederatedShareProvider.php',  | 
                                                        |
| 30 | + 'OCA\\FederatedFileSharing\\Notifications' => __DIR__.'/..'.'/../lib/Notifications.php',  | 
                                                        |
| 31 | + 'OCA\\FederatedFileSharing\\Notifier' => __DIR__.'/..'.'/../lib/Notifier.php',  | 
                                                        |
| 32 | + 'OCA\\FederatedFileSharing\\OCM\\CloudFederationProviderFiles' => __DIR__.'/..'.'/../lib/ocm/CloudFederationProviderFiles.php',  | 
                                                        |
| 33 | + 'OCA\\FederatedFileSharing\\Settings\\Admin' => __DIR__.'/..'.'/../lib/Settings/Admin.php',  | 
                                                        |
| 34 | + 'OCA\\FederatedFileSharing\\Settings\\Personal' => __DIR__.'/..'.'/../lib/Settings/Personal.php',  | 
                                                        |
| 35 | + 'OCA\\FederatedFileSharing\\Settings\\PersonalSection' => __DIR__.'/..'.'/../lib/Settings/PersonalSection.php',  | 
                                                        |
| 36 | + 'OCA\\FederatedFileSharing\\TokenHandler' => __DIR__.'/..'.'/../lib/TokenHandler.php',  | 
                                                        |
| 37 | 37 | );  | 
                                                        
| 38 | 38 | |
| 39 | 39 | public static function getInitializer(ClassLoader $loader)  | 
                                                        
| 40 | 40 |      { | 
                                                        
| 41 | -        return \Closure::bind(function () use ($loader) { | 
                                                        |
| 41 | +        return \Closure::bind(function() use ($loader) { | 
                                                        |
| 42 | 42 | $loader->prefixLengthsPsr4 = ComposerStaticInitFederatedFileSharing::$prefixLengthsPsr4;  | 
                                                        
| 43 | 43 | $loader->prefixDirsPsr4 = ComposerStaticInitFederatedFileSharing::$prefixDirsPsr4;  | 
                                                        
| 44 | 44 | $loader->classMap = ComposerStaticInitFederatedFileSharing::$classMap;  | 
                                                        
@@ -6,17 +6,17 @@  | 
                                                    ||
| 6 | 6 | $baseDir = $vendorDir;  | 
                                                        
| 7 | 7 | |
| 8 | 8 | return array(  | 
                                                        
| 9 | - 'OCA\\FederatedFileSharing\\AddressHandler' => $baseDir . '/../lib/AddressHandler.php',  | 
                                                        |
| 10 | - 'OCA\\FederatedFileSharing\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',  | 
                                                        |
| 11 | - 'OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob' => $baseDir . '/../lib/BackgroundJob/RetryJob.php',  | 
                                                        |
| 12 | - 'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => $baseDir . '/../lib/Controller/MountPublicLinkController.php',  | 
                                                        |
| 13 | - 'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => $baseDir . '/../lib/Controller/RequestHandlerController.php',  | 
                                                        |
| 14 | - 'OCA\\FederatedFileSharing\\FederatedShareProvider' => $baseDir . '/../lib/FederatedShareProvider.php',  | 
                                                        |
| 15 | - 'OCA\\FederatedFileSharing\\Notifications' => $baseDir . '/../lib/Notifications.php',  | 
                                                        |
| 16 | - 'OCA\\FederatedFileSharing\\Notifier' => $baseDir . '/../lib/Notifier.php',  | 
                                                        |
| 17 | - 'OCA\\FederatedFileSharing\\OCM\\CloudFederationProviderFiles' => $baseDir . '/../lib/ocm/CloudFederationProviderFiles.php',  | 
                                                        |
| 18 | - 'OCA\\FederatedFileSharing\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',  | 
                                                        |
| 19 | - 'OCA\\FederatedFileSharing\\Settings\\Personal' => $baseDir . '/../lib/Settings/Personal.php',  | 
                                                        |
| 20 | - 'OCA\\FederatedFileSharing\\Settings\\PersonalSection' => $baseDir . '/../lib/Settings/PersonalSection.php',  | 
                                                        |
| 21 | - 'OCA\\FederatedFileSharing\\TokenHandler' => $baseDir . '/../lib/TokenHandler.php',  | 
                                                        |
| 9 | + 'OCA\\FederatedFileSharing\\AddressHandler' => $baseDir.'/../lib/AddressHandler.php',  | 
                                                        |
| 10 | + 'OCA\\FederatedFileSharing\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php',  | 
                                                        |
| 11 | + 'OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob' => $baseDir.'/../lib/BackgroundJob/RetryJob.php',  | 
                                                        |
| 12 | + 'OCA\\FederatedFileSharing\\Controller\\MountPublicLinkController' => $baseDir.'/../lib/Controller/MountPublicLinkController.php',  | 
                                                        |
| 13 | + 'OCA\\FederatedFileSharing\\Controller\\RequestHandlerController' => $baseDir.'/../lib/Controller/RequestHandlerController.php',  | 
                                                        |
| 14 | + 'OCA\\FederatedFileSharing\\FederatedShareProvider' => $baseDir.'/../lib/FederatedShareProvider.php',  | 
                                                        |
| 15 | + 'OCA\\FederatedFileSharing\\Notifications' => $baseDir.'/../lib/Notifications.php',  | 
                                                        |
| 16 | + 'OCA\\FederatedFileSharing\\Notifier' => $baseDir.'/../lib/Notifier.php',  | 
                                                        |
| 17 | + 'OCA\\FederatedFileSharing\\OCM\\CloudFederationProviderFiles' => $baseDir.'/../lib/ocm/CloudFederationProviderFiles.php',  | 
                                                        |
| 18 | + 'OCA\\FederatedFileSharing\\Settings\\Admin' => $baseDir.'/../lib/Settings/Admin.php',  | 
                                                        |
| 19 | + 'OCA\\FederatedFileSharing\\Settings\\Personal' => $baseDir.'/../lib/Settings/Personal.php',  | 
                                                        |
| 20 | + 'OCA\\FederatedFileSharing\\Settings\\PersonalSection' => $baseDir.'/../lib/Settings/PersonalSection.php',  | 
                                                        |
| 21 | + 'OCA\\FederatedFileSharing\\TokenHandler' => $baseDir.'/../lib/TokenHandler.php',  | 
                                                        |
| 22 | 22 | );  | 
                                                        
@@ -32,15 +32,15 @@  | 
                                                    ||
| 32 | 32 | */  | 
                                                        
| 33 | 33 |  class Config { | 
                                                        
| 34 | 34 | |
| 35 | -	public function __construct() { | 
                                                        |
| 36 | - }  | 
                                                        |
| 35 | +    public function __construct() { | 
                                                        |
| 36 | + }  | 
                                                        |
| 37 | 37 | |
| 38 | -	public function incomingRequestsEnabled() { | 
                                                        |
| 39 | - return true;  | 
                                                        |
| 40 | - }  | 
                                                        |
| 38 | +    public function incomingRequestsEnabled() { | 
                                                        |
| 39 | + return true;  | 
                                                        |
| 40 | + }  | 
                                                        |
| 41 | 41 | |
| 42 | -	public function outgoingRequestsEnabled() { | 
                                                        |
| 43 | - return true;  | 
                                                        |
| 44 | - }  | 
                                                        |
| 42 | +    public function outgoingRequestsEnabled() { | 
                                                        |
| 43 | + return true;  | 
                                                        |
| 44 | + }  | 
                                                        |
| 45 | 45 | |
| 46 | 46 | }  | 
                                                        
@@ -28,10 +28,10 @@  | 
                                                    ||
| 28 | 28 | |
| 29 | 29 |  class Application extends App { | 
                                                        
| 30 | 30 | |
| 31 | -	public function __construct() { | 
                                                        |
| 32 | -		parent::__construct('cloud_federation_api'); | 
                                                        |
| 31 | +    public function __construct() { | 
                                                        |
| 32 | +        parent::__construct('cloud_federation_api'); | 
                                                        |
| 33 | 33 | |
| 34 | - $container = $this->getContainer();  | 
                                                        |
| 35 | - $container->registerCapability(Capabilities::class);  | 
                                                        |
| 36 | - }  | 
                                                        |
| 34 | + $container = $this->getContainer();  | 
                                                        |
| 35 | + $container->registerCapability(Capabilities::class);  | 
                                                        |
| 36 | + }  | 
                                                        |
| 37 | 37 | }  | 
                                                        
@@ -32,7 +32,7 @@  | 
                                                    ||
| 32 | 32 | */  | 
                                                        
| 33 | 33 |  	public function __construct($providerId) { | 
                                                        
| 34 | 34 |  		$l = \OC::$server->getL10N('federation'); | 
                                                        
| 35 | - $message = 'Cloud Federation Provider with ID: "' . $providerId . '" does not exist.';  | 
                                                        |
| 35 | + $message = 'Cloud Federation Provider with ID: "'.$providerId.'" does not exist.';  | 
                                                        |
| 36 | 36 |  		$hint = $l->t('Cloud Federation Provider with ID: "%s" does not exist.', [$providerId]); | 
                                                        
| 37 | 37 | parent::__construct($message, $hint);  | 
                                                        
| 38 | 38 | }  | 
                                                        
@@ -32,18 +32,18 @@  | 
                                                    ||
| 32 | 32 | */  | 
                                                        
| 33 | 33 |  class ProviderDoesNotExistsException extends HintException { | 
                                                        
| 34 | 34 | |
| 35 | - /**  | 
                                                        |
| 36 | - * ProviderDoesNotExistsException constructor.  | 
                                                        |
| 37 | - *  | 
                                                        |
| 38 | - * @since 14.0.0  | 
                                                        |
| 39 | - *  | 
                                                        |
| 40 | - * @param string $providerId cloud federation provider ID  | 
                                                        |
| 41 | - */  | 
                                                        |
| 42 | -	public function __construct($providerId) { | 
                                                        |
| 43 | -		$l = \OC::$server->getL10N('federation'); | 
                                                        |
| 44 | - $message = 'Cloud Federation Provider with ID: "' . $providerId . '" does not exist.';  | 
                                                        |
| 45 | -		$hint = $l->t('Cloud Federation Provider with ID: "%s" does not exist.', [$providerId]); | 
                                                        |
| 46 | - parent::__construct($message, $hint);  | 
                                                        |
| 47 | - }  | 
                                                        |
| 35 | + /**  | 
                                                        |
| 36 | + * ProviderDoesNotExistsException constructor.  | 
                                                        |
| 37 | + *  | 
                                                        |
| 38 | + * @since 14.0.0  | 
                                                        |
| 39 | + *  | 
                                                        |
| 40 | + * @param string $providerId cloud federation provider ID  | 
                                                        |
| 41 | + */  | 
                                                        |
| 42 | +    public function __construct($providerId) { | 
                                                        |
| 43 | +        $l = \OC::$server->getL10N('federation'); | 
                                                        |
| 44 | + $message = 'Cloud Federation Provider with ID: "' . $providerId . '" does not exist.';  | 
                                                        |
| 45 | +        $hint = $l->t('Cloud Federation Provider with ID: "%s" does not exist.', [$providerId]); | 
                                                        |
| 46 | + parent::__construct($message, $hint);  | 
                                                        |
| 47 | + }  | 
                                                        |
| 48 | 48 | |
| 49 | 49 | }  |