@@ -29,43 +29,43 @@ |
||
29 | 29 | |
30 | 30 | class Mount extends MountPoint implements MoveableMount { |
31 | 31 | |
32 | - /** |
|
33 | - * @var \OCA\Files_Sharing\External\Manager |
|
34 | - */ |
|
35 | - protected $manager; |
|
32 | + /** |
|
33 | + * @var \OCA\Files_Sharing\External\Manager |
|
34 | + */ |
|
35 | + protected $manager; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param string|\OC\Files\Storage\Storage $storage |
|
39 | - * @param string $mountpoint |
|
40 | - * @param array $options |
|
41 | - * @param \OCA\Files_Sharing\External\Manager $manager |
|
42 | - * @param \OC\Files\Storage\StorageFactory $loader |
|
43 | - */ |
|
44 | - public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { |
|
45 | - parent::__construct($storage, $mountpoint, $options, $loader); |
|
46 | - $this->manager = $manager; |
|
47 | - } |
|
37 | + /** |
|
38 | + * @param string|\OC\Files\Storage\Storage $storage |
|
39 | + * @param string $mountpoint |
|
40 | + * @param array $options |
|
41 | + * @param \OCA\Files_Sharing\External\Manager $manager |
|
42 | + * @param \OC\Files\Storage\StorageFactory $loader |
|
43 | + */ |
|
44 | + public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { |
|
45 | + parent::__construct($storage, $mountpoint, $options, $loader); |
|
46 | + $this->manager = $manager; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Move the mount point to $target |
|
51 | - * |
|
52 | - * @param string $target the target mount point |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function moveMount($target) { |
|
56 | - $result = $this->manager->setMountPoint($this->mountPoint, $target); |
|
57 | - $this->setMountPoint($target); |
|
49 | + /** |
|
50 | + * Move the mount point to $target |
|
51 | + * |
|
52 | + * @param string $target the target mount point |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function moveMount($target) { |
|
56 | + $result = $this->manager->setMountPoint($this->mountPoint, $target); |
|
57 | + $this->setMountPoint($target); |
|
58 | 58 | |
59 | - return $result; |
|
60 | - } |
|
59 | + return $result; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Remove the mount points |
|
64 | - * |
|
65 | - * @return mixed |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function removeMount() { |
|
69 | - return $this->manager->removeShare($this->mountPoint); |
|
70 | - } |
|
62 | + /** |
|
63 | + * Remove the mount points |
|
64 | + * |
|
65 | + * @return mixed |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function removeMount() { |
|
69 | + return $this->manager->removeShare($this->mountPoint); |
|
70 | + } |
|
71 | 71 | } |
@@ -27,81 +27,81 @@ |
||
27 | 27 | |
28 | 28 | class Updater { |
29 | 29 | |
30 | - /** |
|
31 | - * @param array $params |
|
32 | - */ |
|
33 | - static public function renameHook($params) { |
|
34 | - self::renameChildren($params['oldpath'], $params['newpath']); |
|
35 | - self::moveShareToShare($params['newpath']); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Fix for https://github.com/owncloud/core/issues/20769 |
|
40 | - * |
|
41 | - * The owner is allowed to move their files (if they are shared) into a receiving folder |
|
42 | - * In this case we need to update the parent of the moved share. Since they are |
|
43 | - * effectively handing over ownership of the file the rest of the code needs to know |
|
44 | - * they need to build up the reshare tree. |
|
45 | - * |
|
46 | - * @param string $path |
|
47 | - */ |
|
48 | - static private function moveShareToShare($path) { |
|
49 | - $userFolder = \OC::$server->getUserFolder(); |
|
50 | - |
|
51 | - // If the user folder can't be constructed (e.g. link share) just return. |
|
52 | - if ($userFolder === null) { |
|
53 | - return; |
|
54 | - } |
|
55 | - |
|
56 | - $src = $userFolder->get($path); |
|
57 | - |
|
58 | - $shareManager = \OC::$server->getShareManager(); |
|
59 | - |
|
60 | - $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_USER, $src, false, -1); |
|
61 | - $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $src, false, -1)); |
|
62 | - |
|
63 | - // If the path we move is not a share we don't care |
|
64 | - if (empty($shares)) { |
|
65 | - return; |
|
66 | - } |
|
67 | - |
|
68 | - // Check if the destination is inside a share |
|
69 | - $mountManager = \OC::$server->getMountManager(); |
|
70 | - $dstMount = $mountManager->find($src->getPath()); |
|
71 | - if (!($dstMount instanceof \OCA\Files_Sharing\SharedMount)) { |
|
72 | - return; |
|
73 | - } |
|
74 | - |
|
75 | - $newOwner = $dstMount->getShare()->getShareOwner(); |
|
76 | - |
|
77 | - //Ownership is moved over |
|
78 | - foreach ($shares as $share) { |
|
79 | - /** @var \OCP\Share\IShare $share */ |
|
80 | - $share->setShareOwner($newOwner); |
|
81 | - $shareManager->updateShare($share); |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * rename mount point from the children if the parent was renamed |
|
87 | - * |
|
88 | - * @param string $oldPath old path relative to data/user/files |
|
89 | - * @param string $newPath new path relative to data/user/files |
|
90 | - */ |
|
91 | - static private function renameChildren($oldPath, $newPath) { |
|
92 | - |
|
93 | - $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath); |
|
94 | - $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
95 | - |
|
96 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
97 | - $mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
98 | - foreach ($mountedShares as $mount) { |
|
99 | - if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
|
100 | - $mountPoint = $mount->getMountPoint(); |
|
101 | - $target = str_replace($absOldPath, $absNewPath, $mountPoint); |
|
102 | - $mount->moveMount($target); |
|
103 | - } |
|
104 | - } |
|
105 | - } |
|
30 | + /** |
|
31 | + * @param array $params |
|
32 | + */ |
|
33 | + static public function renameHook($params) { |
|
34 | + self::renameChildren($params['oldpath'], $params['newpath']); |
|
35 | + self::moveShareToShare($params['newpath']); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Fix for https://github.com/owncloud/core/issues/20769 |
|
40 | + * |
|
41 | + * The owner is allowed to move their files (if they are shared) into a receiving folder |
|
42 | + * In this case we need to update the parent of the moved share. Since they are |
|
43 | + * effectively handing over ownership of the file the rest of the code needs to know |
|
44 | + * they need to build up the reshare tree. |
|
45 | + * |
|
46 | + * @param string $path |
|
47 | + */ |
|
48 | + static private function moveShareToShare($path) { |
|
49 | + $userFolder = \OC::$server->getUserFolder(); |
|
50 | + |
|
51 | + // If the user folder can't be constructed (e.g. link share) just return. |
|
52 | + if ($userFolder === null) { |
|
53 | + return; |
|
54 | + } |
|
55 | + |
|
56 | + $src = $userFolder->get($path); |
|
57 | + |
|
58 | + $shareManager = \OC::$server->getShareManager(); |
|
59 | + |
|
60 | + $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_USER, $src, false, -1); |
|
61 | + $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $src, false, -1)); |
|
62 | + |
|
63 | + // If the path we move is not a share we don't care |
|
64 | + if (empty($shares)) { |
|
65 | + return; |
|
66 | + } |
|
67 | + |
|
68 | + // Check if the destination is inside a share |
|
69 | + $mountManager = \OC::$server->getMountManager(); |
|
70 | + $dstMount = $mountManager->find($src->getPath()); |
|
71 | + if (!($dstMount instanceof \OCA\Files_Sharing\SharedMount)) { |
|
72 | + return; |
|
73 | + } |
|
74 | + |
|
75 | + $newOwner = $dstMount->getShare()->getShareOwner(); |
|
76 | + |
|
77 | + //Ownership is moved over |
|
78 | + foreach ($shares as $share) { |
|
79 | + /** @var \OCP\Share\IShare $share */ |
|
80 | + $share->setShareOwner($newOwner); |
|
81 | + $shareManager->updateShare($share); |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * rename mount point from the children if the parent was renamed |
|
87 | + * |
|
88 | + * @param string $oldPath old path relative to data/user/files |
|
89 | + * @param string $newPath new path relative to data/user/files |
|
90 | + */ |
|
91 | + static private function renameChildren($oldPath, $newPath) { |
|
92 | + |
|
93 | + $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath); |
|
94 | + $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
95 | + |
|
96 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
97 | + $mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
98 | + foreach ($mountedShares as $mount) { |
|
99 | + if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
|
100 | + $mountPoint = $mount->getMountPoint(); |
|
101 | + $target = str_replace($absOldPath, $absNewPath, $mountPoint); |
|
102 | + $mount->moveMount($target); |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | } |
@@ -90,11 +90,11 @@ |
||
90 | 90 | */ |
91 | 91 | static private function renameChildren($oldPath, $newPath) { |
92 | 92 | |
93 | - $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath); |
|
94 | - $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
93 | + $absNewPath = \OC\Files\Filesystem::normalizePath('/'.\OCP\User::getUser().'/files/'.$newPath); |
|
94 | + $absOldPath = \OC\Files\Filesystem::normalizePath('/'.\OCP\User::getUser().'/files/'.$oldPath); |
|
95 | 95 | |
96 | 96 | $mountManager = \OC\Files\Filesystem::getMountManager(); |
97 | - $mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
97 | + $mountedShares = $mountManager->findIn('/'.\OCP\User::getUser().'/files/'.$oldPath); |
|
98 | 98 | foreach ($mountedShares as $mount) { |
99 | 99 | if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
100 | 100 | $mountPoint = $mount->getMountPoint(); |
@@ -31,36 +31,36 @@ |
||
31 | 31 | */ |
32 | 32 | class DeleteOrphanedSharesJob extends TimedJob { |
33 | 33 | |
34 | - /** |
|
35 | - * Default interval in minutes |
|
36 | - * |
|
37 | - * @var int $defaultIntervalMin |
|
38 | - **/ |
|
39 | - protected $defaultIntervalMin = 15; |
|
34 | + /** |
|
35 | + * Default interval in minutes |
|
36 | + * |
|
37 | + * @var int $defaultIntervalMin |
|
38 | + **/ |
|
39 | + protected $defaultIntervalMin = 15; |
|
40 | 40 | |
41 | - /** |
|
42 | - * sets the correct interval for this timed job |
|
43 | - */ |
|
44 | - public function __construct(){ |
|
45 | - $this->interval = $this->defaultIntervalMin * 60; |
|
46 | - } |
|
41 | + /** |
|
42 | + * sets the correct interval for this timed job |
|
43 | + */ |
|
44 | + public function __construct(){ |
|
45 | + $this->interval = $this->defaultIntervalMin * 60; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Makes the background job do its work |
|
50 | - * |
|
51 | - * @param array $argument unused argument |
|
52 | - */ |
|
53 | - public function run($argument) { |
|
54 | - $connection = \OC::$server->getDatabaseConnection(); |
|
55 | - $logger = \OC::$server->getLogger(); |
|
48 | + /** |
|
49 | + * Makes the background job do its work |
|
50 | + * |
|
51 | + * @param array $argument unused argument |
|
52 | + */ |
|
53 | + public function run($argument) { |
|
54 | + $connection = \OC::$server->getDatabaseConnection(); |
|
55 | + $logger = \OC::$server->getLogger(); |
|
56 | 56 | |
57 | - $sql = |
|
58 | - 'DELETE FROM `*PREFIX*share` ' . |
|
59 | - 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
60 | - 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
|
57 | + $sql = |
|
58 | + 'DELETE FROM `*PREFIX*share` ' . |
|
59 | + 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
60 | + 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
|
61 | 61 | |
62 | - $deletedEntries = $connection->executeUpdate($sql); |
|
63 | - $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); |
|
64 | - } |
|
62 | + $deletedEntries = $connection->executeUpdate($sql); |
|
63 | + $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * sets the correct interval for this timed job |
43 | 43 | */ |
44 | - public function __construct(){ |
|
44 | + public function __construct() { |
|
45 | 45 | $this->interval = $this->defaultIntervalMin * 60; |
46 | 46 | } |
47 | 47 | |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | $logger = \OC::$server->getLogger(); |
56 | 56 | |
57 | 57 | $sql = |
58 | - 'DELETE FROM `*PREFIX*share` ' . |
|
59 | - 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
58 | + 'DELETE FROM `*PREFIX*share` '. |
|
59 | + 'WHERE `item_type` in (\'file\', \'folder\') '. |
|
60 | 60 | 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
61 | 61 | |
62 | 62 | $deletedEntries = $connection->executeUpdate($sql); |
@@ -71,7 +71,7 @@ |
||
71 | 71 | $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1); |
72 | 72 | $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1)); |
73 | 73 | // filter out excluded shares and group shares that includes self |
74 | - $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) { |
|
74 | + $shares = array_filter($shares, function(\OCP\Share\IShare $share) use ($user) { |
|
75 | 75 | return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID(); |
76 | 76 | }); |
77 | 77 |
@@ -33,152 +33,152 @@ |
||
33 | 33 | use OCP\Share\IManager; |
34 | 34 | |
35 | 35 | class MountProvider implements IMountProvider { |
36 | - /** |
|
37 | - * @var \OCP\IConfig |
|
38 | - */ |
|
39 | - protected $config; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var IManager |
|
43 | - */ |
|
44 | - protected $shareManager; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var ILogger |
|
48 | - */ |
|
49 | - protected $logger; |
|
50 | - |
|
51 | - /** |
|
52 | - * @param \OCP\IConfig $config |
|
53 | - * @param IManager $shareManager |
|
54 | - * @param ILogger $logger |
|
55 | - */ |
|
56 | - public function __construct(IConfig $config, IManager $shareManager, ILogger $logger) { |
|
57 | - $this->config = $config; |
|
58 | - $this->shareManager = $shareManager; |
|
59 | - $this->logger = $logger; |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Get all mountpoints applicable for the user and check for shares where we need to update the etags |
|
65 | - * |
|
66 | - * @param \OCP\IUser $user |
|
67 | - * @param \OCP\Files\Storage\IStorageFactory $storageFactory |
|
68 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
69 | - */ |
|
70 | - public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) { |
|
71 | - $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1); |
|
72 | - $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1)); |
|
73 | - // filter out excluded shares and group shares that includes self |
|
74 | - $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) { |
|
75 | - return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID(); |
|
76 | - }); |
|
77 | - |
|
78 | - $superShares = $this->buildSuperShares($shares, $user); |
|
79 | - |
|
80 | - $mounts = []; |
|
81 | - foreach ($superShares as $share) { |
|
82 | - try { |
|
83 | - $mounts[] = new SharedMount( |
|
84 | - '\OC\Files\Storage\Shared', |
|
85 | - $mounts, |
|
86 | - [ |
|
87 | - 'user' => $user->getUID(), |
|
88 | - // parent share |
|
89 | - 'superShare' => $share[0], |
|
90 | - // children/component of the superShare |
|
91 | - 'groupedShares' => $share[1], |
|
92 | - ], |
|
93 | - $storageFactory |
|
94 | - ); |
|
95 | - } catch (\Exception $e) { |
|
96 | - $this->logger->logException($e); |
|
97 | - $this->logger->error('Error while trying to create shared mount'); |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - // array_filter removes the null values from the array |
|
102 | - return array_filter($mounts); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Groups shares by path (nodeId) and target path |
|
107 | - * |
|
108 | - * @param \OCP\Share\IShare[] $shares |
|
109 | - * @return \OCP\Share\IShare[][] array of grouped shares, each element in the |
|
110 | - * array is a group which itself is an array of shares |
|
111 | - */ |
|
112 | - private function groupShares(array $shares) { |
|
113 | - $tmp = []; |
|
114 | - |
|
115 | - foreach ($shares as $share) { |
|
116 | - if (!isset($tmp[$share->getNodeId()])) { |
|
117 | - $tmp[$share->getNodeId()] = []; |
|
118 | - } |
|
119 | - $tmp[$share->getNodeId()][] = $share; |
|
120 | - } |
|
121 | - |
|
122 | - $result = []; |
|
123 | - // sort by stime, the super share will be based on the least recent share |
|
124 | - foreach ($tmp as &$tmp2) { |
|
125 | - @usort($tmp2, function($a, $b) { |
|
126 | - if ($a->getShareTime() < $b->getShareTime()) { |
|
127 | - return -1; |
|
128 | - } |
|
129 | - return 1; |
|
130 | - }); |
|
131 | - $result[] = $tmp2; |
|
132 | - } |
|
133 | - |
|
134 | - return array_values($result); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Build super shares (virtual share) by grouping them by node id and target, |
|
139 | - * then for each group compute the super share and return it along with the matching |
|
140 | - * grouped shares. The most permissive permissions are used based on the permissions |
|
141 | - * of all shares within the group. |
|
142 | - * |
|
143 | - * @param \OCP\Share\IShare[] $allShares |
|
144 | - * @param \OCP\IUser $user user |
|
145 | - * @return array Tuple of [superShare, groupedShares] |
|
146 | - */ |
|
147 | - private function buildSuperShares(array $allShares, \OCP\IUser $user) { |
|
148 | - $result = []; |
|
149 | - |
|
150 | - $groupedShares = $this->groupShares($allShares); |
|
151 | - |
|
152 | - /** @var \OCP\Share\IShare[] $shares */ |
|
153 | - foreach ($groupedShares as $shares) { |
|
154 | - if (count($shares) === 0) { |
|
155 | - continue; |
|
156 | - } |
|
157 | - |
|
158 | - $superShare = $this->shareManager->newShare(); |
|
159 | - |
|
160 | - // compute super share based on first entry of the group |
|
161 | - $superShare->setId($shares[0]->getId()) |
|
162 | - ->setShareOwner($shares[0]->getShareOwner()) |
|
163 | - ->setNodeId($shares[0]->getNodeId()) |
|
164 | - ->setTarget($shares[0]->getTarget()); |
|
165 | - |
|
166 | - // use most permissive permissions |
|
167 | - $permissions = 0; |
|
168 | - foreach ($shares as $share) { |
|
169 | - $permissions |= $share->getPermissions(); |
|
170 | - if ($share->getTarget() !== $superShare->getTarget()) { |
|
171 | - // adjust target, for database consistency |
|
172 | - $share->setTarget($superShare->getTarget()); |
|
173 | - $this->shareManager->moveShare($share, $user->getUID()); |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - $superShare->setPermissions($permissions); |
|
178 | - |
|
179 | - $result[] = [$superShare, $shares]; |
|
180 | - } |
|
181 | - |
|
182 | - return $result; |
|
183 | - } |
|
36 | + /** |
|
37 | + * @var \OCP\IConfig |
|
38 | + */ |
|
39 | + protected $config; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var IManager |
|
43 | + */ |
|
44 | + protected $shareManager; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var ILogger |
|
48 | + */ |
|
49 | + protected $logger; |
|
50 | + |
|
51 | + /** |
|
52 | + * @param \OCP\IConfig $config |
|
53 | + * @param IManager $shareManager |
|
54 | + * @param ILogger $logger |
|
55 | + */ |
|
56 | + public function __construct(IConfig $config, IManager $shareManager, ILogger $logger) { |
|
57 | + $this->config = $config; |
|
58 | + $this->shareManager = $shareManager; |
|
59 | + $this->logger = $logger; |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Get all mountpoints applicable for the user and check for shares where we need to update the etags |
|
65 | + * |
|
66 | + * @param \OCP\IUser $user |
|
67 | + * @param \OCP\Files\Storage\IStorageFactory $storageFactory |
|
68 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
69 | + */ |
|
70 | + public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) { |
|
71 | + $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1); |
|
72 | + $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1)); |
|
73 | + // filter out excluded shares and group shares that includes self |
|
74 | + $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) { |
|
75 | + return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID(); |
|
76 | + }); |
|
77 | + |
|
78 | + $superShares = $this->buildSuperShares($shares, $user); |
|
79 | + |
|
80 | + $mounts = []; |
|
81 | + foreach ($superShares as $share) { |
|
82 | + try { |
|
83 | + $mounts[] = new SharedMount( |
|
84 | + '\OC\Files\Storage\Shared', |
|
85 | + $mounts, |
|
86 | + [ |
|
87 | + 'user' => $user->getUID(), |
|
88 | + // parent share |
|
89 | + 'superShare' => $share[0], |
|
90 | + // children/component of the superShare |
|
91 | + 'groupedShares' => $share[1], |
|
92 | + ], |
|
93 | + $storageFactory |
|
94 | + ); |
|
95 | + } catch (\Exception $e) { |
|
96 | + $this->logger->logException($e); |
|
97 | + $this->logger->error('Error while trying to create shared mount'); |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + // array_filter removes the null values from the array |
|
102 | + return array_filter($mounts); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Groups shares by path (nodeId) and target path |
|
107 | + * |
|
108 | + * @param \OCP\Share\IShare[] $shares |
|
109 | + * @return \OCP\Share\IShare[][] array of grouped shares, each element in the |
|
110 | + * array is a group which itself is an array of shares |
|
111 | + */ |
|
112 | + private function groupShares(array $shares) { |
|
113 | + $tmp = []; |
|
114 | + |
|
115 | + foreach ($shares as $share) { |
|
116 | + if (!isset($tmp[$share->getNodeId()])) { |
|
117 | + $tmp[$share->getNodeId()] = []; |
|
118 | + } |
|
119 | + $tmp[$share->getNodeId()][] = $share; |
|
120 | + } |
|
121 | + |
|
122 | + $result = []; |
|
123 | + // sort by stime, the super share will be based on the least recent share |
|
124 | + foreach ($tmp as &$tmp2) { |
|
125 | + @usort($tmp2, function($a, $b) { |
|
126 | + if ($a->getShareTime() < $b->getShareTime()) { |
|
127 | + return -1; |
|
128 | + } |
|
129 | + return 1; |
|
130 | + }); |
|
131 | + $result[] = $tmp2; |
|
132 | + } |
|
133 | + |
|
134 | + return array_values($result); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Build super shares (virtual share) by grouping them by node id and target, |
|
139 | + * then for each group compute the super share and return it along with the matching |
|
140 | + * grouped shares. The most permissive permissions are used based on the permissions |
|
141 | + * of all shares within the group. |
|
142 | + * |
|
143 | + * @param \OCP\Share\IShare[] $allShares |
|
144 | + * @param \OCP\IUser $user user |
|
145 | + * @return array Tuple of [superShare, groupedShares] |
|
146 | + */ |
|
147 | + private function buildSuperShares(array $allShares, \OCP\IUser $user) { |
|
148 | + $result = []; |
|
149 | + |
|
150 | + $groupedShares = $this->groupShares($allShares); |
|
151 | + |
|
152 | + /** @var \OCP\Share\IShare[] $shares */ |
|
153 | + foreach ($groupedShares as $shares) { |
|
154 | + if (count($shares) === 0) { |
|
155 | + continue; |
|
156 | + } |
|
157 | + |
|
158 | + $superShare = $this->shareManager->newShare(); |
|
159 | + |
|
160 | + // compute super share based on first entry of the group |
|
161 | + $superShare->setId($shares[0]->getId()) |
|
162 | + ->setShareOwner($shares[0]->getShareOwner()) |
|
163 | + ->setNodeId($shares[0]->getNodeId()) |
|
164 | + ->setTarget($shares[0]->getTarget()); |
|
165 | + |
|
166 | + // use most permissive permissions |
|
167 | + $permissions = 0; |
|
168 | + foreach ($shares as $share) { |
|
169 | + $permissions |= $share->getPermissions(); |
|
170 | + if ($share->getTarget() !== $superShare->getTarget()) { |
|
171 | + // adjust target, for database consistency |
|
172 | + $share->setTarget($superShare->getTarget()); |
|
173 | + $this->shareManager->moveShare($share, $user->getUID()); |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + $superShare->setPermissions($permissions); |
|
178 | + |
|
179 | + $result[] = [$superShare, $shares]; |
|
180 | + } |
|
181 | + |
|
182 | + return $result; |
|
183 | + } |
|
184 | 184 | } |
@@ -28,9 +28,9 @@ |
||
28 | 28 | $route = isset($_GET['download']) ? 'files_sharing.sharecontroller.downloadShare' : 'files_sharing.sharecontroller.showShare'; |
29 | 29 | |
30 | 30 | if($token !== '') { |
31 | - OC_Response::redirect($urlGenerator->linkToRoute($route, array('token' => $token))); |
|
31 | + OC_Response::redirect($urlGenerator->linkToRoute($route, array('token' => $token))); |
|
32 | 32 | } else { |
33 | - header('HTTP/1.0 404 Not Found'); |
|
34 | - $tmpl = new OCP\Template('', '404', 'guest'); |
|
35 | - print_unescaped($tmpl->fetchPage()); |
|
33 | + header('HTTP/1.0 404 Not Found'); |
|
34 | + $tmpl = new OCP\Template('', '404', 'guest'); |
|
35 | + print_unescaped($tmpl->fetchPage()); |
|
36 | 36 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | $token = isset($_GET['t']) ? $_GET['t'] : ''; |
28 | 28 | $route = isset($_GET['download']) ? 'files_sharing.sharecontroller.downloadShare' : 'files_sharing.sharecontroller.showShare'; |
29 | 29 | |
30 | -if($token !== '') { |
|
30 | +if ($token !== '') { |
|
31 | 31 | OC_Response::redirect($urlGenerator->linkToRoute($route, array('token' => $token))); |
32 | 32 | } else { |
33 | 33 | header('HTTP/1.0 404 Not Found'); |
@@ -48,11 +48,20 @@ |
||
48 | 48 | <br /> |
49 | 49 | <?php p($l->t('Notify members of the following groups about available updates:')); ?> |
50 | 50 | <input name="oca_updatenotification_groups_list" type="hidden" id="oca_updatenotification_groups_list" value="<?php p($_['notify_groups']) ?>" style="width: 400px"> |
51 | - <em class="<?php if (!in_array($currentChannel, ['daily', 'git'])) p('hidden'); ?>"> |
|
51 | + <em class="<?php if (!in_array($currentChannel, ['daily', 'git'])) { |
|
52 | + p('hidden'); |
|
53 | +} |
|
54 | +?>"> |
|
52 | 55 | <br /> |
53 | 56 | <?php p($l->t('Only notification for app updates are available.')); ?> |
54 | - <?php if ($currentChannel === 'daily') p($l->t('The selected update channel makes dedicated notifications for the server obsolete.')); ?> |
|
55 | - <?php if ($currentChannel === 'git') p($l->t('The selected update channel does not support updates of the server.')); ?> |
|
57 | + <?php if ($currentChannel === 'daily') { |
|
58 | + p($l->t('The selected update channel makes dedicated notifications for the server obsolete.')); |
|
59 | +} |
|
60 | +?> |
|
61 | + <?php if ($currentChannel === 'git') { |
|
62 | + p($l->t('The selected update channel does not support updates of the server.')); |
|
63 | +} |
|
64 | +?> |
|
56 | 65 | </em> |
57 | 66 | </p> |
58 | 67 | </form> |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | - script('updatenotification', 'admin'); |
|
2 | + script('updatenotification', 'admin'); |
|
3 | 3 | |
4 | - /** @var array $_ */ |
|
5 | - /** @var bool $isNewVersionAvailable */ |
|
6 | - $isNewVersionAvailable = $_['isNewVersionAvailable']; |
|
7 | - /** @var string $newVersionString */ |
|
8 | - $newVersionString = $_['newVersionString']; |
|
9 | - /** @var string $lastCheckedDate */ |
|
10 | - $lastCheckedDate = $_['lastChecked']; |
|
11 | - /** @var array $channels */ |
|
12 | - $channels = $_['channels']; |
|
13 | - /** @var string $currentChannel */ |
|
14 | - $currentChannel = $_['currentChannel']; |
|
4 | + /** @var array $_ */ |
|
5 | + /** @var bool $isNewVersionAvailable */ |
|
6 | + $isNewVersionAvailable = $_['isNewVersionAvailable']; |
|
7 | + /** @var string $newVersionString */ |
|
8 | + $newVersionString = $_['newVersionString']; |
|
9 | + /** @var string $lastCheckedDate */ |
|
10 | + $lastCheckedDate = $_['lastChecked']; |
|
11 | + /** @var array $channels */ |
|
12 | + $channels = $_['channels']; |
|
13 | + /** @var string $currentChannel */ |
|
14 | + $currentChannel = $_['currentChannel']; |
|
15 | 15 | ?> |
16 | 16 | <form id="oca_updatenotification_section" class="followupsection"> |
17 | 17 |
@@ -15,13 +15,13 @@ discard block |
||
15 | 15 | ?> |
16 | 16 | <form id="oca_updatenotification_section" class="followupsection"> |
17 | 17 | |
18 | - <?php if($_['outdatedPHP'] === true) { ?> |
|
18 | + <?php if ($_['outdatedPHP'] === true) { ?> |
|
19 | 19 | <p class="warning" style="margin-bottom: 15px;"> |
20 | - <?php p($l->t('You are running PHP %s. To allow you to upgrade to Nextcloud 11 and higher you need to run at least PHP 5.6. Once you upgraded your PHP version you will be able to receive update notifications for these newer versions.', [PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION])); ?> |
|
20 | + <?php p($l->t('You are running PHP %s. To allow you to upgrade to Nextcloud 11 and higher you need to run at least PHP 5.6. Once you upgraded your PHP version you will be able to receive update notifications for these newer versions.', [PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION])); ?> |
|
21 | 21 | </p> |
22 | 22 | <?php } ?> |
23 | 23 | |
24 | - <?php if($isNewVersionAvailable === true) { ?> |
|
24 | + <?php if ($isNewVersionAvailable === true) { ?> |
|
25 | 25 | <strong><?php p($l->t('A new version is available: %s', [$newVersionString])); ?></strong> |
26 | 26 | <?php if ($_['updaterEnabled']) { ?> |
27 | 27 | <input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>"> |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | <label for="release-channel"><?php p($l->t('Update channel:')) ?></label> |
39 | 39 | <select id="release-channel"> |
40 | 40 | <option value="<?php p($currentChannel); ?>"><?php p($currentChannel); ?></option> |
41 | - <?php foreach ($channels as $channel => $channelTitle){ ?> |
|
41 | + <?php foreach ($channels as $channel => $channelTitle) { ?> |
|
42 | 42 | <option value="<?php p($channelTitle) ?>"> |
43 | 43 | <?php p($channelTitle) ?> |
44 | 44 | </option> |
@@ -99,7 +99,7 @@ |
||
99 | 99 | $currentChannel = \OCP\Util::getChannel(); |
100 | 100 | |
101 | 101 | // Remove the currently used channel from the channels list |
102 | - if(($key = array_search($currentChannel, $channels)) !== false) { |
|
102 | + if (($key = array_search($currentChannel, $channels)) !== false) { |
|
103 | 103 | unset($channels[$key]); |
104 | 104 | } |
105 | 105 | $updateState = $this->updateChecker->getUpdateState(); |
@@ -37,139 +37,139 @@ |
||
37 | 37 | use OCP\Settings\ISettings; |
38 | 38 | |
39 | 39 | class AdminController extends Controller implements ISettings { |
40 | - /** @var IJobList */ |
|
41 | - private $jobList; |
|
42 | - /** @var ISecureRandom */ |
|
43 | - private $secureRandom; |
|
44 | - /** @var IConfig */ |
|
45 | - private $config; |
|
46 | - /** @var ITimeFactory */ |
|
47 | - private $timeFactory; |
|
48 | - /** @var UpdateChecker */ |
|
49 | - private $updateChecker; |
|
50 | - /** @var IL10N */ |
|
51 | - private $l10n; |
|
52 | - /** @var IDateTimeFormatter */ |
|
53 | - private $dateTimeFormatter; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $appName |
|
57 | - * @param IRequest $request |
|
58 | - * @param IJobList $jobList |
|
59 | - * @param ISecureRandom $secureRandom |
|
60 | - * @param IConfig $config |
|
61 | - * @param ITimeFactory $timeFactory |
|
62 | - * @param IL10N $l10n |
|
63 | - * @param UpdateChecker $updateChecker |
|
64 | - * @param IDateTimeFormatter $dateTimeFormatter |
|
65 | - */ |
|
66 | - public function __construct($appName, |
|
67 | - IRequest $request, |
|
68 | - IJobList $jobList, |
|
69 | - ISecureRandom $secureRandom, |
|
70 | - IConfig $config, |
|
71 | - ITimeFactory $timeFactory, |
|
72 | - IL10N $l10n, |
|
73 | - UpdateChecker $updateChecker, |
|
74 | - IDateTimeFormatter $dateTimeFormatter) { |
|
75 | - parent::__construct($appName, $request); |
|
76 | - $this->jobList = $jobList; |
|
77 | - $this->secureRandom = $secureRandom; |
|
78 | - $this->config = $config; |
|
79 | - $this->timeFactory = $timeFactory; |
|
80 | - $this->l10n = $l10n; |
|
81 | - $this->updateChecker = $updateChecker; |
|
82 | - $this->dateTimeFormatter = $dateTimeFormatter; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @return TemplateResponse |
|
87 | - */ |
|
88 | - public function displayPanel() { |
|
89 | - $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime( |
|
90 | - $this->config->getAppValue('core', 'lastupdatedat') |
|
91 | - ); |
|
92 | - |
|
93 | - $channels = [ |
|
94 | - 'daily', |
|
95 | - 'beta', |
|
96 | - 'stable', |
|
97 | - 'production', |
|
98 | - ]; |
|
99 | - $currentChannel = \OCP\Util::getChannel(); |
|
100 | - |
|
101 | - // Remove the currently used channel from the channels list |
|
102 | - if(($key = array_search($currentChannel, $channels)) !== false) { |
|
103 | - unset($channels[$key]); |
|
104 | - } |
|
105 | - $updateState = $this->updateChecker->getUpdateState(); |
|
106 | - |
|
107 | - $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
108 | - |
|
109 | - $params = [ |
|
110 | - 'isNewVersionAvailable' => !empty($updateState['updateAvailable']), |
|
111 | - 'lastChecked' => $lastUpdateCheck, |
|
112 | - 'currentChannel' => $currentChannel, |
|
113 | - 'channels' => $channels, |
|
114 | - 'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'], |
|
115 | - 'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'], |
|
116 | - 'updaterEnabled' => (empty($updateState['updaterEnabled'])) ? false : $updateState['updaterEnabled'], |
|
117 | - 'outdatedPHP' => version_compare(PHP_VERSION, '5.6') === -1, |
|
118 | - 'notify_groups' => implode('|', $notifyGroups), |
|
119 | - ]; |
|
120 | - |
|
121 | - return new TemplateResponse($this->appName, 'admin', $params, ''); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @UseSession |
|
126 | - * |
|
127 | - * @param string $channel |
|
128 | - * @return DataResponse |
|
129 | - */ |
|
130 | - public function setChannel($channel) { |
|
131 | - \OCP\Util::setChannel($channel); |
|
132 | - $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
133 | - return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @return DataResponse |
|
138 | - */ |
|
139 | - public function createCredentials() { |
|
140 | - // Create a new job and store the creation date |
|
141 | - $this->jobList->add('OCA\UpdateNotification\ResetTokenBackgroundJob'); |
|
142 | - $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); |
|
143 | - |
|
144 | - // Create a new token |
|
145 | - $newToken = $this->secureRandom->generate(64); |
|
146 | - $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); |
|
147 | - |
|
148 | - return new DataResponse($newToken); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
153 | - */ |
|
154 | - public function getForm() { |
|
155 | - return $this->displayPanel(); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return string the section ID, e.g. 'sharing' |
|
160 | - */ |
|
161 | - public function getSection() { |
|
162 | - return 'server'; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @return int whether the form should be rather on the top or bottom of |
|
167 | - * the admin section. The forms are arranged in ascending order of the |
|
168 | - * priority values. It is required to return a value between 0 and 100. |
|
169 | - * |
|
170 | - * E.g.: 70 |
|
171 | - */ |
|
172 | - public function getPriority() { |
|
173 | - return 1; |
|
174 | - } |
|
40 | + /** @var IJobList */ |
|
41 | + private $jobList; |
|
42 | + /** @var ISecureRandom */ |
|
43 | + private $secureRandom; |
|
44 | + /** @var IConfig */ |
|
45 | + private $config; |
|
46 | + /** @var ITimeFactory */ |
|
47 | + private $timeFactory; |
|
48 | + /** @var UpdateChecker */ |
|
49 | + private $updateChecker; |
|
50 | + /** @var IL10N */ |
|
51 | + private $l10n; |
|
52 | + /** @var IDateTimeFormatter */ |
|
53 | + private $dateTimeFormatter; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $appName |
|
57 | + * @param IRequest $request |
|
58 | + * @param IJobList $jobList |
|
59 | + * @param ISecureRandom $secureRandom |
|
60 | + * @param IConfig $config |
|
61 | + * @param ITimeFactory $timeFactory |
|
62 | + * @param IL10N $l10n |
|
63 | + * @param UpdateChecker $updateChecker |
|
64 | + * @param IDateTimeFormatter $dateTimeFormatter |
|
65 | + */ |
|
66 | + public function __construct($appName, |
|
67 | + IRequest $request, |
|
68 | + IJobList $jobList, |
|
69 | + ISecureRandom $secureRandom, |
|
70 | + IConfig $config, |
|
71 | + ITimeFactory $timeFactory, |
|
72 | + IL10N $l10n, |
|
73 | + UpdateChecker $updateChecker, |
|
74 | + IDateTimeFormatter $dateTimeFormatter) { |
|
75 | + parent::__construct($appName, $request); |
|
76 | + $this->jobList = $jobList; |
|
77 | + $this->secureRandom = $secureRandom; |
|
78 | + $this->config = $config; |
|
79 | + $this->timeFactory = $timeFactory; |
|
80 | + $this->l10n = $l10n; |
|
81 | + $this->updateChecker = $updateChecker; |
|
82 | + $this->dateTimeFormatter = $dateTimeFormatter; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @return TemplateResponse |
|
87 | + */ |
|
88 | + public function displayPanel() { |
|
89 | + $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime( |
|
90 | + $this->config->getAppValue('core', 'lastupdatedat') |
|
91 | + ); |
|
92 | + |
|
93 | + $channels = [ |
|
94 | + 'daily', |
|
95 | + 'beta', |
|
96 | + 'stable', |
|
97 | + 'production', |
|
98 | + ]; |
|
99 | + $currentChannel = \OCP\Util::getChannel(); |
|
100 | + |
|
101 | + // Remove the currently used channel from the channels list |
|
102 | + if(($key = array_search($currentChannel, $channels)) !== false) { |
|
103 | + unset($channels[$key]); |
|
104 | + } |
|
105 | + $updateState = $this->updateChecker->getUpdateState(); |
|
106 | + |
|
107 | + $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
108 | + |
|
109 | + $params = [ |
|
110 | + 'isNewVersionAvailable' => !empty($updateState['updateAvailable']), |
|
111 | + 'lastChecked' => $lastUpdateCheck, |
|
112 | + 'currentChannel' => $currentChannel, |
|
113 | + 'channels' => $channels, |
|
114 | + 'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'], |
|
115 | + 'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'], |
|
116 | + 'updaterEnabled' => (empty($updateState['updaterEnabled'])) ? false : $updateState['updaterEnabled'], |
|
117 | + 'outdatedPHP' => version_compare(PHP_VERSION, '5.6') === -1, |
|
118 | + 'notify_groups' => implode('|', $notifyGroups), |
|
119 | + ]; |
|
120 | + |
|
121 | + return new TemplateResponse($this->appName, 'admin', $params, ''); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @UseSession |
|
126 | + * |
|
127 | + * @param string $channel |
|
128 | + * @return DataResponse |
|
129 | + */ |
|
130 | + public function setChannel($channel) { |
|
131 | + \OCP\Util::setChannel($channel); |
|
132 | + $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
133 | + return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @return DataResponse |
|
138 | + */ |
|
139 | + public function createCredentials() { |
|
140 | + // Create a new job and store the creation date |
|
141 | + $this->jobList->add('OCA\UpdateNotification\ResetTokenBackgroundJob'); |
|
142 | + $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); |
|
143 | + |
|
144 | + // Create a new token |
|
145 | + $newToken = $this->secureRandom->generate(64); |
|
146 | + $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); |
|
147 | + |
|
148 | + return new DataResponse($newToken); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
153 | + */ |
|
154 | + public function getForm() { |
|
155 | + return $this->displayPanel(); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return string the section ID, e.g. 'sharing' |
|
160 | + */ |
|
161 | + public function getSection() { |
|
162 | + return 'server'; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @return int whether the form should be rather on the top or bottom of |
|
167 | + * the admin section. The forms are arranged in ascending order of the |
|
168 | + * priority values. It is required to return a value between 0 and 100. |
|
169 | + * |
|
170 | + * E.g.: 70 |
|
171 | + */ |
|
172 | + public function getPriority() { |
|
173 | + return 1; |
|
174 | + } |
|
175 | 175 | } |
@@ -26,48 +26,48 @@ |
||
26 | 26 | use OC\Updater\VersionCheck; |
27 | 27 | |
28 | 28 | class UpdateChecker { |
29 | - /** @var VersionCheck */ |
|
30 | - private $updater; |
|
29 | + /** @var VersionCheck */ |
|
30 | + private $updater; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param VersionCheck $updater |
|
34 | - */ |
|
35 | - public function __construct(VersionCheck $updater) { |
|
36 | - $this->updater = $updater; |
|
37 | - } |
|
32 | + /** |
|
33 | + * @param VersionCheck $updater |
|
34 | + */ |
|
35 | + public function __construct(VersionCheck $updater) { |
|
36 | + $this->updater = $updater; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return array |
|
41 | - */ |
|
42 | - public function getUpdateState() { |
|
43 | - $data = $this->updater->check(); |
|
44 | - $result = []; |
|
39 | + /** |
|
40 | + * @return array |
|
41 | + */ |
|
42 | + public function getUpdateState() { |
|
43 | + $data = $this->updater->check(); |
|
44 | + $result = []; |
|
45 | 45 | |
46 | - if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) { |
|
47 | - $result['updateAvailable'] = true; |
|
48 | - $result['updateVersion'] = $data['versionstring']; |
|
49 | - $result['updaterEnabled'] = $data['autoupdater'] === '1'; |
|
50 | - if(substr($data['web'], 0, 8) === 'https://') { |
|
51 | - $result['updateLink'] = $data['web']; |
|
52 | - } |
|
53 | - if(substr($data['url'], 0, 8) === 'https://') { |
|
54 | - $result['downloadLink'] = $data['url']; |
|
55 | - } |
|
46 | + if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) { |
|
47 | + $result['updateAvailable'] = true; |
|
48 | + $result['updateVersion'] = $data['versionstring']; |
|
49 | + $result['updaterEnabled'] = $data['autoupdater'] === '1'; |
|
50 | + if(substr($data['web'], 0, 8) === 'https://') { |
|
51 | + $result['updateLink'] = $data['web']; |
|
52 | + } |
|
53 | + if(substr($data['url'], 0, 8) === 'https://') { |
|
54 | + $result['downloadLink'] = $data['url']; |
|
55 | + } |
|
56 | 56 | |
57 | - return $result; |
|
58 | - } |
|
57 | + return $result; |
|
58 | + } |
|
59 | 59 | |
60 | - return []; |
|
61 | - } |
|
60 | + return []; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param array $data |
|
65 | - */ |
|
66 | - public function getJavaScript(array $data) { |
|
67 | - $data['array']['oc_updateState'] = json_encode([ |
|
68 | - 'updateAvailable' => true, |
|
69 | - 'updateVersion' => $this->getUpdateState()['updateVersion'], |
|
70 | - 'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '', |
|
71 | - ]); |
|
72 | - } |
|
63 | + /** |
|
64 | + * @param array $data |
|
65 | + */ |
|
66 | + public function getJavaScript(array $data) { |
|
67 | + $data['array']['oc_updateState'] = json_encode([ |
|
68 | + 'updateAvailable' => true, |
|
69 | + 'updateVersion' => $this->getUpdateState()['updateVersion'], |
|
70 | + 'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '', |
|
71 | + ]); |
|
72 | + } |
|
73 | 73 | } |
@@ -43,14 +43,14 @@ discard block |
||
43 | 43 | $data = $this->updater->check(); |
44 | 44 | $result = []; |
45 | 45 | |
46 | - if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) { |
|
46 | + if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) { |
|
47 | 47 | $result['updateAvailable'] = true; |
48 | 48 | $result['updateVersion'] = $data['versionstring']; |
49 | 49 | $result['updaterEnabled'] = $data['autoupdater'] === '1'; |
50 | - if(substr($data['web'], 0, 8) === 'https://') { |
|
50 | + if (substr($data['web'], 0, 8) === 'https://') { |
|
51 | 51 | $result['updateLink'] = $data['web']; |
52 | 52 | } |
53 | - if(substr($data['url'], 0, 8) === 'https://') { |
|
53 | + if (substr($data['url'], 0, 8) === 'https://') { |
|
54 | 54 | $result['downloadLink'] = $data['url']; |
55 | 55 | } |
56 | 56 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @param array $data |
65 | 65 | */ |
66 | 66 | public function getJavaScript(array $data) { |
67 | - $data['array']['oc_updateState'] = json_encode([ |
|
67 | + $data['array']['oc_updateState'] = json_encode([ |
|
68 | 68 | 'updateAvailable' => true, |
69 | 69 | 'updateVersion' => $this->getUpdateState()['updateVersion'], |
70 | 70 | 'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '', |
@@ -30,27 +30,27 @@ |
||
30 | 30 | use OCP\AppFramework\IAppContainer; |
31 | 31 | |
32 | 32 | class Application extends App { |
33 | - public function __construct (array $urlParams = array()) { |
|
34 | - parent::__construct('updatenotification', $urlParams); |
|
35 | - $container = $this->getContainer(); |
|
33 | + public function __construct (array $urlParams = array()) { |
|
34 | + parent::__construct('updatenotification', $urlParams); |
|
35 | + $container = $this->getContainer(); |
|
36 | 36 | |
37 | - $container->registerService('AdminController', function(IAppContainer $c) { |
|
38 | - $updater = new \OC\Updater\VersionCheck( |
|
39 | - \OC::$server->getHTTPClientService(), |
|
40 | - \OC::$server->getConfig() |
|
41 | - ); |
|
42 | - return new AdminController( |
|
43 | - $c->query('AppName'), |
|
44 | - $c->query('Request'), |
|
45 | - $c->getServer()->getJobList(), |
|
46 | - $c->getServer()->getSecureRandom(), |
|
47 | - $c->getServer()->getConfig(), |
|
48 | - new TimeFactory(), |
|
49 | - $c->getServer()->getL10N($c->query('AppName')), |
|
50 | - new UpdateChecker($updater), |
|
51 | - $c->getServer()->getDateTimeFormatter() |
|
52 | - ); |
|
53 | - }); |
|
54 | - } |
|
37 | + $container->registerService('AdminController', function(IAppContainer $c) { |
|
38 | + $updater = new \OC\Updater\VersionCheck( |
|
39 | + \OC::$server->getHTTPClientService(), |
|
40 | + \OC::$server->getConfig() |
|
41 | + ); |
|
42 | + return new AdminController( |
|
43 | + $c->query('AppName'), |
|
44 | + $c->query('Request'), |
|
45 | + $c->getServer()->getJobList(), |
|
46 | + $c->getServer()->getSecureRandom(), |
|
47 | + $c->getServer()->getConfig(), |
|
48 | + new TimeFactory(), |
|
49 | + $c->getServer()->getL10N($c->query('AppName')), |
|
50 | + new UpdateChecker($updater), |
|
51 | + $c->getServer()->getDateTimeFormatter() |
|
52 | + ); |
|
53 | + }); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | } |
@@ -30,7 +30,7 @@ |
||
30 | 30 | use OCP\AppFramework\IAppContainer; |
31 | 31 | |
32 | 32 | class Application extends App { |
33 | - public function __construct (array $urlParams = array()) { |
|
33 | + public function __construct(array $urlParams = array()) { |
|
34 | 34 | parent::__construct('updatenotification', $urlParams); |
35 | 35 | $container = $this->getContainer(); |
36 | 36 |