|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Morris Jobke <[email protected]> |
|
4
|
|
|
* @author Robin Appelman <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
7
|
|
|
* @license AGPL-3.0 |
|
8
|
|
|
* |
|
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
11
|
|
|
* as published by the Free Software Foundation. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace OCA\Files_Sharing; |
|
24
|
|
|
|
|
25
|
|
|
use OC\Files\Filesystem; |
|
26
|
|
|
use OC\User\NoUserException; |
|
27
|
|
|
use OCP\Files\Config\IMountProvider; |
|
28
|
|
|
use OCP\Files\Storage\IStorageFactory; |
|
29
|
|
|
use OCP\IConfig; |
|
30
|
|
|
use OCP\ILogger; |
|
31
|
|
|
use OCP\IUser; |
|
32
|
|
|
|
|
33
|
|
|
class MountProvider implements IMountProvider { |
|
34
|
|
|
/** |
|
35
|
|
|
* @var \OCP\IConfig |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $config; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var ILogger |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $logger; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param \OCP\IConfig $config |
|
46
|
|
|
* @param ILogger $logger |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(IConfig $config, ILogger $logger) { |
|
49
|
|
|
$this->config = $config; |
|
50
|
|
|
$this->logger = $logger; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get all mountpoints applicable for the user and check for shares where we need to update the etags |
|
56
|
|
|
* |
|
57
|
|
|
* @param \OCP\IUser $user |
|
58
|
|
|
* @param \OCP\Files\Storage\IStorageFactory $storageFactory |
|
59
|
|
|
* @return \OCP\Files\Mount\IMountPoint[] |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) { |
|
62
|
|
|
$shares = \OCP\Share::getItemsSharedWithUser('file', $user->getUID()); |
|
63
|
|
|
$shares = array_filter($shares, function ($share) { |
|
64
|
|
|
return $share['permissions'] > 0; |
|
65
|
|
|
}); |
|
66
|
|
|
$mounts = []; |
|
67
|
|
|
foreach ($shares as $share) { |
|
68
|
|
|
try { |
|
69
|
|
|
$mounts[] = new SharedMount( |
|
70
|
|
|
'\OC\Files\Storage\Shared', |
|
71
|
|
|
$mounts, |
|
72
|
|
|
[ |
|
73
|
|
|
'share' => $share, |
|
74
|
|
|
'user' => $user->getUID() |
|
75
|
|
|
], |
|
76
|
|
|
$storageFactory |
|
77
|
|
|
); |
|
78
|
|
|
} catch (\Exception $e) { |
|
79
|
|
|
$this->logger->logException($e); |
|
80
|
|
|
$this->logger->error('Error while trying to create shared mount'); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
// array_filter removes the null values from the array |
|
85
|
|
|
return array_filter($mounts); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|