@@ -27,35 +27,35 @@ |
||
27 | 27 | |
28 | 28 | class SettingsManager { |
29 | 29 | |
30 | - /** @var IConfig */ |
|
31 | - private $config; |
|
32 | - |
|
33 | - private $sendPasswordByMailDefault = 'yes'; |
|
34 | - |
|
35 | - private $enforcePasswordProtectionDefault = 'no'; |
|
36 | - |
|
37 | - public function __construct(IConfig $config) { |
|
38 | - $this->config = $config; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * should the password for a mail share be send to the recipient |
|
43 | - * |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - public function sendPasswordByMail() { |
|
47 | - $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault); |
|
48 | - return $sendPasswordByMail === 'yes'; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * do we require a share by mail to be password protected |
|
53 | - * |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function enforcePasswordProtection() { |
|
57 | - $enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault); |
|
58 | - return $enforcePassword === 'yes'; |
|
59 | - } |
|
30 | + /** @var IConfig */ |
|
31 | + private $config; |
|
32 | + |
|
33 | + private $sendPasswordByMailDefault = 'yes'; |
|
34 | + |
|
35 | + private $enforcePasswordProtectionDefault = 'no'; |
|
36 | + |
|
37 | + public function __construct(IConfig $config) { |
|
38 | + $this->config = $config; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * should the password for a mail share be send to the recipient |
|
43 | + * |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + public function sendPasswordByMail() { |
|
47 | + $sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault); |
|
48 | + return $sendPasswordByMail === 'yes'; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * do we require a share by mail to be password protected |
|
53 | + * |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function enforcePasswordProtection() { |
|
57 | + $enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault); |
|
58 | + return $enforcePassword === 'yes'; |
|
59 | + } |
|
60 | 60 | |
61 | 61 | } |
@@ -27,42 +27,42 @@ |
||
27 | 27 | |
28 | 28 | class Admin implements ISettings { |
29 | 29 | |
30 | - /** @var SettingsManager */ |
|
31 | - private $settingsManager; |
|
30 | + /** @var SettingsManager */ |
|
31 | + private $settingsManager; |
|
32 | 32 | |
33 | - public function __construct(SettingsManager $settingsManager) { |
|
34 | - $this->settingsManager = $settingsManager; |
|
35 | - } |
|
33 | + public function __construct(SettingsManager $settingsManager) { |
|
34 | + $this->settingsManager = $settingsManager; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @return TemplateResponse |
|
39 | - */ |
|
40 | - public function getForm() { |
|
37 | + /** |
|
38 | + * @return TemplateResponse |
|
39 | + */ |
|
40 | + public function getForm() { |
|
41 | 41 | |
42 | - $parameters = [ |
|
43 | - 'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(), |
|
44 | - 'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection() |
|
45 | - ]; |
|
42 | + $parameters = [ |
|
43 | + 'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(), |
|
44 | + 'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection() |
|
45 | + ]; |
|
46 | 46 | |
47 | - return new TemplateResponse('sharebymail', 'settings-admin', $parameters, ''); |
|
48 | - } |
|
47 | + return new TemplateResponse('sharebymail', 'settings-admin', $parameters, ''); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return string the section ID, e.g. 'sharing' |
|
52 | - */ |
|
53 | - public function getSection() { |
|
54 | - return 'sharing'; |
|
55 | - } |
|
50 | + /** |
|
51 | + * @return string the section ID, e.g. 'sharing' |
|
52 | + */ |
|
53 | + public function getSection() { |
|
54 | + return 'sharing'; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return int whether the form should be rather on the top or bottom of |
|
59 | - * the admin section. The forms are arranged in ascending order of the |
|
60 | - * priority values. It is required to return a value between 0 and 100. |
|
61 | - * |
|
62 | - * E.g.: 70 |
|
63 | - */ |
|
64 | - public function getPriority() { |
|
65 | - return 40; |
|
66 | - } |
|
57 | + /** |
|
58 | + * @return int whether the form should be rather on the top or bottom of |
|
59 | + * the admin section. The forms are arranged in ascending order of the |
|
60 | + * priority values. It is required to return a value between 0 and 100. |
|
61 | + * |
|
62 | + * E.g.: 70 |
|
63 | + */ |
|
64 | + public function getPriority() { |
|
65 | + return 40; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | } |
@@ -27,27 +27,27 @@ |
||
27 | 27 | |
28 | 28 | class Settings { |
29 | 29 | |
30 | - /** @var SettingsManager */ |
|
31 | - private $settingsManager; |
|
32 | - |
|
33 | - public function __construct(SettingsManager $settingsManager) { |
|
34 | - $this->settingsManager = $settingsManager; |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * announce that the share-by-mail share provider is enabled |
|
39 | - * |
|
40 | - * @param array $settings |
|
41 | - */ |
|
42 | - public function announceShareProvider(array $settings) { |
|
43 | - $array = json_decode($settings['array']['oc_appconfig'], true); |
|
44 | - $array['shareByMailEnabled'] = true; |
|
45 | - $settings['array']['oc_appconfig'] = json_encode($array); |
|
46 | - } |
|
47 | - |
|
48 | - public function announceShareByMailSettings(array $settings) { |
|
49 | - $array = json_decode($settings['array']['oc_appconfig'], true); |
|
50 | - $array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection(); |
|
51 | - $settings['array']['oc_appconfig'] = json_encode($array); |
|
52 | - } |
|
30 | + /** @var SettingsManager */ |
|
31 | + private $settingsManager; |
|
32 | + |
|
33 | + public function __construct(SettingsManager $settingsManager) { |
|
34 | + $this->settingsManager = $settingsManager; |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * announce that the share-by-mail share provider is enabled |
|
39 | + * |
|
40 | + * @param array $settings |
|
41 | + */ |
|
42 | + public function announceShareProvider(array $settings) { |
|
43 | + $array = json_decode($settings['array']['oc_appconfig'], true); |
|
44 | + $array['shareByMailEnabled'] = true; |
|
45 | + $settings['array']['oc_appconfig'] = json_encode($array); |
|
46 | + } |
|
47 | + |
|
48 | + public function announceShareByMailSettings(array $settings) { |
|
49 | + $array = json_decode($settings['array']['oc_appconfig'], true); |
|
50 | + $array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection(); |
|
51 | + $settings['array']['oc_appconfig'] = json_encode($array); |
|
52 | + } |
|
53 | 53 | } |
@@ -28,13 +28,13 @@ |
||
28 | 28 | * @brief wraps around static Nextcloud core methods |
29 | 29 | */ |
30 | 30 | class LogWrapper { |
31 | - protected $app = 'user_ldap'; |
|
31 | + protected $app = 'user_ldap'; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @brief states whether the filesystem was loaded |
|
35 | - * @return bool |
|
36 | - */ |
|
37 | - public function log($msg, $level) { |
|
38 | - \OCP\Util::writeLog($this->app, $msg, $level); |
|
39 | - } |
|
33 | + /** |
|
34 | + * @brief states whether the filesystem was loaded |
|
35 | + * @return bool |
|
36 | + */ |
|
37 | + public function log($msg, $level) { |
|
38 | + \OCP\Util::writeLog($this->app, $msg, $level); |
|
39 | + } |
|
40 | 40 | } |
@@ -29,19 +29,19 @@ |
||
29 | 29 | */ |
30 | 30 | class FilesystemHelper { |
31 | 31 | |
32 | - /** |
|
33 | - * @brief states whether the filesystem was loaded |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function isLoaded() { |
|
37 | - return \OC\Files\Filesystem::$loaded; |
|
38 | - } |
|
32 | + /** |
|
33 | + * @brief states whether the filesystem was loaded |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function isLoaded() { |
|
37 | + return \OC\Files\Filesystem::$loaded; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @brief initializes the filesystem for the given user |
|
42 | - * @param string $uid the Nextcloud username of the user |
|
43 | - */ |
|
44 | - public function setup($uid) { |
|
45 | - \OC_Util::setupFS($uid); |
|
46 | - } |
|
40 | + /** |
|
41 | + * @brief initializes the filesystem for the given user |
|
42 | + * @param string $uid the Nextcloud username of the user |
|
43 | + */ |
|
44 | + public function setup($uid) { |
|
45 | + \OC_Util::setupFS($uid); |
|
46 | + } |
|
47 | 47 | } |
@@ -34,91 +34,91 @@ |
||
34 | 34 | |
35 | 35 | class SettingsController extends Controller { |
36 | 36 | |
37 | - /** @var IL10N */ |
|
38 | - private $l; |
|
39 | - |
|
40 | - /** @var TrustedServers */ |
|
41 | - private $trustedServers; |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $AppName |
|
45 | - * @param IRequest $request |
|
46 | - * @param IL10N $l10n |
|
47 | - * @param TrustedServers $trustedServers |
|
48 | - */ |
|
49 | - public function __construct($AppName, |
|
50 | - IRequest $request, |
|
51 | - IL10N $l10n, |
|
52 | - TrustedServers $trustedServers |
|
53 | - ) { |
|
54 | - parent::__construct($AppName, $request); |
|
55 | - $this->l = $l10n; |
|
56 | - $this->trustedServers = $trustedServers; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * add server to the list of trusted Nextclouds |
|
62 | - * |
|
63 | - * @param string $url |
|
64 | - * @return DataResponse |
|
65 | - * @throws HintException |
|
66 | - */ |
|
67 | - public function addServer($url) { |
|
68 | - $this->checkServer($url); |
|
69 | - $id = $this->trustedServers->addServer($url); |
|
70 | - |
|
71 | - return new DataResponse( |
|
72 | - [ |
|
73 | - 'url' => $url, |
|
74 | - 'id' => $id, |
|
75 | - 'message' => (string) $this->l->t('Added to the list of trusted servers') |
|
76 | - ] |
|
77 | - ); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * add server to the list of trusted Nextclouds |
|
82 | - * |
|
83 | - * @param int $id |
|
84 | - * @return DataResponse |
|
85 | - */ |
|
86 | - public function removeServer($id) { |
|
87 | - $this->trustedServers->removeServer($id); |
|
88 | - return new DataResponse(); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * enable/disable to automatically add servers to the list of trusted servers |
|
93 | - * once a federated share was created and accepted successfully |
|
94 | - * |
|
95 | - * @param bool $autoAddServers |
|
96 | - */ |
|
97 | - public function autoAddServers($autoAddServers) { |
|
98 | - $this->trustedServers->setAutoAddServers($autoAddServers); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * check if the server should be added to the list of trusted servers or not |
|
103 | - * |
|
104 | - * @param string $url |
|
105 | - * @return bool |
|
106 | - * @throws HintException |
|
107 | - */ |
|
108 | - protected function checkServer($url) { |
|
109 | - if ($this->trustedServers->isTrustedServer($url) === true) { |
|
110 | - $message = 'Server is already in the list of trusted servers.'; |
|
111 | - $hint = $this->l->t('Server is already in the list of trusted servers.'); |
|
112 | - throw new HintException($message, $hint); |
|
113 | - } |
|
114 | - |
|
115 | - if ($this->trustedServers->isOwnCloudServer($url) === false) { |
|
116 | - $message = 'No server to federate with found'; |
|
117 | - $hint = $this->l->t('No server to federate with found'); |
|
118 | - throw new HintException($message, $hint); |
|
119 | - } |
|
120 | - |
|
121 | - return true; |
|
122 | - } |
|
37 | + /** @var IL10N */ |
|
38 | + private $l; |
|
39 | + |
|
40 | + /** @var TrustedServers */ |
|
41 | + private $trustedServers; |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $AppName |
|
45 | + * @param IRequest $request |
|
46 | + * @param IL10N $l10n |
|
47 | + * @param TrustedServers $trustedServers |
|
48 | + */ |
|
49 | + public function __construct($AppName, |
|
50 | + IRequest $request, |
|
51 | + IL10N $l10n, |
|
52 | + TrustedServers $trustedServers |
|
53 | + ) { |
|
54 | + parent::__construct($AppName, $request); |
|
55 | + $this->l = $l10n; |
|
56 | + $this->trustedServers = $trustedServers; |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * add server to the list of trusted Nextclouds |
|
62 | + * |
|
63 | + * @param string $url |
|
64 | + * @return DataResponse |
|
65 | + * @throws HintException |
|
66 | + */ |
|
67 | + public function addServer($url) { |
|
68 | + $this->checkServer($url); |
|
69 | + $id = $this->trustedServers->addServer($url); |
|
70 | + |
|
71 | + return new DataResponse( |
|
72 | + [ |
|
73 | + 'url' => $url, |
|
74 | + 'id' => $id, |
|
75 | + 'message' => (string) $this->l->t('Added to the list of trusted servers') |
|
76 | + ] |
|
77 | + ); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * add server to the list of trusted Nextclouds |
|
82 | + * |
|
83 | + * @param int $id |
|
84 | + * @return DataResponse |
|
85 | + */ |
|
86 | + public function removeServer($id) { |
|
87 | + $this->trustedServers->removeServer($id); |
|
88 | + return new DataResponse(); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * enable/disable to automatically add servers to the list of trusted servers |
|
93 | + * once a federated share was created and accepted successfully |
|
94 | + * |
|
95 | + * @param bool $autoAddServers |
|
96 | + */ |
|
97 | + public function autoAddServers($autoAddServers) { |
|
98 | + $this->trustedServers->setAutoAddServers($autoAddServers); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * check if the server should be added to the list of trusted servers or not |
|
103 | + * |
|
104 | + * @param string $url |
|
105 | + * @return bool |
|
106 | + * @throws HintException |
|
107 | + */ |
|
108 | + protected function checkServer($url) { |
|
109 | + if ($this->trustedServers->isTrustedServer($url) === true) { |
|
110 | + $message = 'Server is already in the list of trusted servers.'; |
|
111 | + $hint = $this->l->t('Server is already in the list of trusted servers.'); |
|
112 | + throw new HintException($message, $hint); |
|
113 | + } |
|
114 | + |
|
115 | + if ($this->trustedServers->isOwnCloudServer($url) === false) { |
|
116 | + $message = 'No server to federate with found'; |
|
117 | + $hint = $this->l->t('No server to federate with found'); |
|
118 | + throw new HintException($message, $hint); |
|
119 | + } |
|
120 | + |
|
121 | + return true; |
|
122 | + } |
|
123 | 123 | |
124 | 124 | } |
@@ -42,97 +42,97 @@ |
||
42 | 42 | * Migrate mount config from mount.json to the database |
43 | 43 | */ |
44 | 44 | class StorageMigrator { |
45 | - /** |
|
46 | - * @var BackendService |
|
47 | - */ |
|
48 | - private $backendService; |
|
45 | + /** |
|
46 | + * @var BackendService |
|
47 | + */ |
|
48 | + private $backendService; |
|
49 | 49 | |
50 | - /** |
|
51 | - * @var DBConfigService |
|
52 | - */ |
|
53 | - private $dbConfig; |
|
50 | + /** |
|
51 | + * @var DBConfigService |
|
52 | + */ |
|
53 | + private $dbConfig; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var IConfig |
|
57 | - */ |
|
58 | - private $config; |
|
55 | + /** |
|
56 | + * @var IConfig |
|
57 | + */ |
|
58 | + private $config; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @var IDBConnection |
|
62 | - */ |
|
63 | - private $connection; |
|
60 | + /** |
|
61 | + * @var IDBConnection |
|
62 | + */ |
|
63 | + private $connection; |
|
64 | 64 | |
65 | - /** |
|
66 | - * @var ILogger |
|
67 | - */ |
|
68 | - private $logger; |
|
65 | + /** |
|
66 | + * @var ILogger |
|
67 | + */ |
|
68 | + private $logger; |
|
69 | 69 | |
70 | - /** @var IUserMountCache */ |
|
71 | - private $userMountCache; |
|
70 | + /** @var IUserMountCache */ |
|
71 | + private $userMountCache; |
|
72 | 72 | |
73 | - /** |
|
74 | - * StorageMigrator constructor. |
|
75 | - * |
|
76 | - * @param BackendService $backendService |
|
77 | - * @param DBConfigService $dbConfig |
|
78 | - * @param IConfig $config |
|
79 | - * @param IDBConnection $connection |
|
80 | - * @param ILogger $logger |
|
81 | - * @param IUserMountCache $userMountCache |
|
82 | - */ |
|
83 | - public function __construct( |
|
84 | - BackendService $backendService, |
|
85 | - DBConfigService $dbConfig, |
|
86 | - IConfig $config, |
|
87 | - IDBConnection $connection, |
|
88 | - ILogger $logger, |
|
89 | - IUserMountCache $userMountCache |
|
90 | - ) { |
|
91 | - $this->backendService = $backendService; |
|
92 | - $this->dbConfig = $dbConfig; |
|
93 | - $this->config = $config; |
|
94 | - $this->connection = $connection; |
|
95 | - $this->logger = $logger; |
|
96 | - $this->userMountCache = $userMountCache; |
|
97 | - } |
|
73 | + /** |
|
74 | + * StorageMigrator constructor. |
|
75 | + * |
|
76 | + * @param BackendService $backendService |
|
77 | + * @param DBConfigService $dbConfig |
|
78 | + * @param IConfig $config |
|
79 | + * @param IDBConnection $connection |
|
80 | + * @param ILogger $logger |
|
81 | + * @param IUserMountCache $userMountCache |
|
82 | + */ |
|
83 | + public function __construct( |
|
84 | + BackendService $backendService, |
|
85 | + DBConfigService $dbConfig, |
|
86 | + IConfig $config, |
|
87 | + IDBConnection $connection, |
|
88 | + ILogger $logger, |
|
89 | + IUserMountCache $userMountCache |
|
90 | + ) { |
|
91 | + $this->backendService = $backendService; |
|
92 | + $this->dbConfig = $dbConfig; |
|
93 | + $this->config = $config; |
|
94 | + $this->connection = $connection; |
|
95 | + $this->logger = $logger; |
|
96 | + $this->userMountCache = $userMountCache; |
|
97 | + } |
|
98 | 98 | |
99 | - private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService) { |
|
100 | - $existingStorage = $legacyService->getAllStorages(); |
|
99 | + private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService) { |
|
100 | + $existingStorage = $legacyService->getAllStorages(); |
|
101 | 101 | |
102 | - $this->connection->beginTransaction(); |
|
103 | - try { |
|
104 | - foreach ($existingStorage as $storage) { |
|
105 | - $mountOptions = $storage->getMountOptions(); |
|
106 | - if (!empty($mountOptions) && !isset($mountOptions['enable_sharing'])) { |
|
107 | - // existing mounts must have sharing enabled by default to avoid surprises |
|
108 | - $mountOptions['enable_sharing'] = true; |
|
109 | - $storage->setMountOptions($mountOptions); |
|
110 | - } |
|
111 | - $storageService->addStorage($storage); |
|
112 | - } |
|
113 | - $this->connection->commit(); |
|
114 | - } catch (\Exception $e) { |
|
115 | - $this->logger->logException($e); |
|
116 | - $this->connection->rollBack(); |
|
117 | - } |
|
118 | - } |
|
102 | + $this->connection->beginTransaction(); |
|
103 | + try { |
|
104 | + foreach ($existingStorage as $storage) { |
|
105 | + $mountOptions = $storage->getMountOptions(); |
|
106 | + if (!empty($mountOptions) && !isset($mountOptions['enable_sharing'])) { |
|
107 | + // existing mounts must have sharing enabled by default to avoid surprises |
|
108 | + $mountOptions['enable_sharing'] = true; |
|
109 | + $storage->setMountOptions($mountOptions); |
|
110 | + } |
|
111 | + $storageService->addStorage($storage); |
|
112 | + } |
|
113 | + $this->connection->commit(); |
|
114 | + } catch (\Exception $e) { |
|
115 | + $this->logger->logException($e); |
|
116 | + $this->connection->rollBack(); |
|
117 | + } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Migrate personal storages configured by the current user |
|
122 | - * |
|
123 | - * @param IUser $user |
|
124 | - */ |
|
125 | - public function migrateUser(IUser $user) { |
|
126 | - $dummySession = new DummyUserSession(); |
|
127 | - $dummySession->setUser($user); |
|
128 | - $userId = $user->getUID(); |
|
129 | - $userVersion = $this->config->getUserValue($userId, 'files_external', 'config_version', '0.0.0'); |
|
130 | - if (version_compare($userVersion, '0.5.0', '<')) { |
|
131 | - $this->config->setUserValue($userId, 'files_external', 'config_version', '0.5.0'); |
|
132 | - $legacyService = new UserLegacyStoragesService($this->backendService, $dummySession); |
|
133 | - $storageService = new UserStoragesService($this->backendService, $this->dbConfig, $dummySession, $this->userMountCache); |
|
120 | + /** |
|
121 | + * Migrate personal storages configured by the current user |
|
122 | + * |
|
123 | + * @param IUser $user |
|
124 | + */ |
|
125 | + public function migrateUser(IUser $user) { |
|
126 | + $dummySession = new DummyUserSession(); |
|
127 | + $dummySession->setUser($user); |
|
128 | + $userId = $user->getUID(); |
|
129 | + $userVersion = $this->config->getUserValue($userId, 'files_external', 'config_version', '0.0.0'); |
|
130 | + if (version_compare($userVersion, '0.5.0', '<')) { |
|
131 | + $this->config->setUserValue($userId, 'files_external', 'config_version', '0.5.0'); |
|
132 | + $legacyService = new UserLegacyStoragesService($this->backendService, $dummySession); |
|
133 | + $storageService = new UserStoragesService($this->backendService, $this->dbConfig, $dummySession, $this->userMountCache); |
|
134 | 134 | |
135 | - $this->migrate($legacyService, $storageService); |
|
136 | - } |
|
137 | - } |
|
135 | + $this->migrate($legacyService, $storageService); |
|
136 | + } |
|
137 | + } |
|
138 | 138 | } |
@@ -31,52 +31,52 @@ |
||
31 | 31 | * Scanner for SharedStorage |
32 | 32 | */ |
33 | 33 | class Scanner extends \OC\Files\Cache\Scanner { |
34 | - /** |
|
35 | - * @var \OCA\Files_Sharing\SharedStorage $storage |
|
36 | - */ |
|
37 | - protected $storage; |
|
34 | + /** |
|
35 | + * @var \OCA\Files_Sharing\SharedStorage $storage |
|
36 | + */ |
|
37 | + protected $storage; |
|
38 | 38 | |
39 | - private $sourceScanner; |
|
39 | + private $sourceScanner; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Returns metadata from the shared storage, but |
|
43 | - * with permissions from the source storage. |
|
44 | - * |
|
45 | - * @param string $path path of the file for which to retrieve metadata |
|
46 | - * |
|
47 | - * @return array an array of metadata of the file |
|
48 | - */ |
|
49 | - public function getData($path) { |
|
50 | - $data = parent::getData($path); |
|
51 | - if ($data === null) { |
|
52 | - return null; |
|
53 | - } |
|
54 | - $internalPath = $this->storage->getUnjailedPath($path); |
|
55 | - $data['permissions'] = $this->storage->getSourceStorage()->getPermissions($internalPath); |
|
56 | - return $data; |
|
57 | - } |
|
41 | + /** |
|
42 | + * Returns metadata from the shared storage, but |
|
43 | + * with permissions from the source storage. |
|
44 | + * |
|
45 | + * @param string $path path of the file for which to retrieve metadata |
|
46 | + * |
|
47 | + * @return array an array of metadata of the file |
|
48 | + */ |
|
49 | + public function getData($path) { |
|
50 | + $data = parent::getData($path); |
|
51 | + if ($data === null) { |
|
52 | + return null; |
|
53 | + } |
|
54 | + $internalPath = $this->storage->getUnjailedPath($path); |
|
55 | + $data['permissions'] = $this->storage->getSourceStorage()->getPermissions($internalPath); |
|
56 | + return $data; |
|
57 | + } |
|
58 | 58 | |
59 | - private function getSourceScanner() { |
|
60 | - if ($this->sourceScanner) { |
|
61 | - return $this->sourceScanner; |
|
62 | - } |
|
63 | - if ($this->storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
64 | - /** @var \OC\Files\Storage\Storage $storage */ |
|
65 | - list($storage) = $this->storage->resolvePath(''); |
|
66 | - $this->sourceScanner = $storage->getScanner(); |
|
67 | - return $this->sourceScanner; |
|
68 | - } else { |
|
69 | - return null; |
|
70 | - } |
|
71 | - } |
|
59 | + private function getSourceScanner() { |
|
60 | + if ($this->sourceScanner) { |
|
61 | + return $this->sourceScanner; |
|
62 | + } |
|
63 | + if ($this->storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
64 | + /** @var \OC\Files\Storage\Storage $storage */ |
|
65 | + list($storage) = $this->storage->resolvePath(''); |
|
66 | + $this->sourceScanner = $storage->getScanner(); |
|
67 | + return $this->sourceScanner; |
|
68 | + } else { |
|
69 | + return null; |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { |
|
74 | - $sourceScanner = $this->getSourceScanner(); |
|
75 | - if ($sourceScanner instanceof NoopScanner) { |
|
76 | - return []; |
|
77 | - } else { |
|
78 | - return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock); |
|
79 | - } |
|
80 | - } |
|
73 | + public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { |
|
74 | + $sourceScanner = $this->getSourceScanner(); |
|
75 | + if ($sourceScanner instanceof NoopScanner) { |
|
76 | + return []; |
|
77 | + } else { |
|
78 | + return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock); |
|
79 | + } |
|
80 | + } |
|
81 | 81 | } |
82 | 82 |
@@ -49,7 +49,7 @@ |
||
49 | 49 | protected function setSubjects(IEvent $event, $subject, array $parameters) { |
50 | 50 | $placeholders = $replacements = []; |
51 | 51 | foreach ($parameters as $placeholder => $parameter) { |
52 | - $placeholders[] = '{' . $placeholder . '}'; |
|
52 | + $placeholders[] = '{'.$placeholder.'}'; |
|
53 | 53 | $replacements[] = $parameter['name']; |
54 | 54 | } |
55 | 55 |
@@ -32,157 +32,157 @@ |
||
32 | 32 | |
33 | 33 | class Provider implements IProvider { |
34 | 34 | |
35 | - const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
36 | - const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
37 | - const PASSWORD_RESET = 'password_changed'; |
|
38 | - const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
39 | - const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
40 | - const EMAIL_CHANGED = 'email_changed'; |
|
41 | - |
|
42 | - /** @var IFactory */ |
|
43 | - protected $languageFactory; |
|
44 | - |
|
45 | - /** @var IL10N */ |
|
46 | - protected $l; |
|
47 | - |
|
48 | - /** @var IURLGenerator */ |
|
49 | - protected $url; |
|
50 | - |
|
51 | - /** @var IUserManager */ |
|
52 | - protected $userManager; |
|
53 | - |
|
54 | - /** @var IManager */ |
|
55 | - private $activityManager; |
|
56 | - |
|
57 | - /** @var string[] cached displayNames - key is the UID and value the displayname */ |
|
58 | - protected $displayNames = []; |
|
59 | - |
|
60 | - /** |
|
61 | - * @param IFactory $languageFactory |
|
62 | - * @param IURLGenerator $url |
|
63 | - * @param IUserManager $userManager |
|
64 | - * @param IManager $activityManager |
|
65 | - */ |
|
66 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IUserManager $userManager, IManager $activityManager) { |
|
67 | - $this->languageFactory = $languageFactory; |
|
68 | - $this->url = $url; |
|
69 | - $this->userManager = $userManager; |
|
70 | - $this->activityManager = $activityManager; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param string $language |
|
75 | - * @param IEvent $event |
|
76 | - * @param IEvent|null $previousEvent |
|
77 | - * @return IEvent |
|
78 | - * @throws \InvalidArgumentException |
|
79 | - * @since 11.0.0 |
|
80 | - */ |
|
81 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
82 | - if ($event->getApp() !== 'settings') { |
|
83 | - throw new \InvalidArgumentException(); |
|
84 | - } |
|
85 | - |
|
86 | - $this->l = $this->languageFactory->get('settings', $language); |
|
87 | - |
|
88 | - if ($this->activityManager->getRequirePNG()) { |
|
89 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
90 | - } else { |
|
91 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
92 | - } |
|
93 | - |
|
94 | - if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
95 | - $subject = $this->l->t('{actor} changed your password'); |
|
96 | - } else if ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
97 | - $subject = $this->l->t('You changed your password'); |
|
98 | - } else if ($event->getSubject() === self::PASSWORD_RESET) { |
|
99 | - $subject = $this->l->t('Your password was reset by an administrator'); |
|
100 | - |
|
101 | - } else if ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
102 | - $subject = $this->l->t('{actor} changed your email address'); |
|
103 | - } else if ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
104 | - $subject = $this->l->t('You changed your email address'); |
|
105 | - } else if ($event->getSubject() === self::EMAIL_CHANGED) { |
|
106 | - $subject = $this->l->t('Your email address was changed by an administrator'); |
|
107 | - |
|
108 | - } else { |
|
109 | - throw new \InvalidArgumentException(); |
|
110 | - } |
|
111 | - |
|
112 | - $parsedParameters = $this->getParameters($event); |
|
113 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
114 | - |
|
115 | - return $event; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @param IEvent $event |
|
120 | - * @return array |
|
121 | - * @throws \InvalidArgumentException |
|
122 | - */ |
|
123 | - protected function getParameters(IEvent $event) { |
|
124 | - $subject = $event->getSubject(); |
|
125 | - $parameters = $event->getSubjectParameters(); |
|
126 | - |
|
127 | - switch ($subject) { |
|
128 | - case self::PASSWORD_CHANGED_SELF: |
|
129 | - case self::PASSWORD_RESET: |
|
130 | - case self::EMAIL_CHANGED_SELF: |
|
131 | - case self::EMAIL_CHANGED: |
|
132 | - return []; |
|
133 | - case self::PASSWORD_CHANGED_BY: |
|
134 | - case self::EMAIL_CHANGED_BY: |
|
135 | - return [ |
|
136 | - 'actor' => $this->generateUserParameter($parameters[0]), |
|
137 | - ]; |
|
138 | - } |
|
139 | - |
|
140 | - throw new \InvalidArgumentException(); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param IEvent $event |
|
145 | - * @param string $subject |
|
146 | - * @param array $parameters |
|
147 | - * @throws \InvalidArgumentException |
|
148 | - */ |
|
149 | - protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
150 | - $placeholders = $replacements = []; |
|
151 | - foreach ($parameters as $placeholder => $parameter) { |
|
152 | - $placeholders[] = '{' . $placeholder . '}'; |
|
153 | - $replacements[] = $parameter['name']; |
|
154 | - } |
|
155 | - |
|
156 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
157 | - ->setRichSubject($subject, $parameters); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @param string $uid |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - protected function generateUserParameter($uid) { |
|
165 | - if (!isset($this->displayNames[$uid])) { |
|
166 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
167 | - } |
|
168 | - |
|
169 | - return [ |
|
170 | - 'type' => 'user', |
|
171 | - 'id' => $uid, |
|
172 | - 'name' => $this->displayNames[$uid], |
|
173 | - ]; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @param string $uid |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - protected function getDisplayName($uid) { |
|
181 | - $user = $this->userManager->get($uid); |
|
182 | - if ($user instanceof IUser) { |
|
183 | - return $user->getDisplayName(); |
|
184 | - } |
|
185 | - |
|
186 | - return $uid; |
|
187 | - } |
|
35 | + const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
36 | + const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
37 | + const PASSWORD_RESET = 'password_changed'; |
|
38 | + const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
39 | + const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
40 | + const EMAIL_CHANGED = 'email_changed'; |
|
41 | + |
|
42 | + /** @var IFactory */ |
|
43 | + protected $languageFactory; |
|
44 | + |
|
45 | + /** @var IL10N */ |
|
46 | + protected $l; |
|
47 | + |
|
48 | + /** @var IURLGenerator */ |
|
49 | + protected $url; |
|
50 | + |
|
51 | + /** @var IUserManager */ |
|
52 | + protected $userManager; |
|
53 | + |
|
54 | + /** @var IManager */ |
|
55 | + private $activityManager; |
|
56 | + |
|
57 | + /** @var string[] cached displayNames - key is the UID and value the displayname */ |
|
58 | + protected $displayNames = []; |
|
59 | + |
|
60 | + /** |
|
61 | + * @param IFactory $languageFactory |
|
62 | + * @param IURLGenerator $url |
|
63 | + * @param IUserManager $userManager |
|
64 | + * @param IManager $activityManager |
|
65 | + */ |
|
66 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IUserManager $userManager, IManager $activityManager) { |
|
67 | + $this->languageFactory = $languageFactory; |
|
68 | + $this->url = $url; |
|
69 | + $this->userManager = $userManager; |
|
70 | + $this->activityManager = $activityManager; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param string $language |
|
75 | + * @param IEvent $event |
|
76 | + * @param IEvent|null $previousEvent |
|
77 | + * @return IEvent |
|
78 | + * @throws \InvalidArgumentException |
|
79 | + * @since 11.0.0 |
|
80 | + */ |
|
81 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
82 | + if ($event->getApp() !== 'settings') { |
|
83 | + throw new \InvalidArgumentException(); |
|
84 | + } |
|
85 | + |
|
86 | + $this->l = $this->languageFactory->get('settings', $language); |
|
87 | + |
|
88 | + if ($this->activityManager->getRequirePNG()) { |
|
89 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
90 | + } else { |
|
91 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
92 | + } |
|
93 | + |
|
94 | + if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
95 | + $subject = $this->l->t('{actor} changed your password'); |
|
96 | + } else if ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
97 | + $subject = $this->l->t('You changed your password'); |
|
98 | + } else if ($event->getSubject() === self::PASSWORD_RESET) { |
|
99 | + $subject = $this->l->t('Your password was reset by an administrator'); |
|
100 | + |
|
101 | + } else if ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
102 | + $subject = $this->l->t('{actor} changed your email address'); |
|
103 | + } else if ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
104 | + $subject = $this->l->t('You changed your email address'); |
|
105 | + } else if ($event->getSubject() === self::EMAIL_CHANGED) { |
|
106 | + $subject = $this->l->t('Your email address was changed by an administrator'); |
|
107 | + |
|
108 | + } else { |
|
109 | + throw new \InvalidArgumentException(); |
|
110 | + } |
|
111 | + |
|
112 | + $parsedParameters = $this->getParameters($event); |
|
113 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
114 | + |
|
115 | + return $event; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @param IEvent $event |
|
120 | + * @return array |
|
121 | + * @throws \InvalidArgumentException |
|
122 | + */ |
|
123 | + protected function getParameters(IEvent $event) { |
|
124 | + $subject = $event->getSubject(); |
|
125 | + $parameters = $event->getSubjectParameters(); |
|
126 | + |
|
127 | + switch ($subject) { |
|
128 | + case self::PASSWORD_CHANGED_SELF: |
|
129 | + case self::PASSWORD_RESET: |
|
130 | + case self::EMAIL_CHANGED_SELF: |
|
131 | + case self::EMAIL_CHANGED: |
|
132 | + return []; |
|
133 | + case self::PASSWORD_CHANGED_BY: |
|
134 | + case self::EMAIL_CHANGED_BY: |
|
135 | + return [ |
|
136 | + 'actor' => $this->generateUserParameter($parameters[0]), |
|
137 | + ]; |
|
138 | + } |
|
139 | + |
|
140 | + throw new \InvalidArgumentException(); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param IEvent $event |
|
145 | + * @param string $subject |
|
146 | + * @param array $parameters |
|
147 | + * @throws \InvalidArgumentException |
|
148 | + */ |
|
149 | + protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
150 | + $placeholders = $replacements = []; |
|
151 | + foreach ($parameters as $placeholder => $parameter) { |
|
152 | + $placeholders[] = '{' . $placeholder . '}'; |
|
153 | + $replacements[] = $parameter['name']; |
|
154 | + } |
|
155 | + |
|
156 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
157 | + ->setRichSubject($subject, $parameters); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @param string $uid |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + protected function generateUserParameter($uid) { |
|
165 | + if (!isset($this->displayNames[$uid])) { |
|
166 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
167 | + } |
|
168 | + |
|
169 | + return [ |
|
170 | + 'type' => 'user', |
|
171 | + 'id' => $uid, |
|
172 | + 'name' => $this->displayNames[$uid], |
|
173 | + ]; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @param string $uid |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + protected function getDisplayName($uid) { |
|
181 | + $user = $this->userManager->get($uid); |
|
182 | + if ($user instanceof IUser) { |
|
183 | + return $user->getDisplayName(); |
|
184 | + } |
|
185 | + |
|
186 | + return $uid; |
|
187 | + } |
|
188 | 188 | } |