|
38 | 38 | use OCA\FilesLock\Model\FileLock; |
39 | 39 | use OCA\FilesLock\Tools\Traits\TLogger; |
40 | 40 | use OCA\FilesLock\Tools\Traits\TStringTools; |
| 41 | +use OCA\GroupFolders\Mount\GroupMountPoint; |
41 | 42 | use OCP\App\IAppManager; |
42 | 43 | use OCP\EventDispatcher\IEventDispatcher; |
43 | 44 | use OCP\Files\InvalidPathException; |
44 | 45 | use OCP\Files\Lock\ILock; |
45 | 46 | use OCP\Files\Lock\LockContext; |
46 | 47 | use OCP\Files\Lock\OwnerLockedException; |
| 48 | +use OCP\Files\Node; |
47 | 49 | use OCP\Files\NotFoundException; |
| 50 | +use OCP\IGroupManager; |
48 | 51 | use OCP\IL10N; |
| 52 | +use OCP\IUser; |
49 | 53 | use OCP\IUserManager; |
50 | 54 |
|
51 | 55 | /** |
|
56 | 60 | class LockService { |
57 | 61 | public const PREFIX = 'files_lock'; |
58 | 62 |
|
59 | | - |
60 | 63 | use TStringTools; |
61 | 64 | use TLogger; |
62 | 65 |
|
63 | | - |
64 | | - private ?string $userId; |
65 | | - private IUserManager $userManager; |
66 | | - private IL10N $l10n; |
67 | | - private LocksRequest $locksRequest; |
68 | | - private FileService $fileService; |
69 | | - private ConfigService $configService; |
70 | | - private IAppManager $appManager; |
71 | | - private IEventDispatcher $eventDispatcher; |
72 | | - |
73 | | - |
74 | 66 | private array $locks = []; |
75 | 67 | private bool $lockRetrieved = false; |
76 | 68 | private array $lockCache = []; |
77 | 69 | private ?array $directEditors = null; |
78 | 70 | private bool $allowUserOverride = false; |
79 | 71 |
|
80 | | - |
81 | 72 | public function __construct( |
82 | | - $userId, |
83 | | - IL10N $l10n, |
84 | | - IUserManager $userManager, |
85 | | - LocksRequest $locksRequest, |
86 | | - FileService $fileService, |
87 | | - ConfigService $configService, |
88 | | - IAppManager $appManager, |
89 | | - IEventDispatcher $eventDispatcher |
| 73 | + private ?string $userId, |
| 74 | + private IL10N $l10n, |
| 75 | + private IUserManager $userManager, |
| 76 | + private IGroupManager $groupManager, |
| 77 | + private LocksRequest $locksRequest, |
| 78 | + private FileService $fileService, |
| 79 | + private ConfigService $configService, |
| 80 | + private IAppManager $appManager, |
| 81 | + private IEventDispatcher $eventDispatcher |
90 | 82 | ) { |
91 | | - $this->userId = $userId; |
92 | | - $this->l10n = $l10n; |
93 | | - $this->userManager = $userManager; |
94 | | - $this->locksRequest = $locksRequest; |
95 | | - $this->fileService = $fileService; |
96 | | - $this->configService = $configService; |
97 | | - $this->appManager = $appManager; |
98 | | - $this->eventDispatcher = $eventDispatcher; |
99 | | - |
100 | 83 | $this->setup('app', 'files_lock'); |
101 | 84 | } |
102 | 85 |
|
@@ -402,4 +385,24 @@ private function propagateEtag(LockContext $lockContext): void { |
402 | 385 | ]); |
403 | 386 | $node->getStorage()->getUpdater()->propagate($node->getInternalPath(), $node->getMTime()); |
404 | 387 | } |
| 388 | + |
| 389 | + public function isLockManager(IUser $user, ?Node $node): bool { |
| 390 | + if ($this->groupManager->isAdmin($user->getUID())) { |
| 391 | + return true; |
| 392 | + } |
| 393 | + |
| 394 | + $lockManagerGroups = explode('|', $this->configService->getAppValue('lock_managers') ?? ''); |
| 395 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
| 396 | + $matchGroups = !empty(array_intersect($lockManagerGroups, $userGroups)); |
| 397 | + |
| 398 | + if ($matchGroups) { |
| 399 | + return true; |
| 400 | + } |
| 401 | + |
| 402 | + if ($node && $node->getOwner()?->getUID() === $user?->getUID() && !$node->getMountPoint() instanceof GroupMountPoint) { |
| 403 | + return true; |
| 404 | + } |
| 405 | + |
| 406 | + return false; |
| 407 | + } |
405 | 408 | } |
0 commit comments