|
34 | 34 | use OC\Files\Storage\Wrapper\PermissionsMask; |
35 | 35 | use OC\Files\Storage\Wrapper\Quota; |
36 | 36 | use OC\Lockdown\Filesystem\NullStorage; |
| 37 | +use OC\Share\Share; |
| 38 | +use OC\Share20\ShareDisableChecker; |
37 | 39 | use OC_App; |
38 | 40 | use OC_Hook; |
39 | 41 | use OC_Util; |
| 42 | +use OCA\Files_Sharing\ISharedStorage; |
40 | 43 | use OCP\Constants; |
41 | 44 | use OCP\Diagnostics\IEventLogger; |
42 | 45 | use OCP\EventDispatcher\IEventDispatcher; |
|
64 | 67 |
|
65 | 68 | class SetupManager { |
66 | 69 | private bool $rootSetup = false; |
67 | | - private IEventLogger $eventLogger; |
68 | | - private MountProviderCollection $mountProviderCollection; |
69 | | - private IMountManager $mountManager; |
70 | | - private IUserManager $userManager; |
71 | 70 | // List of users for which at least one mount is setup |
72 | 71 | private array $setupUsers = []; |
73 | 72 | // List of users for which all mounts are setup |
74 | 73 | private array $setupUsersComplete = []; |
75 | 74 | /** @var array<string, string[]> */ |
76 | 75 | private array $setupUserMountProviders = []; |
77 | | - private IEventDispatcher $eventDispatcher; |
78 | | - private IUserMountCache $userMountCache; |
79 | | - private ILockdownManager $lockdownManager; |
80 | | - private IUserSession $userSession; |
81 | 76 | private ICache $cache; |
82 | | - private LoggerInterface $logger; |
83 | | - private IConfig $config; |
84 | 77 | private bool $listeningForProviders; |
85 | 78 | private array $fullSetupRequired = []; |
86 | 79 | private bool $setupBuiltinWrappersDone = false; |
87 | 80 |
|
88 | 81 | public function __construct( |
89 | | - IEventLogger $eventLogger, |
90 | | - MountProviderCollection $mountProviderCollection, |
91 | | - IMountManager $mountManager, |
92 | | - IUserManager $userManager, |
93 | | - IEventDispatcher $eventDispatcher, |
94 | | - IUserMountCache $userMountCache, |
95 | | - ILockdownManager $lockdownManager, |
96 | | - IUserSession $userSession, |
| 82 | + private IEventLogger $eventLogger, |
| 83 | + private MountProviderCollection $mountProviderCollection, |
| 84 | + private IMountManager $mountManager, |
| 85 | + private IUserManager $userManager, |
| 86 | + private IEventDispatcher $eventDispatcher, |
| 87 | + private IUserMountCache $userMountCache, |
| 88 | + private ILockdownManager $lockdownManager, |
| 89 | + private IUserSession $userSession, |
97 | 90 | ICacheFactory $cacheFactory, |
98 | | - LoggerInterface $logger, |
99 | | - IConfig $config |
| 91 | + private LoggerInterface $logger, |
| 92 | + private IConfig $config, |
| 93 | + private ShareDisableChecker $shareDisableChecker, |
100 | 94 | ) { |
101 | | - $this->eventLogger = $eventLogger; |
102 | | - $this->mountProviderCollection = $mountProviderCollection; |
103 | | - $this->mountManager = $mountManager; |
104 | | - $this->userManager = $userManager; |
105 | | - $this->eventDispatcher = $eventDispatcher; |
106 | | - $this->userMountCache = $userMountCache; |
107 | | - $this->lockdownManager = $lockdownManager; |
108 | | - $this->logger = $logger; |
109 | | - $this->userSession = $userSession; |
110 | 95 | $this->cache = $cacheFactory->createDistributed('setupmanager::'); |
111 | 96 | $this->listeningForProviders = false; |
112 | | - $this->config = $config; |
113 | 97 |
|
114 | 98 | $this->setupListeners(); |
115 | 99 | } |
@@ -139,15 +123,23 @@ private function setupBuiltinWrappers() { |
139 | 123 | return $storage; |
140 | 124 | }); |
141 | 125 |
|
142 | | - Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) { |
143 | | - if (!$mount->getOption('enable_sharing', true)) { |
144 | | - return new PermissionsMask([ |
145 | | - 'storage' => $storage, |
146 | | - 'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
147 | | - ]); |
| 126 | + $reSharingEnabled = Share::isResharingAllowed(); |
| 127 | + $user = $this->userSession->getUser(); |
| 128 | + $sharingEnabledForUser = $user ? !$this->shareDisableChecker->sharingDisabledForUser($user->getUID()) : true; |
| 129 | + Filesystem::addStorageWrapper( |
| 130 | + 'sharing_mask', |
| 131 | + function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEnabled, $sharingEnabledForUser) { |
| 132 | + $sharingEnabledForMount = $mount->getOption('enable_sharing', true); |
| 133 | + $isShared = $storage->instanceOfStorage(ISharedStorage::class); |
| 134 | + if (!$sharingEnabledForMount || !$sharingEnabledForUser || (!$reSharingEnabled && $isShared)) { |
| 135 | + return new PermissionsMask([ |
| 136 | + 'storage' => $storage, |
| 137 | + 'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
| 138 | + ]); |
| 139 | + } |
| 140 | + return $storage; |
148 | 141 | } |
149 | | - return $storage; |
150 | | - }); |
| 142 | + ); |
151 | 143 |
|
152 | 144 | // install storage availability wrapper, before most other wrappers |
153 | 145 | Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) { |
|
0 commit comments