Skip to content

Commit 2f812ce

Browse files
committed
cleaning
Signed-off-by: Maxence Lange <[email protected]>
1 parent 67e06b6 commit 2f812ce

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

appinfo/app.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@
2929

3030
namespace OCA\FilesLock\AppInfo;
3131

32+
use OC;
33+
use OCP\AppFramework\QueryException;
34+
3235
require_once __DIR__ . '/autoload.php';
3336

3437
/** @var Application $app */
35-
$app = \OC::$server->query(Application::class);
36-
$app->registerHooks();
38+
try {
39+
$app = OC::$server->query(Application::class);
40+
$app->registerHooks();
41+
} catch (QueryException $e) {
42+
OC::$server->getLogger()->log(1, 'failed to load Application');
43+
}
3744

lib/AppInfo/Application.php

+15-11
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
namespace OCA\FilesLock\AppInfo;
3131

3232

33-
use OC;
3433
use OC\Files\Filesystem;
3534
use OCA\DAV\Connector\Sabre\CachingTree;
3635
use OCA\DAV\Connector\Sabre\ObjectTree;
@@ -41,12 +40,18 @@
4140
use OCA\FilesLock\Storage\LockWrapper;
4241
use OCP\AppFramework\App;
4342
use OCP\AppFramework\QueryException;
43+
use OCP\EventDispatcher\IEventDispatcher;
4444
use OCP\IUserSession;
4545
use OCP\SabrePluginEvent;
4646
use OCP\Util;
4747
use Sabre\DAV\Locks\Plugin;
4848

4949

50+
/**
51+
* Class Application
52+
*
53+
* @package OCA\FilesLock\AppInfo
54+
*/
5055
class Application extends App {
5156

5257

@@ -58,6 +63,9 @@ class Application extends App {
5863
const DAV_PROPERTY_LOCK_TIME = '{http://nextcloud.org/ns}lock-time';
5964

6065

66+
/** @var IEventDispatcher */
67+
private $eventDispatcher;
68+
6169
/** @var IUserSession */
6270
private $userSession;
6371

@@ -83,18 +91,18 @@ public function __construct(array $params = array()) {
8391
*
8492
*/
8593
public function registerHooks() {
86-
$eventDispatcher = OC::$server->getEventDispatcher();
8794
$c = $this->getContainer();
8895
try {
89-
$this->userSession = OC::$server->getUserSession();
96+
$this->eventDispatcher = $c->query(IEventDispatcher::class);
97+
$this->userSession = $c->query(IUserSession::class);
9098
$this->fileService = $c->query(FileService::class);
9199
$this->lockService = $c->query(LockService::class);
92100
$this->miscService = $c->query(MiscService::class);
93101
} catch (QueryException $e) {
94102
return;
95103
}
96104

97-
$eventDispatcher->addListener(
105+
$this->eventDispatcher->addListener(
98106
'OCA\Files::loadAdditionalScripts',
99107
function() {
100108
Util::addScript(self::APP_NAME, 'files');
@@ -103,7 +111,7 @@ function() {
103111
);
104112

105113

106-
$eventDispatcher->addListener(
114+
$this->eventDispatcher->addListener(
107115
'OCA\DAV\Connector\Sabre::addPlugin', function(SabrePluginEvent $e) {
108116
$server = $e->getServer();
109117
$absolute = false;
@@ -136,16 +144,12 @@ function() {
136144
* @internal
137145
*/
138146
public function addStorageWrapper() {
139-
$userSession = $this->getContainer()
140-
->getServer()
141-
->getUserSession();
142-
143147
Filesystem::addStorageWrapper(
144-
'files_lock', function($mountPoint, $storage) use ($userSession) {
148+
'files_lock', function($mountPoint, $storage) {
145149
return new LockWrapper(
146150
[
147151
'storage' => $storage,
148-
'user_session' => $userSession,
152+
'user_session' => $this->userSession,
149153
'file_service' => $this->fileService,
150154
'lock_service' => $this->lockService,
151155
'misc_service' => $this->miscService

lib/Db/LocksRequestBuilder.php

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
use daita\MySmallPhpTools\Traits\TArrayTools;
3535
use OCA\FilesLock\Exceptions\LockNotFoundException;
3636
use OCA\FilesLock\Model\FileLock;
37-
use OCA\FilesLock\Service\ConfigService;
3837

3938

4039
/**

lib/Service/LockService.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use OCP\Files\Node;
4545
use OCP\Files\NotFoundException;
4646
use OCP\IUser;
47+
use OCP\IUserManager;
4748
use Sabre\DAV\INode;
4849
use Sabre\DAV\PropFind;
4950

@@ -65,6 +66,9 @@ class LockService {
6566
/** @var string */
6667
private $userId;
6768

69+
/** @var IUserManager */
70+
private $userManager;
71+
6872
/** @var LocksRequest */
6973
private $locksRequest;
7074

@@ -89,10 +93,11 @@ class LockService {
8993

9094

9195
public function __construct(
92-
$userId, LocksRequest $locksRequest, FileService $fileService, ConfigService $configService,
93-
MiscService $miscService
96+
$userId, IUserManager $userManager, LocksRequest $locksRequest, FileService $fileService,
97+
ConfigService $configService, MiscService $miscService
9498
) {
9599
$this->userId = $userId;
100+
$this->userManager = $userManager;
96101
$this->locksRequest = $locksRequest;
97102
$this->fileService = $fileService;
98103
$this->configService = $configService;
@@ -149,6 +154,8 @@ public function propFind(PropFind $propFind, INode $node) {
149154
if ($lock !== false) {
150155
return $lock->getUserId();
151156
}
157+
158+
return null;
152159
}
153160
);
154161

@@ -159,6 +166,8 @@ public function propFind(PropFind $propFind, INode $node) {
159166
if ($lock !== false) {
160167
return $lock->getCreation();
161168
}
169+
170+
return 0;
162171
}
163172
);
164173

@@ -167,12 +176,13 @@ public function propFind(PropFind $propFind, INode $node) {
167176
$lock = $this->getLockForNodeId($nodeId);
168177

169178
if ($lock !== false) {
170-
$user = \OC::$server->getUserManager()
171-
->get($lock->getUserId());
179+
$user = $this->userManager->get($lock->getUserId());
172180
if ($user !== null) {
173181
return $user->getDisplayName();
174182
}
175183
}
184+
185+
return null;
176186
}
177187
);
178188
}

lib/Storage/LockWrapper.php

-5
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ protected function checkPermissions($path, $permissions): bool {
8686
return true;
8787
}
8888

89-
/** @var FileLock $lock */
90-
if (!$this->isLocked($path, $userId, $lock)) {
91-
return true;
92-
}
93-
9489
switch ($permissions) {
9590
case Constants::PERMISSION_READ:
9691
return true;

0 commit comments

Comments
 (0)