@@ -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 | } |
@@ -11,9 +11,9 @@ |
||
11 | 11 | <em><?php p($l->t('Send a personalized link to a file or folder by mail.')); ?></em> |
12 | 12 | |
13 | 13 | <p> |
14 | - <input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) p('checked'); ?> /> |
|
14 | + <input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if ($_['sendPasswordMail']) p('checked'); ?> /> |
|
15 | 15 | <label for="sendPasswordMail"><?php p($l->t('Send password by mail')); ?></label><br/> |
16 | - <input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) p('checked'); ?> /> |
|
16 | + <input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if ($_['enforcePasswordProtection']) p('checked'); ?> /> |
|
17 | 17 | <label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label> |
18 | 18 | </p> |
19 | 19 |
@@ -11,9 +11,15 @@ |
||
11 | 11 | <em><?php p($l->t('Send a personalized link to a file or folder by mail.')); ?></em> |
12 | 12 | |
13 | 13 | <p> |
14 | - <input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) p('checked'); ?> /> |
|
14 | + <input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) { |
|
15 | + p('checked'); |
|
16 | +} |
|
17 | +?> /> |
|
15 | 18 | <label for="sendPasswordMail"><?php p($l->t('Send password by mail')); ?></label><br/> |
16 | - <input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) p('checked'); ?> /> |
|
19 | + <input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) { |
|
20 | + p('checked'); |
|
21 | +} |
|
22 | +?> /> |
|
17 | 23 | <label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label> |
18 | 24 | </p> |
19 | 25 |
@@ -29,19 +29,19 @@ |
||
29 | 29 | |
30 | 30 | class Application extends App { |
31 | 31 | |
32 | - public function __construct(array $urlParams = array()) { |
|
33 | - parent::__construct('sharebymail', $urlParams); |
|
32 | + public function __construct(array $urlParams = array()) { |
|
33 | + parent::__construct('sharebymail', $urlParams); |
|
34 | 34 | |
35 | - $settingsManager = \OC::$server->query(Settings\SettingsManager::class); |
|
36 | - $settings = new Settings($settingsManager); |
|
35 | + $settingsManager = \OC::$server->query(Settings\SettingsManager::class); |
|
36 | + $settings = new Settings($settingsManager); |
|
37 | 37 | |
38 | - /** register capabilities */ |
|
39 | - $container = $this->getContainer(); |
|
40 | - $container->registerCapability('OCA\ShareByMail\Capabilities'); |
|
38 | + /** register capabilities */ |
|
39 | + $container = $this->getContainer(); |
|
40 | + $container->registerCapability('OCA\ShareByMail\Capabilities'); |
|
41 | 41 | |
42 | - /** register hooks */ |
|
43 | - Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareProvider'); |
|
44 | - Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareByMailSettings'); |
|
45 | - } |
|
42 | + /** register hooks */ |
|
43 | + Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareProvider'); |
|
44 | + Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareByMailSettings'); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | } |
@@ -276,10 +276,10 @@ discard block |
||
276 | 276 | * publish activity if a file/folder was shared by mail |
277 | 277 | * |
278 | 278 | * @param $subject |
279 | - * @param $parameters |
|
280 | - * @param $affectedUser |
|
279 | + * @param string[] $parameters |
|
280 | + * @param string $affectedUser |
|
281 | 281 | * @param $fileId |
282 | - * @param $filePath |
|
282 | + * @param string $filePath |
|
283 | 283 | */ |
284 | 284 | protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
285 | 285 | $event = $this->activityManager->generateEvent(); |
@@ -557,6 +557,7 @@ discard block |
||
557 | 557 | * @param string $uidOwner |
558 | 558 | * @param int $permissions |
559 | 559 | * @param string $token |
560 | + * @param string $password |
|
560 | 561 | * @return int |
561 | 562 | */ |
562 | 563 | protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) { |
@@ -950,7 +951,7 @@ discard block |
||
950 | 951 | /** |
951 | 952 | * get database row of a give share |
952 | 953 | * |
953 | - * @param $id |
|
954 | + * @param integer $id |
|
954 | 955 | * @return array |
955 | 956 | * @throws ShareNotFound |
956 | 957 | */ |
@@ -52,993 +52,993 @@ |
||
52 | 52 | */ |
53 | 53 | class ShareByMailProvider implements IShareProvider { |
54 | 54 | |
55 | - /** @var IDBConnection */ |
|
56 | - private $dbConnection; |
|
57 | - |
|
58 | - /** @var ILogger */ |
|
59 | - private $logger; |
|
60 | - |
|
61 | - /** @var ISecureRandom */ |
|
62 | - private $secureRandom; |
|
63 | - |
|
64 | - /** @var IUserManager */ |
|
65 | - private $userManager; |
|
66 | - |
|
67 | - /** @var IRootFolder */ |
|
68 | - private $rootFolder; |
|
69 | - |
|
70 | - /** @var IL10N */ |
|
71 | - private $l; |
|
72 | - |
|
73 | - /** @var IMailer */ |
|
74 | - private $mailer; |
|
75 | - |
|
76 | - /** @var IURLGenerator */ |
|
77 | - private $urlGenerator; |
|
78 | - |
|
79 | - /** @var IManager */ |
|
80 | - private $activityManager; |
|
81 | - |
|
82 | - /** @var SettingsManager */ |
|
83 | - private $settingsManager; |
|
84 | - |
|
85 | - /** @var Defaults */ |
|
86 | - private $defaults; |
|
87 | - |
|
88 | - /** @var IHasher */ |
|
89 | - private $hasher; |
|
90 | - |
|
91 | - /** |
|
92 | - * Return the identifier of this provider. |
|
93 | - * |
|
94 | - * @return string Containing only [a-zA-Z0-9] |
|
95 | - */ |
|
96 | - public function identifier() { |
|
97 | - return 'ocMailShare'; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * DefaultShareProvider constructor. |
|
102 | - * |
|
103 | - * @param IDBConnection $connection |
|
104 | - * @param ISecureRandom $secureRandom |
|
105 | - * @param IUserManager $userManager |
|
106 | - * @param IRootFolder $rootFolder |
|
107 | - * @param IL10N $l |
|
108 | - * @param ILogger $logger |
|
109 | - * @param IMailer $mailer |
|
110 | - * @param IURLGenerator $urlGenerator |
|
111 | - * @param IManager $activityManager |
|
112 | - * @param SettingsManager $settingsManager |
|
113 | - * @param Defaults $defaults |
|
114 | - * @param IHasher $hasher |
|
115 | - */ |
|
116 | - public function __construct( |
|
117 | - IDBConnection $connection, |
|
118 | - ISecureRandom $secureRandom, |
|
119 | - IUserManager $userManager, |
|
120 | - IRootFolder $rootFolder, |
|
121 | - IL10N $l, |
|
122 | - ILogger $logger, |
|
123 | - IMailer $mailer, |
|
124 | - IURLGenerator $urlGenerator, |
|
125 | - IManager $activityManager, |
|
126 | - SettingsManager $settingsManager, |
|
127 | - Defaults $defaults, |
|
128 | - IHasher $hasher |
|
129 | - ) { |
|
130 | - $this->dbConnection = $connection; |
|
131 | - $this->secureRandom = $secureRandom; |
|
132 | - $this->userManager = $userManager; |
|
133 | - $this->rootFolder = $rootFolder; |
|
134 | - $this->l = $l; |
|
135 | - $this->logger = $logger; |
|
136 | - $this->mailer = $mailer; |
|
137 | - $this->urlGenerator = $urlGenerator; |
|
138 | - $this->activityManager = $activityManager; |
|
139 | - $this->settingsManager = $settingsManager; |
|
140 | - $this->defaults = $defaults; |
|
141 | - $this->hasher = $hasher; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Share a path |
|
146 | - * |
|
147 | - * @param IShare $share |
|
148 | - * @return IShare The share object |
|
149 | - * @throws ShareNotFound |
|
150 | - * @throws \Exception |
|
151 | - */ |
|
152 | - public function create(IShare $share) { |
|
153 | - |
|
154 | - $shareWith = $share->getSharedWith(); |
|
155 | - /* |
|
55 | + /** @var IDBConnection */ |
|
56 | + private $dbConnection; |
|
57 | + |
|
58 | + /** @var ILogger */ |
|
59 | + private $logger; |
|
60 | + |
|
61 | + /** @var ISecureRandom */ |
|
62 | + private $secureRandom; |
|
63 | + |
|
64 | + /** @var IUserManager */ |
|
65 | + private $userManager; |
|
66 | + |
|
67 | + /** @var IRootFolder */ |
|
68 | + private $rootFolder; |
|
69 | + |
|
70 | + /** @var IL10N */ |
|
71 | + private $l; |
|
72 | + |
|
73 | + /** @var IMailer */ |
|
74 | + private $mailer; |
|
75 | + |
|
76 | + /** @var IURLGenerator */ |
|
77 | + private $urlGenerator; |
|
78 | + |
|
79 | + /** @var IManager */ |
|
80 | + private $activityManager; |
|
81 | + |
|
82 | + /** @var SettingsManager */ |
|
83 | + private $settingsManager; |
|
84 | + |
|
85 | + /** @var Defaults */ |
|
86 | + private $defaults; |
|
87 | + |
|
88 | + /** @var IHasher */ |
|
89 | + private $hasher; |
|
90 | + |
|
91 | + /** |
|
92 | + * Return the identifier of this provider. |
|
93 | + * |
|
94 | + * @return string Containing only [a-zA-Z0-9] |
|
95 | + */ |
|
96 | + public function identifier() { |
|
97 | + return 'ocMailShare'; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * DefaultShareProvider constructor. |
|
102 | + * |
|
103 | + * @param IDBConnection $connection |
|
104 | + * @param ISecureRandom $secureRandom |
|
105 | + * @param IUserManager $userManager |
|
106 | + * @param IRootFolder $rootFolder |
|
107 | + * @param IL10N $l |
|
108 | + * @param ILogger $logger |
|
109 | + * @param IMailer $mailer |
|
110 | + * @param IURLGenerator $urlGenerator |
|
111 | + * @param IManager $activityManager |
|
112 | + * @param SettingsManager $settingsManager |
|
113 | + * @param Defaults $defaults |
|
114 | + * @param IHasher $hasher |
|
115 | + */ |
|
116 | + public function __construct( |
|
117 | + IDBConnection $connection, |
|
118 | + ISecureRandom $secureRandom, |
|
119 | + IUserManager $userManager, |
|
120 | + IRootFolder $rootFolder, |
|
121 | + IL10N $l, |
|
122 | + ILogger $logger, |
|
123 | + IMailer $mailer, |
|
124 | + IURLGenerator $urlGenerator, |
|
125 | + IManager $activityManager, |
|
126 | + SettingsManager $settingsManager, |
|
127 | + Defaults $defaults, |
|
128 | + IHasher $hasher |
|
129 | + ) { |
|
130 | + $this->dbConnection = $connection; |
|
131 | + $this->secureRandom = $secureRandom; |
|
132 | + $this->userManager = $userManager; |
|
133 | + $this->rootFolder = $rootFolder; |
|
134 | + $this->l = $l; |
|
135 | + $this->logger = $logger; |
|
136 | + $this->mailer = $mailer; |
|
137 | + $this->urlGenerator = $urlGenerator; |
|
138 | + $this->activityManager = $activityManager; |
|
139 | + $this->settingsManager = $settingsManager; |
|
140 | + $this->defaults = $defaults; |
|
141 | + $this->hasher = $hasher; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Share a path |
|
146 | + * |
|
147 | + * @param IShare $share |
|
148 | + * @return IShare The share object |
|
149 | + * @throws ShareNotFound |
|
150 | + * @throws \Exception |
|
151 | + */ |
|
152 | + public function create(IShare $share) { |
|
153 | + |
|
154 | + $shareWith = $share->getSharedWith(); |
|
155 | + /* |
|
156 | 156 | * Check if file is not already shared with the remote user |
157 | 157 | */ |
158 | - $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
159 | - if (!empty($alreadyShared)) { |
|
160 | - $message = 'Sharing %s failed, this item is already shared with %s'; |
|
161 | - $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
162 | - $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
163 | - throw new \Exception($message_t); |
|
164 | - } |
|
165 | - |
|
166 | - // if the admin enforces a password for all mail shares we create a |
|
167 | - // random password and send it to the recipient |
|
168 | - $password = ''; |
|
169 | - $passwordEnforced = $this->settingsManager->enforcePasswordProtection(); |
|
170 | - if ($passwordEnforced) { |
|
171 | - $password = $this->autoGeneratePassword($share); |
|
172 | - } |
|
173 | - |
|
174 | - $shareId = $this->createMailShare($share); |
|
175 | - $send = $this->sendPassword($share, $password); |
|
176 | - if ($passwordEnforced && $send === false) { |
|
177 | - $send = $this->sendPasswordToOwner($share, $password); |
|
178 | - } |
|
179 | - |
|
180 | - $this->createShareActivity($share); |
|
181 | - $data = $this->getRawShare($shareId); |
|
182 | - |
|
183 | - return $this->createShareObject($data); |
|
184 | - |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * auto generate password in case of password enforcement on mail shares |
|
189 | - * |
|
190 | - * @param IShare $share |
|
191 | - * @return string |
|
192 | - * @throws \Exception |
|
193 | - */ |
|
194 | - protected function autoGeneratePassword($share) { |
|
195 | - $initiatorUser = $this->userManager->get($share->getSharedBy()); |
|
196 | - $initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
197 | - $allowPasswordByMail = $this->settingsManager->sendPasswordByMail(); |
|
198 | - |
|
199 | - if ($initiatorEMailAddress === null && !$allowPasswordByMail) { |
|
200 | - throw new \Exception( |
|
201 | - $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
202 | - ); |
|
203 | - } |
|
204 | - |
|
205 | - $password = $this->generateToken(8); |
|
206 | - $share->setPassword($this->hasher->hash($password)); |
|
207 | - |
|
208 | - return $password; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * create activity if a file/folder was shared by mail |
|
213 | - * |
|
214 | - * @param IShare $share |
|
215 | - */ |
|
216 | - protected function createShareActivity(IShare $share) { |
|
217 | - |
|
218 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
219 | - |
|
220 | - $this->publishActivity( |
|
221 | - Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
222 | - [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
223 | - $share->getSharedBy(), |
|
224 | - $share->getNode()->getId(), |
|
225 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
226 | - ); |
|
227 | - |
|
228 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
229 | - $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
230 | - $fileId = $share->getNode()->getId(); |
|
231 | - $nodes = $ownerFolder->getById($fileId); |
|
232 | - $ownerPath = $nodes[0]->getPath(); |
|
233 | - $this->publishActivity( |
|
234 | - Activity::SUBJECT_SHARED_EMAIL_BY, |
|
235 | - [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
236 | - $share->getShareOwner(), |
|
237 | - $fileId, |
|
238 | - $ownerFolder->getRelativePath($ownerPath) |
|
239 | - ); |
|
240 | - } |
|
241 | - |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * create activity if a file/folder was shared by mail |
|
246 | - * |
|
247 | - * @param IShare $share |
|
248 | - * @param string $sharedWith |
|
249 | - * @param bool $sendToSelf |
|
250 | - */ |
|
251 | - protected function createPasswordSendActivity(IShare $share, $sharedWith, $sendToSelf) { |
|
252 | - |
|
253 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
254 | - |
|
255 | - if ($sendToSelf) { |
|
256 | - $this->publishActivity( |
|
257 | - Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF, |
|
258 | - [$userFolder->getRelativePath($share->getNode()->getPath())], |
|
259 | - $share->getSharedBy(), |
|
260 | - $share->getNode()->getId(), |
|
261 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
262 | - ); |
|
263 | - } else { |
|
264 | - $this->publishActivity( |
|
265 | - Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND, |
|
266 | - [$userFolder->getRelativePath($share->getNode()->getPath()), $sharedWith], |
|
267 | - $share->getSharedBy(), |
|
268 | - $share->getNode()->getId(), |
|
269 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
270 | - ); |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * publish activity if a file/folder was shared by mail |
|
277 | - * |
|
278 | - * @param $subject |
|
279 | - * @param $parameters |
|
280 | - * @param $affectedUser |
|
281 | - * @param $fileId |
|
282 | - * @param $filePath |
|
283 | - */ |
|
284 | - protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
285 | - $event = $this->activityManager->generateEvent(); |
|
286 | - $event->setApp('sharebymail') |
|
287 | - ->setType('shared') |
|
288 | - ->setSubject($subject, $parameters) |
|
289 | - ->setAffectedUser($affectedUser) |
|
290 | - ->setObject('files', $fileId, $filePath); |
|
291 | - $this->activityManager->publish($event); |
|
292 | - |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * @param IShare $share |
|
297 | - * @return int |
|
298 | - * @throws \Exception |
|
299 | - */ |
|
300 | - protected function createMailShare(IShare $share) { |
|
301 | - $share->setToken($this->generateToken()); |
|
302 | - $shareId = $this->addShareToDB( |
|
303 | - $share->getNodeId(), |
|
304 | - $share->getNodeType(), |
|
305 | - $share->getSharedWith(), |
|
306 | - $share->getSharedBy(), |
|
307 | - $share->getShareOwner(), |
|
308 | - $share->getPermissions(), |
|
309 | - $share->getToken(), |
|
310 | - $share->getPassword() |
|
311 | - ); |
|
312 | - |
|
313 | - try { |
|
314 | - $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
315 | - ['token' => $share->getToken()]); |
|
316 | - $this->sendMailNotification( |
|
317 | - $share->getNode()->getName(), |
|
318 | - $link, |
|
319 | - $share->getShareOwner(), |
|
320 | - $share->getSharedBy(), |
|
321 | - $share->getSharedWith() |
|
322 | - ); |
|
323 | - } catch (HintException $hintException) { |
|
324 | - $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
325 | - $this->removeShareFromTable($shareId); |
|
326 | - throw $hintException; |
|
327 | - } catch (\Exception $e) { |
|
328 | - $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
329 | - $this->removeShareFromTable($shareId); |
|
330 | - throw new HintException('Failed to send share by mail', |
|
331 | - $this->l->t('Failed to send share by E-mail')); |
|
332 | - } |
|
333 | - |
|
334 | - return $shareId; |
|
335 | - |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @param string $filename |
|
340 | - * @param string $link |
|
341 | - * @param string $owner |
|
342 | - * @param string $initiator |
|
343 | - * @param string $shareWith |
|
344 | - * @throws \Exception If mail couldn't be sent |
|
345 | - */ |
|
346 | - protected function sendMailNotification($filename, |
|
347 | - $link, |
|
348 | - $owner, |
|
349 | - $initiator, |
|
350 | - $shareWith) { |
|
351 | - $ownerUser = $this->userManager->get($owner); |
|
352 | - $initiatorUser = $this->userManager->get($initiator); |
|
353 | - $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
|
354 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
355 | - $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
356 | - if ($owner === $initiator) { |
|
357 | - $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
358 | - } else { |
|
359 | - $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
360 | - } |
|
361 | - |
|
362 | - $message = $this->mailer->createMessage(); |
|
363 | - |
|
364 | - $emailTemplate = $this->mailer->createEMailTemplate(); |
|
365 | - |
|
366 | - $emailTemplate->addHeader(); |
|
367 | - $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$ownerDisplayName, $filename]), false); |
|
368 | - if ($owner === $initiator) { |
|
369 | - $text = $this->l->t('%s shared »%s« with you.', [$ownerDisplayName, $filename]); |
|
370 | - } else { |
|
371 | - $text= $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); |
|
372 | - } |
|
373 | - $emailTemplate->addBodyText( |
|
374 | - $text . ' ' . $this->l->t('Click the button below to open it.'), |
|
375 | - $text |
|
376 | - ); |
|
377 | - $emailTemplate->addBodyButton( |
|
378 | - $this->l->t('Open »%s«', [$filename]), |
|
379 | - $link |
|
380 | - ); |
|
381 | - |
|
382 | - $emailTemplate->addFooter(); |
|
383 | - if ($initiatorEmailAddress !== null) { |
|
384 | - $message->setFrom([$initiatorEmailAddress => $initiatorDisplayName]); |
|
385 | - } |
|
386 | - |
|
387 | - $message->setTo([$shareWith]); |
|
388 | - |
|
389 | - // The "From" contains the sharers name |
|
390 | - $instanceName = $this->defaults->getName(); |
|
391 | - $senderName = $this->l->t( |
|
392 | - '%s via %s', |
|
393 | - [ |
|
394 | - $ownerDisplayName, |
|
395 | - $instanceName |
|
396 | - ] |
|
397 | - ); |
|
398 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
399 | - |
|
400 | - // The "Reply-To" is set to the sharer if an mail address is configured |
|
401 | - // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
402 | - $ownerEmail = $ownerUser->getEMailAddress(); |
|
403 | - if($ownerEmail !== null) { |
|
404 | - $message->setReplyTo([$ownerEmail => $ownerDisplayName]); |
|
405 | - $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
406 | - } else { |
|
407 | - $emailTemplate->addFooter(); |
|
408 | - } |
|
409 | - |
|
410 | - $message->setSubject($subject); |
|
411 | - $message->setPlainBody($emailTemplate->renderText()); |
|
412 | - $message->setHtmlBody($emailTemplate->renderHTML()); |
|
413 | - $this->mailer->send($message); |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * send password to recipient of a mail share |
|
418 | - * |
|
419 | - * @param IShare $share |
|
420 | - * @param string $password |
|
421 | - * @return bool |
|
422 | - */ |
|
423 | - protected function sendPassword(IShare $share, $password) { |
|
424 | - |
|
425 | - $filename = $share->getNode()->getName(); |
|
426 | - $initiator = $share->getSharedBy(); |
|
427 | - $shareWith = $share->getSharedWith(); |
|
428 | - |
|
429 | - if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) { |
|
430 | - return false; |
|
431 | - } |
|
432 | - |
|
433 | - $initiatorUser = $this->userManager->get($initiator); |
|
434 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
435 | - $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
436 | - |
|
437 | - $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
438 | - $plainBodyPart = $this->l->t("%s shared »%s« with you.\nYou should have already received a separate mail with a link to access it.\n", [$initiatorDisplayName, $filename]); |
|
439 | - $htmlBodyPart = $this->l->t('%s shared »%s« with you. You should have already received a separate mail with a link to access it.', [$initiatorDisplayName, $filename]); |
|
440 | - |
|
441 | - $message = $this->mailer->createMessage(); |
|
442 | - |
|
443 | - $emailTemplate = $this->mailer->createEMailTemplate(); |
|
444 | - $emailTemplate->addHeader(); |
|
445 | - $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
446 | - $emailTemplate->addBodyText($htmlBodyPart, $plainBodyPart); |
|
447 | - $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); |
|
448 | - $emailTemplate->addFooter(); |
|
449 | - |
|
450 | - if ($initiatorEmailAddress !== null) { |
|
451 | - $message->setFrom([$initiatorEmailAddress => $initiatorDisplayName]); |
|
452 | - } |
|
453 | - $message->setTo([$shareWith]); |
|
454 | - $message->setSubject($subject); |
|
455 | - $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
456 | - $message->setHtmlBody($emailTemplate->renderHTML()); |
|
457 | - $this->mailer->send($message); |
|
458 | - |
|
459 | - $this->createPasswordSendActivity($share, $shareWith, false); |
|
460 | - |
|
461 | - return true; |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * send auto generated password to the owner. This happens if the admin enforces |
|
466 | - * a password for mail shares and forbid to send the password by mail to the recipient |
|
467 | - * |
|
468 | - * @param IShare $share |
|
469 | - * @param string $password |
|
470 | - * @return bool |
|
471 | - * @throws \Exception |
|
472 | - */ |
|
473 | - protected function sendPasswordToOwner(IShare $share, $password) { |
|
474 | - |
|
475 | - $filename = $share->getNode()->getName(); |
|
476 | - $initiator = $this->userManager->get($share->getSharedBy()); |
|
477 | - $initiatorEMailAddress = ($initiator instanceof IUser) ? $initiator->getEMailAddress() : null; |
|
478 | - $initiatorDisplayName = ($initiator instanceof IUser) ? $initiator->getDisplayName() : $share->getSharedBy(); |
|
479 | - $shareWith = $share->getSharedWith(); |
|
480 | - |
|
481 | - if ($initiatorEMailAddress === null) { |
|
482 | - throw new \Exception( |
|
483 | - $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
484 | - ); |
|
485 | - } |
|
486 | - |
|
487 | - $subject = (string)$this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]); |
|
488 | - $bodyPart = $this->l->t("You just shared »%s« with %s. The share was already send to the recipient. Due to the security policies defined by the administrator of %s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.", [$filename, $shareWith, $this->defaults->getName()]); |
|
489 | - |
|
490 | - $message = $this->mailer->createMessage(); |
|
491 | - $emailTemplate = $this->mailer->createEMailTemplate(); |
|
492 | - |
|
493 | - $emailTemplate->addHeader(); |
|
494 | - $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
495 | - $emailTemplate->addBodyText($bodyPart); |
|
496 | - $emailTemplate->addBodyText($this->l->t('This is the password: %s', [$password])); |
|
497 | - $emailTemplate->addBodyText($this->l->t('You can chose a different password at any time in the share dialog.')); |
|
498 | - $emailTemplate->addFooter(); |
|
499 | - |
|
500 | - if ($initiatorEMailAddress) { |
|
501 | - $message->setFrom([$initiatorEMailAddress => $initiatorDisplayName]); |
|
502 | - } |
|
503 | - $message->setTo([$initiatorEMailAddress => $initiatorDisplayName]); |
|
504 | - $message->setSubject($subject); |
|
505 | - $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
506 | - $message->setHtmlBody($emailTemplate->renderHTML()); |
|
507 | - $this->mailer->send($message); |
|
508 | - |
|
509 | - $this->createPasswordSendActivity($share, $shareWith, true); |
|
510 | - |
|
511 | - return true; |
|
512 | - } |
|
513 | - |
|
514 | - /** |
|
515 | - * generate share token |
|
516 | - * |
|
517 | - * @return string |
|
518 | - */ |
|
519 | - protected function generateToken($size = 15) { |
|
520 | - $token = $this->secureRandom->generate( |
|
521 | - $size, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
522 | - return $token; |
|
523 | - } |
|
524 | - |
|
525 | - /** |
|
526 | - * Get all children of this share |
|
527 | - * |
|
528 | - * @param IShare $parent |
|
529 | - * @return IShare[] |
|
530 | - */ |
|
531 | - public function getChildren(IShare $parent) { |
|
532 | - $children = []; |
|
533 | - |
|
534 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
535 | - $qb->select('*') |
|
536 | - ->from('share') |
|
537 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
538 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
539 | - ->orderBy('id'); |
|
540 | - |
|
541 | - $cursor = $qb->execute(); |
|
542 | - while($data = $cursor->fetch()) { |
|
543 | - $children[] = $this->createShareObject($data); |
|
544 | - } |
|
545 | - $cursor->closeCursor(); |
|
546 | - |
|
547 | - return $children; |
|
548 | - } |
|
549 | - |
|
550 | - /** |
|
551 | - * add share to the database and return the ID |
|
552 | - * |
|
553 | - * @param int $itemSource |
|
554 | - * @param string $itemType |
|
555 | - * @param string $shareWith |
|
556 | - * @param string $sharedBy |
|
557 | - * @param string $uidOwner |
|
558 | - * @param int $permissions |
|
559 | - * @param string $token |
|
560 | - * @return int |
|
561 | - */ |
|
562 | - protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) { |
|
563 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
564 | - $qb->insert('share') |
|
565 | - ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
566 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
567 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
568 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
569 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
570 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
571 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
572 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
573 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
574 | - ->setValue('password', $qb->createNamedParameter($password)) |
|
575 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
576 | - |
|
577 | - /* |
|
158 | + $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
159 | + if (!empty($alreadyShared)) { |
|
160 | + $message = 'Sharing %s failed, this item is already shared with %s'; |
|
161 | + $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
162 | + $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
163 | + throw new \Exception($message_t); |
|
164 | + } |
|
165 | + |
|
166 | + // if the admin enforces a password for all mail shares we create a |
|
167 | + // random password and send it to the recipient |
|
168 | + $password = ''; |
|
169 | + $passwordEnforced = $this->settingsManager->enforcePasswordProtection(); |
|
170 | + if ($passwordEnforced) { |
|
171 | + $password = $this->autoGeneratePassword($share); |
|
172 | + } |
|
173 | + |
|
174 | + $shareId = $this->createMailShare($share); |
|
175 | + $send = $this->sendPassword($share, $password); |
|
176 | + if ($passwordEnforced && $send === false) { |
|
177 | + $send = $this->sendPasswordToOwner($share, $password); |
|
178 | + } |
|
179 | + |
|
180 | + $this->createShareActivity($share); |
|
181 | + $data = $this->getRawShare($shareId); |
|
182 | + |
|
183 | + return $this->createShareObject($data); |
|
184 | + |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * auto generate password in case of password enforcement on mail shares |
|
189 | + * |
|
190 | + * @param IShare $share |
|
191 | + * @return string |
|
192 | + * @throws \Exception |
|
193 | + */ |
|
194 | + protected function autoGeneratePassword($share) { |
|
195 | + $initiatorUser = $this->userManager->get($share->getSharedBy()); |
|
196 | + $initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
197 | + $allowPasswordByMail = $this->settingsManager->sendPasswordByMail(); |
|
198 | + |
|
199 | + if ($initiatorEMailAddress === null && !$allowPasswordByMail) { |
|
200 | + throw new \Exception( |
|
201 | + $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
202 | + ); |
|
203 | + } |
|
204 | + |
|
205 | + $password = $this->generateToken(8); |
|
206 | + $share->setPassword($this->hasher->hash($password)); |
|
207 | + |
|
208 | + return $password; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * create activity if a file/folder was shared by mail |
|
213 | + * |
|
214 | + * @param IShare $share |
|
215 | + */ |
|
216 | + protected function createShareActivity(IShare $share) { |
|
217 | + |
|
218 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
219 | + |
|
220 | + $this->publishActivity( |
|
221 | + Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
222 | + [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
223 | + $share->getSharedBy(), |
|
224 | + $share->getNode()->getId(), |
|
225 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
226 | + ); |
|
227 | + |
|
228 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
229 | + $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
230 | + $fileId = $share->getNode()->getId(); |
|
231 | + $nodes = $ownerFolder->getById($fileId); |
|
232 | + $ownerPath = $nodes[0]->getPath(); |
|
233 | + $this->publishActivity( |
|
234 | + Activity::SUBJECT_SHARED_EMAIL_BY, |
|
235 | + [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
236 | + $share->getShareOwner(), |
|
237 | + $fileId, |
|
238 | + $ownerFolder->getRelativePath($ownerPath) |
|
239 | + ); |
|
240 | + } |
|
241 | + |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * create activity if a file/folder was shared by mail |
|
246 | + * |
|
247 | + * @param IShare $share |
|
248 | + * @param string $sharedWith |
|
249 | + * @param bool $sendToSelf |
|
250 | + */ |
|
251 | + protected function createPasswordSendActivity(IShare $share, $sharedWith, $sendToSelf) { |
|
252 | + |
|
253 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
254 | + |
|
255 | + if ($sendToSelf) { |
|
256 | + $this->publishActivity( |
|
257 | + Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF, |
|
258 | + [$userFolder->getRelativePath($share->getNode()->getPath())], |
|
259 | + $share->getSharedBy(), |
|
260 | + $share->getNode()->getId(), |
|
261 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
262 | + ); |
|
263 | + } else { |
|
264 | + $this->publishActivity( |
|
265 | + Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND, |
|
266 | + [$userFolder->getRelativePath($share->getNode()->getPath()), $sharedWith], |
|
267 | + $share->getSharedBy(), |
|
268 | + $share->getNode()->getId(), |
|
269 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
270 | + ); |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * publish activity if a file/folder was shared by mail |
|
277 | + * |
|
278 | + * @param $subject |
|
279 | + * @param $parameters |
|
280 | + * @param $affectedUser |
|
281 | + * @param $fileId |
|
282 | + * @param $filePath |
|
283 | + */ |
|
284 | + protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
285 | + $event = $this->activityManager->generateEvent(); |
|
286 | + $event->setApp('sharebymail') |
|
287 | + ->setType('shared') |
|
288 | + ->setSubject($subject, $parameters) |
|
289 | + ->setAffectedUser($affectedUser) |
|
290 | + ->setObject('files', $fileId, $filePath); |
|
291 | + $this->activityManager->publish($event); |
|
292 | + |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * @param IShare $share |
|
297 | + * @return int |
|
298 | + * @throws \Exception |
|
299 | + */ |
|
300 | + protected function createMailShare(IShare $share) { |
|
301 | + $share->setToken($this->generateToken()); |
|
302 | + $shareId = $this->addShareToDB( |
|
303 | + $share->getNodeId(), |
|
304 | + $share->getNodeType(), |
|
305 | + $share->getSharedWith(), |
|
306 | + $share->getSharedBy(), |
|
307 | + $share->getShareOwner(), |
|
308 | + $share->getPermissions(), |
|
309 | + $share->getToken(), |
|
310 | + $share->getPassword() |
|
311 | + ); |
|
312 | + |
|
313 | + try { |
|
314 | + $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
315 | + ['token' => $share->getToken()]); |
|
316 | + $this->sendMailNotification( |
|
317 | + $share->getNode()->getName(), |
|
318 | + $link, |
|
319 | + $share->getShareOwner(), |
|
320 | + $share->getSharedBy(), |
|
321 | + $share->getSharedWith() |
|
322 | + ); |
|
323 | + } catch (HintException $hintException) { |
|
324 | + $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
325 | + $this->removeShareFromTable($shareId); |
|
326 | + throw $hintException; |
|
327 | + } catch (\Exception $e) { |
|
328 | + $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
329 | + $this->removeShareFromTable($shareId); |
|
330 | + throw new HintException('Failed to send share by mail', |
|
331 | + $this->l->t('Failed to send share by E-mail')); |
|
332 | + } |
|
333 | + |
|
334 | + return $shareId; |
|
335 | + |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @param string $filename |
|
340 | + * @param string $link |
|
341 | + * @param string $owner |
|
342 | + * @param string $initiator |
|
343 | + * @param string $shareWith |
|
344 | + * @throws \Exception If mail couldn't be sent |
|
345 | + */ |
|
346 | + protected function sendMailNotification($filename, |
|
347 | + $link, |
|
348 | + $owner, |
|
349 | + $initiator, |
|
350 | + $shareWith) { |
|
351 | + $ownerUser = $this->userManager->get($owner); |
|
352 | + $initiatorUser = $this->userManager->get($initiator); |
|
353 | + $ownerDisplayName = ($ownerUser instanceof IUser) ? $ownerUser->getDisplayName() : $owner; |
|
354 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
355 | + $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
356 | + if ($owner === $initiator) { |
|
357 | + $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
358 | + } else { |
|
359 | + $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
360 | + } |
|
361 | + |
|
362 | + $message = $this->mailer->createMessage(); |
|
363 | + |
|
364 | + $emailTemplate = $this->mailer->createEMailTemplate(); |
|
365 | + |
|
366 | + $emailTemplate->addHeader(); |
|
367 | + $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$ownerDisplayName, $filename]), false); |
|
368 | + if ($owner === $initiator) { |
|
369 | + $text = $this->l->t('%s shared »%s« with you.', [$ownerDisplayName, $filename]); |
|
370 | + } else { |
|
371 | + $text= $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); |
|
372 | + } |
|
373 | + $emailTemplate->addBodyText( |
|
374 | + $text . ' ' . $this->l->t('Click the button below to open it.'), |
|
375 | + $text |
|
376 | + ); |
|
377 | + $emailTemplate->addBodyButton( |
|
378 | + $this->l->t('Open »%s«', [$filename]), |
|
379 | + $link |
|
380 | + ); |
|
381 | + |
|
382 | + $emailTemplate->addFooter(); |
|
383 | + if ($initiatorEmailAddress !== null) { |
|
384 | + $message->setFrom([$initiatorEmailAddress => $initiatorDisplayName]); |
|
385 | + } |
|
386 | + |
|
387 | + $message->setTo([$shareWith]); |
|
388 | + |
|
389 | + // The "From" contains the sharers name |
|
390 | + $instanceName = $this->defaults->getName(); |
|
391 | + $senderName = $this->l->t( |
|
392 | + '%s via %s', |
|
393 | + [ |
|
394 | + $ownerDisplayName, |
|
395 | + $instanceName |
|
396 | + ] |
|
397 | + ); |
|
398 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
399 | + |
|
400 | + // The "Reply-To" is set to the sharer if an mail address is configured |
|
401 | + // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
402 | + $ownerEmail = $ownerUser->getEMailAddress(); |
|
403 | + if($ownerEmail !== null) { |
|
404 | + $message->setReplyTo([$ownerEmail => $ownerDisplayName]); |
|
405 | + $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
406 | + } else { |
|
407 | + $emailTemplate->addFooter(); |
|
408 | + } |
|
409 | + |
|
410 | + $message->setSubject($subject); |
|
411 | + $message->setPlainBody($emailTemplate->renderText()); |
|
412 | + $message->setHtmlBody($emailTemplate->renderHTML()); |
|
413 | + $this->mailer->send($message); |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * send password to recipient of a mail share |
|
418 | + * |
|
419 | + * @param IShare $share |
|
420 | + * @param string $password |
|
421 | + * @return bool |
|
422 | + */ |
|
423 | + protected function sendPassword(IShare $share, $password) { |
|
424 | + |
|
425 | + $filename = $share->getNode()->getName(); |
|
426 | + $initiator = $share->getSharedBy(); |
|
427 | + $shareWith = $share->getSharedWith(); |
|
428 | + |
|
429 | + if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) { |
|
430 | + return false; |
|
431 | + } |
|
432 | + |
|
433 | + $initiatorUser = $this->userManager->get($initiator); |
|
434 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
435 | + $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
436 | + |
|
437 | + $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
438 | + $plainBodyPart = $this->l->t("%s shared »%s« with you.\nYou should have already received a separate mail with a link to access it.\n", [$initiatorDisplayName, $filename]); |
|
439 | + $htmlBodyPart = $this->l->t('%s shared »%s« with you. You should have already received a separate mail with a link to access it.', [$initiatorDisplayName, $filename]); |
|
440 | + |
|
441 | + $message = $this->mailer->createMessage(); |
|
442 | + |
|
443 | + $emailTemplate = $this->mailer->createEMailTemplate(); |
|
444 | + $emailTemplate->addHeader(); |
|
445 | + $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
446 | + $emailTemplate->addBodyText($htmlBodyPart, $plainBodyPart); |
|
447 | + $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); |
|
448 | + $emailTemplate->addFooter(); |
|
449 | + |
|
450 | + if ($initiatorEmailAddress !== null) { |
|
451 | + $message->setFrom([$initiatorEmailAddress => $initiatorDisplayName]); |
|
452 | + } |
|
453 | + $message->setTo([$shareWith]); |
|
454 | + $message->setSubject($subject); |
|
455 | + $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
456 | + $message->setHtmlBody($emailTemplate->renderHTML()); |
|
457 | + $this->mailer->send($message); |
|
458 | + |
|
459 | + $this->createPasswordSendActivity($share, $shareWith, false); |
|
460 | + |
|
461 | + return true; |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * send auto generated password to the owner. This happens if the admin enforces |
|
466 | + * a password for mail shares and forbid to send the password by mail to the recipient |
|
467 | + * |
|
468 | + * @param IShare $share |
|
469 | + * @param string $password |
|
470 | + * @return bool |
|
471 | + * @throws \Exception |
|
472 | + */ |
|
473 | + protected function sendPasswordToOwner(IShare $share, $password) { |
|
474 | + |
|
475 | + $filename = $share->getNode()->getName(); |
|
476 | + $initiator = $this->userManager->get($share->getSharedBy()); |
|
477 | + $initiatorEMailAddress = ($initiator instanceof IUser) ? $initiator->getEMailAddress() : null; |
|
478 | + $initiatorDisplayName = ($initiator instanceof IUser) ? $initiator->getDisplayName() : $share->getSharedBy(); |
|
479 | + $shareWith = $share->getSharedWith(); |
|
480 | + |
|
481 | + if ($initiatorEMailAddress === null) { |
|
482 | + throw new \Exception( |
|
483 | + $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
484 | + ); |
|
485 | + } |
|
486 | + |
|
487 | + $subject = (string)$this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]); |
|
488 | + $bodyPart = $this->l->t("You just shared »%s« with %s. The share was already send to the recipient. Due to the security policies defined by the administrator of %s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.", [$filename, $shareWith, $this->defaults->getName()]); |
|
489 | + |
|
490 | + $message = $this->mailer->createMessage(); |
|
491 | + $emailTemplate = $this->mailer->createEMailTemplate(); |
|
492 | + |
|
493 | + $emailTemplate->addHeader(); |
|
494 | + $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
495 | + $emailTemplate->addBodyText($bodyPart); |
|
496 | + $emailTemplate->addBodyText($this->l->t('This is the password: %s', [$password])); |
|
497 | + $emailTemplate->addBodyText($this->l->t('You can chose a different password at any time in the share dialog.')); |
|
498 | + $emailTemplate->addFooter(); |
|
499 | + |
|
500 | + if ($initiatorEMailAddress) { |
|
501 | + $message->setFrom([$initiatorEMailAddress => $initiatorDisplayName]); |
|
502 | + } |
|
503 | + $message->setTo([$initiatorEMailAddress => $initiatorDisplayName]); |
|
504 | + $message->setSubject($subject); |
|
505 | + $message->setBody($emailTemplate->renderText(), 'text/plain'); |
|
506 | + $message->setHtmlBody($emailTemplate->renderHTML()); |
|
507 | + $this->mailer->send($message); |
|
508 | + |
|
509 | + $this->createPasswordSendActivity($share, $shareWith, true); |
|
510 | + |
|
511 | + return true; |
|
512 | + } |
|
513 | + |
|
514 | + /** |
|
515 | + * generate share token |
|
516 | + * |
|
517 | + * @return string |
|
518 | + */ |
|
519 | + protected function generateToken($size = 15) { |
|
520 | + $token = $this->secureRandom->generate( |
|
521 | + $size, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
522 | + return $token; |
|
523 | + } |
|
524 | + |
|
525 | + /** |
|
526 | + * Get all children of this share |
|
527 | + * |
|
528 | + * @param IShare $parent |
|
529 | + * @return IShare[] |
|
530 | + */ |
|
531 | + public function getChildren(IShare $parent) { |
|
532 | + $children = []; |
|
533 | + |
|
534 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
535 | + $qb->select('*') |
|
536 | + ->from('share') |
|
537 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
538 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
539 | + ->orderBy('id'); |
|
540 | + |
|
541 | + $cursor = $qb->execute(); |
|
542 | + while($data = $cursor->fetch()) { |
|
543 | + $children[] = $this->createShareObject($data); |
|
544 | + } |
|
545 | + $cursor->closeCursor(); |
|
546 | + |
|
547 | + return $children; |
|
548 | + } |
|
549 | + |
|
550 | + /** |
|
551 | + * add share to the database and return the ID |
|
552 | + * |
|
553 | + * @param int $itemSource |
|
554 | + * @param string $itemType |
|
555 | + * @param string $shareWith |
|
556 | + * @param string $sharedBy |
|
557 | + * @param string $uidOwner |
|
558 | + * @param int $permissions |
|
559 | + * @param string $token |
|
560 | + * @return int |
|
561 | + */ |
|
562 | + protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) { |
|
563 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
564 | + $qb->insert('share') |
|
565 | + ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
566 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
567 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
568 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
569 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
570 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
571 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
572 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
573 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
574 | + ->setValue('password', $qb->createNamedParameter($password)) |
|
575 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
576 | + |
|
577 | + /* |
|
578 | 578 | * Added to fix https://github.com/owncloud/core/issues/22215 |
579 | 579 | * Can be removed once we get rid of ajax/share.php |
580 | 580 | */ |
581 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
581 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
582 | 582 | |
583 | - $qb->execute(); |
|
584 | - $id = $qb->getLastInsertId(); |
|
583 | + $qb->execute(); |
|
584 | + $id = $qb->getLastInsertId(); |
|
585 | 585 | |
586 | - return (int)$id; |
|
587 | - } |
|
586 | + return (int)$id; |
|
587 | + } |
|
588 | 588 | |
589 | - /** |
|
590 | - * Update a share |
|
591 | - * |
|
592 | - * @param IShare $share |
|
593 | - * @param string|null $plainTextPassword |
|
594 | - * @return IShare The share object |
|
595 | - */ |
|
596 | - public function update(IShare $share, $plainTextPassword = null) { |
|
589 | + /** |
|
590 | + * Update a share |
|
591 | + * |
|
592 | + * @param IShare $share |
|
593 | + * @param string|null $plainTextPassword |
|
594 | + * @return IShare The share object |
|
595 | + */ |
|
596 | + public function update(IShare $share, $plainTextPassword = null) { |
|
597 | 597 | |
598 | - $originalShare = $this->getShareById($share->getId()); |
|
598 | + $originalShare = $this->getShareById($share->getId()); |
|
599 | 599 | |
600 | - // a real password was given |
|
601 | - $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
600 | + // a real password was given |
|
601 | + $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
602 | 602 | |
603 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
604 | - $this->sendPassword($share, $plainTextPassword); |
|
605 | - } |
|
606 | - /* |
|
603 | + if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
604 | + $this->sendPassword($share, $plainTextPassword); |
|
605 | + } |
|
606 | + /* |
|
607 | 607 | * We allow updating the permissions and password of mail shares |
608 | 608 | */ |
609 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
610 | - $qb->update('share') |
|
611 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
612 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
613 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
614 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
615 | - ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
616 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
617 | - ->execute(); |
|
618 | - |
|
619 | - return $share; |
|
620 | - } |
|
621 | - |
|
622 | - /** |
|
623 | - * @inheritdoc |
|
624 | - */ |
|
625 | - public function move(IShare $share, $recipient) { |
|
626 | - /** |
|
627 | - * nothing to do here, mail shares are only outgoing shares |
|
628 | - */ |
|
629 | - return $share; |
|
630 | - } |
|
631 | - |
|
632 | - /** |
|
633 | - * Delete a share (owner unShares the file) |
|
634 | - * |
|
635 | - * @param IShare $share |
|
636 | - */ |
|
637 | - public function delete(IShare $share) { |
|
638 | - $this->removeShareFromTable($share->getId()); |
|
639 | - } |
|
640 | - |
|
641 | - /** |
|
642 | - * @inheritdoc |
|
643 | - */ |
|
644 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
645 | - // nothing to do here, mail shares are only outgoing shares |
|
646 | - return; |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * @inheritdoc |
|
651 | - */ |
|
652 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
653 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
654 | - $qb->select('*') |
|
655 | - ->from('share'); |
|
656 | - |
|
657 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
658 | - |
|
659 | - /** |
|
660 | - * Reshares for this user are shares where they are the owner. |
|
661 | - */ |
|
662 | - if ($reshares === false) { |
|
663 | - //Special case for old shares created via the web UI |
|
664 | - $or1 = $qb->expr()->andX( |
|
665 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
666 | - $qb->expr()->isNull('uid_initiator') |
|
667 | - ); |
|
668 | - |
|
669 | - $qb->andWhere( |
|
670 | - $qb->expr()->orX( |
|
671 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
672 | - $or1 |
|
673 | - ) |
|
674 | - ); |
|
675 | - } else { |
|
676 | - $qb->andWhere( |
|
677 | - $qb->expr()->orX( |
|
678 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
679 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
680 | - ) |
|
681 | - ); |
|
682 | - } |
|
683 | - |
|
684 | - if ($node !== null) { |
|
685 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
686 | - } |
|
687 | - |
|
688 | - if ($limit !== -1) { |
|
689 | - $qb->setMaxResults($limit); |
|
690 | - } |
|
691 | - |
|
692 | - $qb->setFirstResult($offset); |
|
693 | - $qb->orderBy('id'); |
|
694 | - |
|
695 | - $cursor = $qb->execute(); |
|
696 | - $shares = []; |
|
697 | - while($data = $cursor->fetch()) { |
|
698 | - $shares[] = $this->createShareObject($data); |
|
699 | - } |
|
700 | - $cursor->closeCursor(); |
|
701 | - |
|
702 | - return $shares; |
|
703 | - } |
|
704 | - |
|
705 | - /** |
|
706 | - * @inheritdoc |
|
707 | - */ |
|
708 | - public function getShareById($id, $recipientId = null) { |
|
709 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
710 | - |
|
711 | - $qb->select('*') |
|
712 | - ->from('share') |
|
713 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
714 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
715 | - |
|
716 | - $cursor = $qb->execute(); |
|
717 | - $data = $cursor->fetch(); |
|
718 | - $cursor->closeCursor(); |
|
719 | - |
|
720 | - if ($data === false) { |
|
721 | - throw new ShareNotFound(); |
|
722 | - } |
|
723 | - |
|
724 | - try { |
|
725 | - $share = $this->createShareObject($data); |
|
726 | - } catch (InvalidShare $e) { |
|
727 | - throw new ShareNotFound(); |
|
728 | - } |
|
729 | - |
|
730 | - return $share; |
|
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Get shares for a given path |
|
735 | - * |
|
736 | - * @param \OCP\Files\Node $path |
|
737 | - * @return IShare[] |
|
738 | - */ |
|
739 | - public function getSharesByPath(Node $path) { |
|
740 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
741 | - |
|
742 | - $cursor = $qb->select('*') |
|
743 | - ->from('share') |
|
744 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
745 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
746 | - ->execute(); |
|
747 | - |
|
748 | - $shares = []; |
|
749 | - while($data = $cursor->fetch()) { |
|
750 | - $shares[] = $this->createShareObject($data); |
|
751 | - } |
|
752 | - $cursor->closeCursor(); |
|
753 | - |
|
754 | - return $shares; |
|
755 | - } |
|
756 | - |
|
757 | - /** |
|
758 | - * @inheritdoc |
|
759 | - */ |
|
760 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
761 | - /** @var IShare[] $shares */ |
|
762 | - $shares = []; |
|
763 | - |
|
764 | - //Get shares directly with this user |
|
765 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
766 | - $qb->select('*') |
|
767 | - ->from('share'); |
|
768 | - |
|
769 | - // Order by id |
|
770 | - $qb->orderBy('id'); |
|
771 | - |
|
772 | - // Set limit and offset |
|
773 | - if ($limit !== -1) { |
|
774 | - $qb->setMaxResults($limit); |
|
775 | - } |
|
776 | - $qb->setFirstResult($offset); |
|
777 | - |
|
778 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
779 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
780 | - |
|
781 | - // Filter by node if provided |
|
782 | - if ($node !== null) { |
|
783 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
784 | - } |
|
785 | - |
|
786 | - $cursor = $qb->execute(); |
|
787 | - |
|
788 | - while($data = $cursor->fetch()) { |
|
789 | - $shares[] = $this->createShareObject($data); |
|
790 | - } |
|
791 | - $cursor->closeCursor(); |
|
792 | - |
|
793 | - |
|
794 | - return $shares; |
|
795 | - } |
|
796 | - |
|
797 | - /** |
|
798 | - * Get a share by token |
|
799 | - * |
|
800 | - * @param string $token |
|
801 | - * @return IShare |
|
802 | - * @throws ShareNotFound |
|
803 | - */ |
|
804 | - public function getShareByToken($token) { |
|
805 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
806 | - |
|
807 | - $cursor = $qb->select('*') |
|
808 | - ->from('share') |
|
809 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
810 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
811 | - ->execute(); |
|
812 | - |
|
813 | - $data = $cursor->fetch(); |
|
814 | - |
|
815 | - if ($data === false) { |
|
816 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
817 | - } |
|
818 | - |
|
819 | - try { |
|
820 | - $share = $this->createShareObject($data); |
|
821 | - } catch (InvalidShare $e) { |
|
822 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
823 | - } |
|
824 | - |
|
825 | - return $share; |
|
826 | - } |
|
827 | - |
|
828 | - /** |
|
829 | - * remove share from table |
|
830 | - * |
|
831 | - * @param string $shareId |
|
832 | - */ |
|
833 | - protected function removeShareFromTable($shareId) { |
|
834 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
835 | - $qb->delete('share') |
|
836 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
837 | - $qb->execute(); |
|
838 | - } |
|
839 | - |
|
840 | - /** |
|
841 | - * Create a share object from an database row |
|
842 | - * |
|
843 | - * @param array $data |
|
844 | - * @return IShare |
|
845 | - * @throws InvalidShare |
|
846 | - * @throws ShareNotFound |
|
847 | - */ |
|
848 | - protected function createShareObject($data) { |
|
849 | - |
|
850 | - $share = new Share($this->rootFolder, $this->userManager); |
|
851 | - $share->setId((int)$data['id']) |
|
852 | - ->setShareType((int)$data['share_type']) |
|
853 | - ->setPermissions((int)$data['permissions']) |
|
854 | - ->setTarget($data['file_target']) |
|
855 | - ->setMailSend((bool)$data['mail_send']) |
|
856 | - ->setToken($data['token']); |
|
857 | - |
|
858 | - $shareTime = new \DateTime(); |
|
859 | - $shareTime->setTimestamp((int)$data['stime']); |
|
860 | - $share->setShareTime($shareTime); |
|
861 | - $share->setSharedWith($data['share_with']); |
|
862 | - $share->setPassword($data['password']); |
|
863 | - |
|
864 | - if ($data['uid_initiator'] !== null) { |
|
865 | - $share->setShareOwner($data['uid_owner']); |
|
866 | - $share->setSharedBy($data['uid_initiator']); |
|
867 | - } else { |
|
868 | - //OLD SHARE |
|
869 | - $share->setSharedBy($data['uid_owner']); |
|
870 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
871 | - |
|
872 | - $owner = $path->getOwner(); |
|
873 | - $share->setShareOwner($owner->getUID()); |
|
874 | - } |
|
875 | - |
|
876 | - if ($data['expiration'] !== null) { |
|
877 | - $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
878 | - if ($expiration !== false) { |
|
879 | - $share->setExpirationDate($expiration); |
|
880 | - } |
|
881 | - } |
|
882 | - |
|
883 | - $share->setNodeId((int)$data['file_source']); |
|
884 | - $share->setNodeType($data['item_type']); |
|
885 | - |
|
886 | - $share->setProviderId($this->identifier()); |
|
887 | - |
|
888 | - return $share; |
|
889 | - } |
|
890 | - |
|
891 | - /** |
|
892 | - * Get the node with file $id for $user |
|
893 | - * |
|
894 | - * @param string $userId |
|
895 | - * @param int $id |
|
896 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
897 | - * @throws InvalidShare |
|
898 | - */ |
|
899 | - private function getNode($userId, $id) { |
|
900 | - try { |
|
901 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
902 | - } catch (NotFoundException $e) { |
|
903 | - throw new InvalidShare(); |
|
904 | - } |
|
905 | - |
|
906 | - $nodes = $userFolder->getById($id); |
|
907 | - |
|
908 | - if (empty($nodes)) { |
|
909 | - throw new InvalidShare(); |
|
910 | - } |
|
911 | - |
|
912 | - return $nodes[0]; |
|
913 | - } |
|
914 | - |
|
915 | - /** |
|
916 | - * A user is deleted from the system |
|
917 | - * So clean up the relevant shares. |
|
918 | - * |
|
919 | - * @param string $uid |
|
920 | - * @param int $shareType |
|
921 | - */ |
|
922 | - public function userDeleted($uid, $shareType) { |
|
923 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
924 | - |
|
925 | - $qb->delete('share') |
|
926 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
927 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
928 | - ->execute(); |
|
929 | - } |
|
930 | - |
|
931 | - /** |
|
932 | - * This provider does not support group shares |
|
933 | - * |
|
934 | - * @param string $gid |
|
935 | - */ |
|
936 | - public function groupDeleted($gid) { |
|
937 | - return; |
|
938 | - } |
|
939 | - |
|
940 | - /** |
|
941 | - * This provider does not support group shares |
|
942 | - * |
|
943 | - * @param string $uid |
|
944 | - * @param string $gid |
|
945 | - */ |
|
946 | - public function userDeletedFromGroup($uid, $gid) { |
|
947 | - return; |
|
948 | - } |
|
949 | - |
|
950 | - /** |
|
951 | - * get database row of a give share |
|
952 | - * |
|
953 | - * @param $id |
|
954 | - * @return array |
|
955 | - * @throws ShareNotFound |
|
956 | - */ |
|
957 | - protected function getRawShare($id) { |
|
958 | - |
|
959 | - // Now fetch the inserted share and create a complete share object |
|
960 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
961 | - $qb->select('*') |
|
962 | - ->from('share') |
|
963 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
964 | - |
|
965 | - $cursor = $qb->execute(); |
|
966 | - $data = $cursor->fetch(); |
|
967 | - $cursor->closeCursor(); |
|
968 | - |
|
969 | - if ($data === false) { |
|
970 | - throw new ShareNotFound; |
|
971 | - } |
|
972 | - |
|
973 | - return $data; |
|
974 | - } |
|
975 | - |
|
976 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
977 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
978 | - $qb->select('*') |
|
979 | - ->from('share', 's') |
|
980 | - ->andWhere($qb->expr()->orX( |
|
981 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
982 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
983 | - )) |
|
984 | - ->andWhere( |
|
985 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
986 | - ); |
|
987 | - |
|
988 | - /** |
|
989 | - * Reshares for this user are shares where they are the owner. |
|
990 | - */ |
|
991 | - if ($reshares === false) { |
|
992 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
993 | - } else { |
|
994 | - $qb->andWhere( |
|
995 | - $qb->expr()->orX( |
|
996 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
997 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
998 | - ) |
|
999 | - ); |
|
1000 | - } |
|
1001 | - |
|
1002 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
1003 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
1004 | - |
|
1005 | - $qb->orderBy('id'); |
|
1006 | - |
|
1007 | - $cursor = $qb->execute(); |
|
1008 | - $shares = []; |
|
1009 | - while ($data = $cursor->fetch()) { |
|
1010 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
1011 | - } |
|
1012 | - $cursor->closeCursor(); |
|
1013 | - |
|
1014 | - return $shares; |
|
1015 | - } |
|
1016 | - |
|
1017 | - /** |
|
1018 | - * @inheritdoc |
|
1019 | - */ |
|
1020 | - public function getAccessList($nodes, $currentAccess) { |
|
1021 | - $ids = []; |
|
1022 | - foreach ($nodes as $node) { |
|
1023 | - $ids[] = $node->getId(); |
|
1024 | - } |
|
1025 | - |
|
1026 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
1027 | - $qb->select('share_with') |
|
1028 | - ->from('share') |
|
1029 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
1030 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1031 | - ->andWhere($qb->expr()->orX( |
|
1032 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1033 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1034 | - )) |
|
1035 | - ->setMaxResults(1); |
|
1036 | - $cursor = $qb->execute(); |
|
1037 | - |
|
1038 | - $mail = $cursor->fetch() !== false; |
|
1039 | - $cursor->closeCursor(); |
|
1040 | - |
|
1041 | - return ['public' => $mail]; |
|
1042 | - } |
|
609 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
610 | + $qb->update('share') |
|
611 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
612 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
613 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
614 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
615 | + ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
616 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
617 | + ->execute(); |
|
618 | + |
|
619 | + return $share; |
|
620 | + } |
|
621 | + |
|
622 | + /** |
|
623 | + * @inheritdoc |
|
624 | + */ |
|
625 | + public function move(IShare $share, $recipient) { |
|
626 | + /** |
|
627 | + * nothing to do here, mail shares are only outgoing shares |
|
628 | + */ |
|
629 | + return $share; |
|
630 | + } |
|
631 | + |
|
632 | + /** |
|
633 | + * Delete a share (owner unShares the file) |
|
634 | + * |
|
635 | + * @param IShare $share |
|
636 | + */ |
|
637 | + public function delete(IShare $share) { |
|
638 | + $this->removeShareFromTable($share->getId()); |
|
639 | + } |
|
640 | + |
|
641 | + /** |
|
642 | + * @inheritdoc |
|
643 | + */ |
|
644 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
645 | + // nothing to do here, mail shares are only outgoing shares |
|
646 | + return; |
|
647 | + } |
|
648 | + |
|
649 | + /** |
|
650 | + * @inheritdoc |
|
651 | + */ |
|
652 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
653 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
654 | + $qb->select('*') |
|
655 | + ->from('share'); |
|
656 | + |
|
657 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
658 | + |
|
659 | + /** |
|
660 | + * Reshares for this user are shares where they are the owner. |
|
661 | + */ |
|
662 | + if ($reshares === false) { |
|
663 | + //Special case for old shares created via the web UI |
|
664 | + $or1 = $qb->expr()->andX( |
|
665 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
666 | + $qb->expr()->isNull('uid_initiator') |
|
667 | + ); |
|
668 | + |
|
669 | + $qb->andWhere( |
|
670 | + $qb->expr()->orX( |
|
671 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
672 | + $or1 |
|
673 | + ) |
|
674 | + ); |
|
675 | + } else { |
|
676 | + $qb->andWhere( |
|
677 | + $qb->expr()->orX( |
|
678 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
679 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
680 | + ) |
|
681 | + ); |
|
682 | + } |
|
683 | + |
|
684 | + if ($node !== null) { |
|
685 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
686 | + } |
|
687 | + |
|
688 | + if ($limit !== -1) { |
|
689 | + $qb->setMaxResults($limit); |
|
690 | + } |
|
691 | + |
|
692 | + $qb->setFirstResult($offset); |
|
693 | + $qb->orderBy('id'); |
|
694 | + |
|
695 | + $cursor = $qb->execute(); |
|
696 | + $shares = []; |
|
697 | + while($data = $cursor->fetch()) { |
|
698 | + $shares[] = $this->createShareObject($data); |
|
699 | + } |
|
700 | + $cursor->closeCursor(); |
|
701 | + |
|
702 | + return $shares; |
|
703 | + } |
|
704 | + |
|
705 | + /** |
|
706 | + * @inheritdoc |
|
707 | + */ |
|
708 | + public function getShareById($id, $recipientId = null) { |
|
709 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
710 | + |
|
711 | + $qb->select('*') |
|
712 | + ->from('share') |
|
713 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
714 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
715 | + |
|
716 | + $cursor = $qb->execute(); |
|
717 | + $data = $cursor->fetch(); |
|
718 | + $cursor->closeCursor(); |
|
719 | + |
|
720 | + if ($data === false) { |
|
721 | + throw new ShareNotFound(); |
|
722 | + } |
|
723 | + |
|
724 | + try { |
|
725 | + $share = $this->createShareObject($data); |
|
726 | + } catch (InvalidShare $e) { |
|
727 | + throw new ShareNotFound(); |
|
728 | + } |
|
729 | + |
|
730 | + return $share; |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Get shares for a given path |
|
735 | + * |
|
736 | + * @param \OCP\Files\Node $path |
|
737 | + * @return IShare[] |
|
738 | + */ |
|
739 | + public function getSharesByPath(Node $path) { |
|
740 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
741 | + |
|
742 | + $cursor = $qb->select('*') |
|
743 | + ->from('share') |
|
744 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
745 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
746 | + ->execute(); |
|
747 | + |
|
748 | + $shares = []; |
|
749 | + while($data = $cursor->fetch()) { |
|
750 | + $shares[] = $this->createShareObject($data); |
|
751 | + } |
|
752 | + $cursor->closeCursor(); |
|
753 | + |
|
754 | + return $shares; |
|
755 | + } |
|
756 | + |
|
757 | + /** |
|
758 | + * @inheritdoc |
|
759 | + */ |
|
760 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
761 | + /** @var IShare[] $shares */ |
|
762 | + $shares = []; |
|
763 | + |
|
764 | + //Get shares directly with this user |
|
765 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
766 | + $qb->select('*') |
|
767 | + ->from('share'); |
|
768 | + |
|
769 | + // Order by id |
|
770 | + $qb->orderBy('id'); |
|
771 | + |
|
772 | + // Set limit and offset |
|
773 | + if ($limit !== -1) { |
|
774 | + $qb->setMaxResults($limit); |
|
775 | + } |
|
776 | + $qb->setFirstResult($offset); |
|
777 | + |
|
778 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
779 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
780 | + |
|
781 | + // Filter by node if provided |
|
782 | + if ($node !== null) { |
|
783 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
784 | + } |
|
785 | + |
|
786 | + $cursor = $qb->execute(); |
|
787 | + |
|
788 | + while($data = $cursor->fetch()) { |
|
789 | + $shares[] = $this->createShareObject($data); |
|
790 | + } |
|
791 | + $cursor->closeCursor(); |
|
792 | + |
|
793 | + |
|
794 | + return $shares; |
|
795 | + } |
|
796 | + |
|
797 | + /** |
|
798 | + * Get a share by token |
|
799 | + * |
|
800 | + * @param string $token |
|
801 | + * @return IShare |
|
802 | + * @throws ShareNotFound |
|
803 | + */ |
|
804 | + public function getShareByToken($token) { |
|
805 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
806 | + |
|
807 | + $cursor = $qb->select('*') |
|
808 | + ->from('share') |
|
809 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
810 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
811 | + ->execute(); |
|
812 | + |
|
813 | + $data = $cursor->fetch(); |
|
814 | + |
|
815 | + if ($data === false) { |
|
816 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
817 | + } |
|
818 | + |
|
819 | + try { |
|
820 | + $share = $this->createShareObject($data); |
|
821 | + } catch (InvalidShare $e) { |
|
822 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
823 | + } |
|
824 | + |
|
825 | + return $share; |
|
826 | + } |
|
827 | + |
|
828 | + /** |
|
829 | + * remove share from table |
|
830 | + * |
|
831 | + * @param string $shareId |
|
832 | + */ |
|
833 | + protected function removeShareFromTable($shareId) { |
|
834 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
835 | + $qb->delete('share') |
|
836 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
837 | + $qb->execute(); |
|
838 | + } |
|
839 | + |
|
840 | + /** |
|
841 | + * Create a share object from an database row |
|
842 | + * |
|
843 | + * @param array $data |
|
844 | + * @return IShare |
|
845 | + * @throws InvalidShare |
|
846 | + * @throws ShareNotFound |
|
847 | + */ |
|
848 | + protected function createShareObject($data) { |
|
849 | + |
|
850 | + $share = new Share($this->rootFolder, $this->userManager); |
|
851 | + $share->setId((int)$data['id']) |
|
852 | + ->setShareType((int)$data['share_type']) |
|
853 | + ->setPermissions((int)$data['permissions']) |
|
854 | + ->setTarget($data['file_target']) |
|
855 | + ->setMailSend((bool)$data['mail_send']) |
|
856 | + ->setToken($data['token']); |
|
857 | + |
|
858 | + $shareTime = new \DateTime(); |
|
859 | + $shareTime->setTimestamp((int)$data['stime']); |
|
860 | + $share->setShareTime($shareTime); |
|
861 | + $share->setSharedWith($data['share_with']); |
|
862 | + $share->setPassword($data['password']); |
|
863 | + |
|
864 | + if ($data['uid_initiator'] !== null) { |
|
865 | + $share->setShareOwner($data['uid_owner']); |
|
866 | + $share->setSharedBy($data['uid_initiator']); |
|
867 | + } else { |
|
868 | + //OLD SHARE |
|
869 | + $share->setSharedBy($data['uid_owner']); |
|
870 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
871 | + |
|
872 | + $owner = $path->getOwner(); |
|
873 | + $share->setShareOwner($owner->getUID()); |
|
874 | + } |
|
875 | + |
|
876 | + if ($data['expiration'] !== null) { |
|
877 | + $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
878 | + if ($expiration !== false) { |
|
879 | + $share->setExpirationDate($expiration); |
|
880 | + } |
|
881 | + } |
|
882 | + |
|
883 | + $share->setNodeId((int)$data['file_source']); |
|
884 | + $share->setNodeType($data['item_type']); |
|
885 | + |
|
886 | + $share->setProviderId($this->identifier()); |
|
887 | + |
|
888 | + return $share; |
|
889 | + } |
|
890 | + |
|
891 | + /** |
|
892 | + * Get the node with file $id for $user |
|
893 | + * |
|
894 | + * @param string $userId |
|
895 | + * @param int $id |
|
896 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
897 | + * @throws InvalidShare |
|
898 | + */ |
|
899 | + private function getNode($userId, $id) { |
|
900 | + try { |
|
901 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
902 | + } catch (NotFoundException $e) { |
|
903 | + throw new InvalidShare(); |
|
904 | + } |
|
905 | + |
|
906 | + $nodes = $userFolder->getById($id); |
|
907 | + |
|
908 | + if (empty($nodes)) { |
|
909 | + throw new InvalidShare(); |
|
910 | + } |
|
911 | + |
|
912 | + return $nodes[0]; |
|
913 | + } |
|
914 | + |
|
915 | + /** |
|
916 | + * A user is deleted from the system |
|
917 | + * So clean up the relevant shares. |
|
918 | + * |
|
919 | + * @param string $uid |
|
920 | + * @param int $shareType |
|
921 | + */ |
|
922 | + public function userDeleted($uid, $shareType) { |
|
923 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
924 | + |
|
925 | + $qb->delete('share') |
|
926 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
927 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
928 | + ->execute(); |
|
929 | + } |
|
930 | + |
|
931 | + /** |
|
932 | + * This provider does not support group shares |
|
933 | + * |
|
934 | + * @param string $gid |
|
935 | + */ |
|
936 | + public function groupDeleted($gid) { |
|
937 | + return; |
|
938 | + } |
|
939 | + |
|
940 | + /** |
|
941 | + * This provider does not support group shares |
|
942 | + * |
|
943 | + * @param string $uid |
|
944 | + * @param string $gid |
|
945 | + */ |
|
946 | + public function userDeletedFromGroup($uid, $gid) { |
|
947 | + return; |
|
948 | + } |
|
949 | + |
|
950 | + /** |
|
951 | + * get database row of a give share |
|
952 | + * |
|
953 | + * @param $id |
|
954 | + * @return array |
|
955 | + * @throws ShareNotFound |
|
956 | + */ |
|
957 | + protected function getRawShare($id) { |
|
958 | + |
|
959 | + // Now fetch the inserted share and create a complete share object |
|
960 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
961 | + $qb->select('*') |
|
962 | + ->from('share') |
|
963 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
964 | + |
|
965 | + $cursor = $qb->execute(); |
|
966 | + $data = $cursor->fetch(); |
|
967 | + $cursor->closeCursor(); |
|
968 | + |
|
969 | + if ($data === false) { |
|
970 | + throw new ShareNotFound; |
|
971 | + } |
|
972 | + |
|
973 | + return $data; |
|
974 | + } |
|
975 | + |
|
976 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
977 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
978 | + $qb->select('*') |
|
979 | + ->from('share', 's') |
|
980 | + ->andWhere($qb->expr()->orX( |
|
981 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
982 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
983 | + )) |
|
984 | + ->andWhere( |
|
985 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
986 | + ); |
|
987 | + |
|
988 | + /** |
|
989 | + * Reshares for this user are shares where they are the owner. |
|
990 | + */ |
|
991 | + if ($reshares === false) { |
|
992 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
993 | + } else { |
|
994 | + $qb->andWhere( |
|
995 | + $qb->expr()->orX( |
|
996 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
997 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
998 | + ) |
|
999 | + ); |
|
1000 | + } |
|
1001 | + |
|
1002 | + $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
1003 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
1004 | + |
|
1005 | + $qb->orderBy('id'); |
|
1006 | + |
|
1007 | + $cursor = $qb->execute(); |
|
1008 | + $shares = []; |
|
1009 | + while ($data = $cursor->fetch()) { |
|
1010 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
1011 | + } |
|
1012 | + $cursor->closeCursor(); |
|
1013 | + |
|
1014 | + return $shares; |
|
1015 | + } |
|
1016 | + |
|
1017 | + /** |
|
1018 | + * @inheritdoc |
|
1019 | + */ |
|
1020 | + public function getAccessList($nodes, $currentAccess) { |
|
1021 | + $ids = []; |
|
1022 | + foreach ($nodes as $node) { |
|
1023 | + $ids[] = $node->getId(); |
|
1024 | + } |
|
1025 | + |
|
1026 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
1027 | + $qb->select('share_with') |
|
1028 | + ->from('share') |
|
1029 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
1030 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1031 | + ->andWhere($qb->expr()->orX( |
|
1032 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1033 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1034 | + )) |
|
1035 | + ->setMaxResults(1); |
|
1036 | + $cursor = $qb->execute(); |
|
1037 | + |
|
1038 | + $mail = $cursor->fetch() !== false; |
|
1039 | + $cursor->closeCursor(); |
|
1040 | + |
|
1041 | + return ['public' => $mail]; |
|
1042 | + } |
|
1043 | 1043 | |
1044 | 1044 | } |
@@ -321,11 +321,11 @@ discard block |
||
321 | 321 | $share->getSharedWith() |
322 | 322 | ); |
323 | 323 | } catch (HintException $hintException) { |
324 | - $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
324 | + $this->logger->error('Failed to send share by mail: '.$hintException->getMessage()); |
|
325 | 325 | $this->removeShareFromTable($shareId); |
326 | 326 | throw $hintException; |
327 | 327 | } catch (\Exception $e) { |
328 | - $this->logger->error('Failed to send share by mail: ' . $e->getMessage()); |
|
328 | + $this->logger->error('Failed to send share by mail: '.$e->getMessage()); |
|
329 | 329 | $this->removeShareFromTable($shareId); |
330 | 330 | throw new HintException('Failed to send share by mail', |
331 | 331 | $this->l->t('Failed to send share by E-mail')); |
@@ -354,9 +354,9 @@ discard block |
||
354 | 354 | $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
355 | 355 | $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
356 | 356 | if ($owner === $initiator) { |
357 | - $subject = (string)$this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
357 | + $subject = (string) $this->l->t('%s shared »%s« with you', array($ownerDisplayName, $filename)); |
|
358 | 358 | } else { |
359 | - $subject = (string)$this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
359 | + $subject = (string) $this->l->t('%s shared »%s« with you on behalf of %s', array($ownerDisplayName, $filename, $initiatorDisplayName)); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | $message = $this->mailer->createMessage(); |
@@ -368,10 +368,10 @@ discard block |
||
368 | 368 | if ($owner === $initiator) { |
369 | 369 | $text = $this->l->t('%s shared »%s« with you.', [$ownerDisplayName, $filename]); |
370 | 370 | } else { |
371 | - $text= $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); |
|
371 | + $text = $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); |
|
372 | 372 | } |
373 | 373 | $emailTemplate->addBodyText( |
374 | - $text . ' ' . $this->l->t('Click the button below to open it.'), |
|
374 | + $text.' '.$this->l->t('Click the button below to open it.'), |
|
375 | 375 | $text |
376 | 376 | ); |
377 | 377 | $emailTemplate->addBodyButton( |
@@ -400,9 +400,9 @@ discard block |
||
400 | 400 | // The "Reply-To" is set to the sharer if an mail address is configured |
401 | 401 | // also the default footer contains a "Do not reply" which needs to be adjusted. |
402 | 402 | $ownerEmail = $ownerUser->getEMailAddress(); |
403 | - if($ownerEmail !== null) { |
|
403 | + if ($ownerEmail !== null) { |
|
404 | 404 | $message->setReplyTo([$ownerEmail => $ownerDisplayName]); |
405 | - $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
405 | + $emailTemplate->addFooter($instanceName.' - '.$this->defaults->getSlogan()); |
|
406 | 406 | } else { |
407 | 407 | $emailTemplate->addFooter(); |
408 | 408 | } |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
435 | 435 | $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
436 | 436 | |
437 | - $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
437 | + $subject = (string) $this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); |
|
438 | 438 | $plainBodyPart = $this->l->t("%s shared »%s« with you.\nYou should have already received a separate mail with a link to access it.\n", [$initiatorDisplayName, $filename]); |
439 | 439 | $htmlBodyPart = $this->l->t('%s shared »%s« with you. You should have already received a separate mail with a link to access it.', [$initiatorDisplayName, $filename]); |
440 | 440 | |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | ); |
485 | 485 | } |
486 | 486 | |
487 | - $subject = (string)$this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]); |
|
487 | + $subject = (string) $this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith]); |
|
488 | 488 | $bodyPart = $this->l->t("You just shared »%s« with %s. The share was already send to the recipient. Due to the security policies defined by the administrator of %s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.", [$filename, $shareWith, $this->defaults->getName()]); |
489 | 489 | |
490 | 490 | $message = $this->mailer->createMessage(); |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | */ |
519 | 519 | protected function generateToken($size = 15) { |
520 | 520 | $token = $this->secureRandom->generate( |
521 | - $size, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); |
|
521 | + $size, ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
522 | 522 | return $token; |
523 | 523 | } |
524 | 524 | |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | ->orderBy('id'); |
540 | 540 | |
541 | 541 | $cursor = $qb->execute(); |
542 | - while($data = $cursor->fetch()) { |
|
542 | + while ($data = $cursor->fetch()) { |
|
543 | 543 | $children[] = $this->createShareObject($data); |
544 | 544 | } |
545 | 545 | $cursor->closeCursor(); |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | $qb->execute(); |
584 | 584 | $id = $qb->getLastInsertId(); |
585 | 585 | |
586 | - return (int)$id; |
|
586 | + return (int) $id; |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | // a real password was given |
601 | 601 | $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
602 | 602 | |
603 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
603 | + if ($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
604 | 604 | $this->sendPassword($share, $plainTextPassword); |
605 | 605 | } |
606 | 606 | /* |
@@ -694,7 +694,7 @@ discard block |
||
694 | 694 | |
695 | 695 | $cursor = $qb->execute(); |
696 | 696 | $shares = []; |
697 | - while($data = $cursor->fetch()) { |
|
697 | + while ($data = $cursor->fetch()) { |
|
698 | 698 | $shares[] = $this->createShareObject($data); |
699 | 699 | } |
700 | 700 | $cursor->closeCursor(); |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | ->execute(); |
747 | 747 | |
748 | 748 | $shares = []; |
749 | - while($data = $cursor->fetch()) { |
|
749 | + while ($data = $cursor->fetch()) { |
|
750 | 750 | $shares[] = $this->createShareObject($data); |
751 | 751 | } |
752 | 752 | $cursor->closeCursor(); |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | |
786 | 786 | $cursor = $qb->execute(); |
787 | 787 | |
788 | - while($data = $cursor->fetch()) { |
|
788 | + while ($data = $cursor->fetch()) { |
|
789 | 789 | $shares[] = $this->createShareObject($data); |
790 | 790 | } |
791 | 791 | $cursor->closeCursor(); |
@@ -848,15 +848,15 @@ discard block |
||
848 | 848 | protected function createShareObject($data) { |
849 | 849 | |
850 | 850 | $share = new Share($this->rootFolder, $this->userManager); |
851 | - $share->setId((int)$data['id']) |
|
852 | - ->setShareType((int)$data['share_type']) |
|
853 | - ->setPermissions((int)$data['permissions']) |
|
851 | + $share->setId((int) $data['id']) |
|
852 | + ->setShareType((int) $data['share_type']) |
|
853 | + ->setPermissions((int) $data['permissions']) |
|
854 | 854 | ->setTarget($data['file_target']) |
855 | - ->setMailSend((bool)$data['mail_send']) |
|
855 | + ->setMailSend((bool) $data['mail_send']) |
|
856 | 856 | ->setToken($data['token']); |
857 | 857 | |
858 | 858 | $shareTime = new \DateTime(); |
859 | - $shareTime->setTimestamp((int)$data['stime']); |
|
859 | + $shareTime->setTimestamp((int) $data['stime']); |
|
860 | 860 | $share->setShareTime($shareTime); |
861 | 861 | $share->setSharedWith($data['share_with']); |
862 | 862 | $share->setPassword($data['password']); |
@@ -867,7 +867,7 @@ discard block |
||
867 | 867 | } else { |
868 | 868 | //OLD SHARE |
869 | 869 | $share->setSharedBy($data['uid_owner']); |
870 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
870 | + $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']); |
|
871 | 871 | |
872 | 872 | $owner = $path->getOwner(); |
873 | 873 | $share->setShareOwner($owner->getUID()); |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | } |
881 | 881 | } |
882 | 882 | |
883 | - $share->setNodeId((int)$data['file_source']); |
|
883 | + $share->setNodeId((int) $data['file_source']); |
|
884 | 884 | $share->setNodeType($data['item_type']); |
885 | 885 | |
886 | 886 | $share->setProviderId($this->identifier()); |
@@ -999,7 +999,7 @@ discard block |
||
999 | 999 | ); |
1000 | 1000 | } |
1001 | 1001 | |
1002 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
1002 | + $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
1003 | 1003 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
1004 | 1004 | |
1005 | 1005 | $qb->orderBy('id'); |
@@ -33,272 +33,272 @@ |
||
33 | 33 | |
34 | 34 | class Activity implements IProvider { |
35 | 35 | |
36 | - /** @var IFactory */ |
|
37 | - protected $languageFactory; |
|
38 | - |
|
39 | - /** @var IL10N */ |
|
40 | - protected $l; |
|
41 | - |
|
42 | - /** @var IURLGenerator */ |
|
43 | - protected $url; |
|
44 | - |
|
45 | - /** @var IManager */ |
|
46 | - protected $activityManager; |
|
47 | - |
|
48 | - /** @var IUserManager */ |
|
49 | - protected $userManager; |
|
50 | - /** @var IContactsManager */ |
|
51 | - protected $contactsManager; |
|
52 | - |
|
53 | - /** @var array */ |
|
54 | - protected $displayNames = []; |
|
55 | - |
|
56 | - /** @var array */ |
|
57 | - protected $contactNames = []; |
|
58 | - |
|
59 | - const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self'; |
|
60 | - const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by'; |
|
61 | - const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send'; |
|
62 | - const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self'; |
|
63 | - |
|
64 | - /** |
|
65 | - * @param IFactory $languageFactory |
|
66 | - * @param IURLGenerator $url |
|
67 | - * @param IManager $activityManager |
|
68 | - * @param IUserManager $userManager |
|
69 | - * @param IContactsManager $contactsManager |
|
70 | - */ |
|
71 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) { |
|
72 | - $this->languageFactory = $languageFactory; |
|
73 | - $this->url = $url; |
|
74 | - $this->activityManager = $activityManager; |
|
75 | - $this->userManager = $userManager; |
|
76 | - $this->contactsManager = $contactsManager; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $language |
|
81 | - * @param IEvent $event |
|
82 | - * @param IEvent|null $previousEvent |
|
83 | - * @return IEvent |
|
84 | - * @throws \InvalidArgumentException |
|
85 | - * @since 11.0.0 |
|
86 | - */ |
|
87 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
88 | - if ($event->getApp() !== 'sharebymail') { |
|
89 | - throw new \InvalidArgumentException(); |
|
90 | - } |
|
91 | - |
|
92 | - $this->l = $this->languageFactory->get('sharebymail', $language); |
|
93 | - |
|
94 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
95 | - try { |
|
96 | - return $this->parseShortVersion($event); |
|
97 | - } catch (\InvalidArgumentException $e) { |
|
98 | - // Ignore and simply use the long version... |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - return $this->parseLongVersion($event); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param IEvent $event |
|
107 | - * @return IEvent |
|
108 | - * @throws \InvalidArgumentException |
|
109 | - * @since 11.0.0 |
|
110 | - */ |
|
111 | - public function parseShortVersion(IEvent $event) { |
|
112 | - $parsedParameters = $this->getParsedParameters($event); |
|
113 | - |
|
114 | - if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
115 | - $event->setParsedSubject($this->l->t('Shared with %1$s', [ |
|
116 | - $parsedParameters['email']['name'], |
|
117 | - ])) |
|
118 | - ->setRichSubject($this->l->t('Shared with {email}'), [ |
|
119 | - 'email' => $parsedParameters['email'], |
|
120 | - ]) |
|
121 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
122 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
123 | - $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [ |
|
124 | - $parsedParameters['email']['name'], |
|
125 | - $parsedParameters['actor']['name'], |
|
126 | - ])) |
|
127 | - ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [ |
|
128 | - 'email' => $parsedParameters['email'], |
|
129 | - 'actor' => $parsedParameters['actor'], |
|
130 | - ]) |
|
131 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
132 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
133 | - $event->setParsedSubject($this->l->t('Password for mail share send to %1$s', [ |
|
134 | - $parsedParameters['email']['name'] |
|
135 | - ])) |
|
136 | - ->setRichSubject($this->l->t('Password for mail share send to {email}'), [ |
|
137 | - 'email' => $parsedParameters['email'] |
|
138 | - ]) |
|
139 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
140 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
141 | - $event->setParsedSubject($this->l->t('Password for mail share send to you')) |
|
142 | - ->setRichSubject($this->l->t('Password for mail share send to you')) |
|
143 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
144 | - } else { |
|
145 | - throw new \InvalidArgumentException(); |
|
146 | - } |
|
147 | - |
|
148 | - return $event; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @param IEvent $event |
|
153 | - * @return IEvent |
|
154 | - * @throws \InvalidArgumentException |
|
155 | - * @since 11.0.0 |
|
156 | - */ |
|
157 | - public function parseLongVersion(IEvent $event) { |
|
158 | - $parsedParameters = $this->getParsedParameters($event); |
|
159 | - |
|
160 | - if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
161 | - $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [ |
|
162 | - $parsedParameters['file']['path'], |
|
163 | - $parsedParameters['email']['name'], |
|
164 | - ])) |
|
165 | - ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters) |
|
166 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
167 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
168 | - $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [ |
|
169 | - $parsedParameters['file']['path'], |
|
170 | - $parsedParameters['email']['name'], |
|
171 | - $parsedParameters['actor']['name'], |
|
172 | - ])) |
|
173 | - ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters) |
|
174 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
175 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
176 | - $event->setParsedSubject($this->l->t('Password to access %1$s was send to %2s', [ |
|
177 | - $parsedParameters['file']['path'], |
|
178 | - $parsedParameters['email']['name'] |
|
179 | - ])) |
|
180 | - ->setRichSubject($this->l->t('Password to access {file} was send to {email}'), $parsedParameters) |
|
181 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
182 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
183 | - $event->setParsedSubject( |
|
184 | - $this->l->t('Password to access %1$s was send to you', |
|
185 | - [$parsedParameters['file']['path']])) |
|
186 | - ->setRichSubject($this->l->t('Password to access {file} was send to you'), $parsedParameters) |
|
187 | - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
188 | - |
|
189 | - } else { |
|
190 | - throw new \InvalidArgumentException(); |
|
191 | - } |
|
192 | - |
|
193 | - return $event; |
|
194 | - } |
|
195 | - |
|
196 | - protected function getParsedParameters(IEvent $event) { |
|
197 | - $subject = $event->getSubject(); |
|
198 | - $parameters = $event->getSubjectParameters(); |
|
199 | - |
|
200 | - switch ($subject) { |
|
201 | - case self::SUBJECT_SHARED_EMAIL_SELF: |
|
202 | - return [ |
|
203 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
204 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
205 | - ]; |
|
206 | - case self::SUBJECT_SHARED_EMAIL_BY: |
|
207 | - return [ |
|
208 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
209 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
210 | - 'actor' => $this->generateUserParameter($parameters[2]), |
|
211 | - ]; |
|
212 | - case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND: |
|
213 | - return [ |
|
214 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
215 | - 'email' => $this->generateEmailParameter($parameters[1]), |
|
216 | - ]; |
|
217 | - case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF: |
|
218 | - return [ |
|
219 | - 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
220 | - ]; |
|
221 | - } |
|
222 | - throw new \InvalidArgumentException(); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * @param int $id |
|
227 | - * @param string $path |
|
228 | - * @return array |
|
229 | - */ |
|
230 | - protected function generateFileParameter($id, $path) { |
|
231 | - return [ |
|
232 | - 'type' => 'file', |
|
233 | - 'id' => $id, |
|
234 | - 'name' => basename($path), |
|
235 | - 'path' => trim($path, '/'), |
|
236 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
237 | - ]; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @param string $email |
|
242 | - * @return array |
|
243 | - */ |
|
244 | - protected function generateEmailParameter($email) { |
|
245 | - if (!isset($this->contactNames[$email])) { |
|
246 | - $this->contactNames[$email] = $this->getContactName($email); |
|
247 | - } |
|
248 | - |
|
249 | - return [ |
|
250 | - 'type' => 'email', |
|
251 | - 'id' => $email, |
|
252 | - 'name' => $this->contactNames[$email], |
|
253 | - ]; |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * @param string $uid |
|
258 | - * @return array |
|
259 | - */ |
|
260 | - protected function generateUserParameter($uid) { |
|
261 | - if (!isset($this->displayNames[$uid])) { |
|
262 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
263 | - } |
|
264 | - |
|
265 | - return [ |
|
266 | - 'type' => 'user', |
|
267 | - 'id' => $uid, |
|
268 | - 'name' => $this->displayNames[$uid], |
|
269 | - ]; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * @param string $email |
|
274 | - * @return string |
|
275 | - */ |
|
276 | - protected function getContactName($email) { |
|
277 | - $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']); |
|
278 | - |
|
279 | - foreach ($addressBookContacts as $contact) { |
|
280 | - if (isset($contact['isLocalSystemBook'])) { |
|
281 | - continue; |
|
282 | - } |
|
283 | - |
|
284 | - if (in_array($email, $contact['EMAIL'])) { |
|
285 | - return $contact['FN']; |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - return $email; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * @param string $uid |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - protected function getDisplayName($uid) { |
|
297 | - $user = $this->userManager->get($uid); |
|
298 | - if ($user instanceof IUser) { |
|
299 | - return $user->getDisplayName(); |
|
300 | - } else { |
|
301 | - return $uid; |
|
302 | - } |
|
303 | - } |
|
36 | + /** @var IFactory */ |
|
37 | + protected $languageFactory; |
|
38 | + |
|
39 | + /** @var IL10N */ |
|
40 | + protected $l; |
|
41 | + |
|
42 | + /** @var IURLGenerator */ |
|
43 | + protected $url; |
|
44 | + |
|
45 | + /** @var IManager */ |
|
46 | + protected $activityManager; |
|
47 | + |
|
48 | + /** @var IUserManager */ |
|
49 | + protected $userManager; |
|
50 | + /** @var IContactsManager */ |
|
51 | + protected $contactsManager; |
|
52 | + |
|
53 | + /** @var array */ |
|
54 | + protected $displayNames = []; |
|
55 | + |
|
56 | + /** @var array */ |
|
57 | + protected $contactNames = []; |
|
58 | + |
|
59 | + const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self'; |
|
60 | + const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by'; |
|
61 | + const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send'; |
|
62 | + const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self'; |
|
63 | + |
|
64 | + /** |
|
65 | + * @param IFactory $languageFactory |
|
66 | + * @param IURLGenerator $url |
|
67 | + * @param IManager $activityManager |
|
68 | + * @param IUserManager $userManager |
|
69 | + * @param IContactsManager $contactsManager |
|
70 | + */ |
|
71 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IContactsManager $contactsManager) { |
|
72 | + $this->languageFactory = $languageFactory; |
|
73 | + $this->url = $url; |
|
74 | + $this->activityManager = $activityManager; |
|
75 | + $this->userManager = $userManager; |
|
76 | + $this->contactsManager = $contactsManager; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $language |
|
81 | + * @param IEvent $event |
|
82 | + * @param IEvent|null $previousEvent |
|
83 | + * @return IEvent |
|
84 | + * @throws \InvalidArgumentException |
|
85 | + * @since 11.0.0 |
|
86 | + */ |
|
87 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
88 | + if ($event->getApp() !== 'sharebymail') { |
|
89 | + throw new \InvalidArgumentException(); |
|
90 | + } |
|
91 | + |
|
92 | + $this->l = $this->languageFactory->get('sharebymail', $language); |
|
93 | + |
|
94 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
95 | + try { |
|
96 | + return $this->parseShortVersion($event); |
|
97 | + } catch (\InvalidArgumentException $e) { |
|
98 | + // Ignore and simply use the long version... |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + return $this->parseLongVersion($event); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param IEvent $event |
|
107 | + * @return IEvent |
|
108 | + * @throws \InvalidArgumentException |
|
109 | + * @since 11.0.0 |
|
110 | + */ |
|
111 | + public function parseShortVersion(IEvent $event) { |
|
112 | + $parsedParameters = $this->getParsedParameters($event); |
|
113 | + |
|
114 | + if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
115 | + $event->setParsedSubject($this->l->t('Shared with %1$s', [ |
|
116 | + $parsedParameters['email']['name'], |
|
117 | + ])) |
|
118 | + ->setRichSubject($this->l->t('Shared with {email}'), [ |
|
119 | + 'email' => $parsedParameters['email'], |
|
120 | + ]) |
|
121 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
122 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
123 | + $event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [ |
|
124 | + $parsedParameters['email']['name'], |
|
125 | + $parsedParameters['actor']['name'], |
|
126 | + ])) |
|
127 | + ->setRichSubject($this->l->t('Shared with {email} by {actor}'), [ |
|
128 | + 'email' => $parsedParameters['email'], |
|
129 | + 'actor' => $parsedParameters['actor'], |
|
130 | + ]) |
|
131 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
132 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
133 | + $event->setParsedSubject($this->l->t('Password for mail share send to %1$s', [ |
|
134 | + $parsedParameters['email']['name'] |
|
135 | + ])) |
|
136 | + ->setRichSubject($this->l->t('Password for mail share send to {email}'), [ |
|
137 | + 'email' => $parsedParameters['email'] |
|
138 | + ]) |
|
139 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
140 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
141 | + $event->setParsedSubject($this->l->t('Password for mail share send to you')) |
|
142 | + ->setRichSubject($this->l->t('Password for mail share send to you')) |
|
143 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
144 | + } else { |
|
145 | + throw new \InvalidArgumentException(); |
|
146 | + } |
|
147 | + |
|
148 | + return $event; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @param IEvent $event |
|
153 | + * @return IEvent |
|
154 | + * @throws \InvalidArgumentException |
|
155 | + * @since 11.0.0 |
|
156 | + */ |
|
157 | + public function parseLongVersion(IEvent $event) { |
|
158 | + $parsedParameters = $this->getParsedParameters($event); |
|
159 | + |
|
160 | + if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_SELF) { |
|
161 | + $event->setParsedSubject($this->l->t('You shared %1$s with %2$s by mail', [ |
|
162 | + $parsedParameters['file']['path'], |
|
163 | + $parsedParameters['email']['name'], |
|
164 | + ])) |
|
165 | + ->setRichSubject($this->l->t('You shared {file} with {email} by mail'), $parsedParameters) |
|
166 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
167 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) { |
|
168 | + $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [ |
|
169 | + $parsedParameters['file']['path'], |
|
170 | + $parsedParameters['email']['name'], |
|
171 | + $parsedParameters['actor']['name'], |
|
172 | + ])) |
|
173 | + ->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters) |
|
174 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
175 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) { |
|
176 | + $event->setParsedSubject($this->l->t('Password to access %1$s was send to %2s', [ |
|
177 | + $parsedParameters['file']['path'], |
|
178 | + $parsedParameters['email']['name'] |
|
179 | + ])) |
|
180 | + ->setRichSubject($this->l->t('Password to access {file} was send to {email}'), $parsedParameters) |
|
181 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
182 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) { |
|
183 | + $event->setParsedSubject( |
|
184 | + $this->l->t('Password to access %1$s was send to you', |
|
185 | + [$parsedParameters['file']['path']])) |
|
186 | + ->setRichSubject($this->l->t('Password to access {file} was send to you'), $parsedParameters) |
|
187 | + ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
188 | + |
|
189 | + } else { |
|
190 | + throw new \InvalidArgumentException(); |
|
191 | + } |
|
192 | + |
|
193 | + return $event; |
|
194 | + } |
|
195 | + |
|
196 | + protected function getParsedParameters(IEvent $event) { |
|
197 | + $subject = $event->getSubject(); |
|
198 | + $parameters = $event->getSubjectParameters(); |
|
199 | + |
|
200 | + switch ($subject) { |
|
201 | + case self::SUBJECT_SHARED_EMAIL_SELF: |
|
202 | + return [ |
|
203 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
204 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
205 | + ]; |
|
206 | + case self::SUBJECT_SHARED_EMAIL_BY: |
|
207 | + return [ |
|
208 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
209 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
210 | + 'actor' => $this->generateUserParameter($parameters[2]), |
|
211 | + ]; |
|
212 | + case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND: |
|
213 | + return [ |
|
214 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
215 | + 'email' => $this->generateEmailParameter($parameters[1]), |
|
216 | + ]; |
|
217 | + case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF: |
|
218 | + return [ |
|
219 | + 'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]), |
|
220 | + ]; |
|
221 | + } |
|
222 | + throw new \InvalidArgumentException(); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * @param int $id |
|
227 | + * @param string $path |
|
228 | + * @return array |
|
229 | + */ |
|
230 | + protected function generateFileParameter($id, $path) { |
|
231 | + return [ |
|
232 | + 'type' => 'file', |
|
233 | + 'id' => $id, |
|
234 | + 'name' => basename($path), |
|
235 | + 'path' => trim($path, '/'), |
|
236 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), |
|
237 | + ]; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @param string $email |
|
242 | + * @return array |
|
243 | + */ |
|
244 | + protected function generateEmailParameter($email) { |
|
245 | + if (!isset($this->contactNames[$email])) { |
|
246 | + $this->contactNames[$email] = $this->getContactName($email); |
|
247 | + } |
|
248 | + |
|
249 | + return [ |
|
250 | + 'type' => 'email', |
|
251 | + 'id' => $email, |
|
252 | + 'name' => $this->contactNames[$email], |
|
253 | + ]; |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * @param string $uid |
|
258 | + * @return array |
|
259 | + */ |
|
260 | + protected function generateUserParameter($uid) { |
|
261 | + if (!isset($this->displayNames[$uid])) { |
|
262 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
263 | + } |
|
264 | + |
|
265 | + return [ |
|
266 | + 'type' => 'user', |
|
267 | + 'id' => $uid, |
|
268 | + 'name' => $this->displayNames[$uid], |
|
269 | + ]; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * @param string $email |
|
274 | + * @return string |
|
275 | + */ |
|
276 | + protected function getContactName($email) { |
|
277 | + $addressBookContacts = $this->contactsManager->search($email, ['EMAIL']); |
|
278 | + |
|
279 | + foreach ($addressBookContacts as $contact) { |
|
280 | + if (isset($contact['isLocalSystemBook'])) { |
|
281 | + continue; |
|
282 | + } |
|
283 | + |
|
284 | + if (in_array($email, $contact['EMAIL'])) { |
|
285 | + return $contact['FN']; |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + return $email; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * @param string $uid |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + protected function getDisplayName($uid) { |
|
297 | + $user = $this->userManager->get($uid); |
|
298 | + if ($user instanceof IUser) { |
|
299 | + return $user->getDisplayName(); |
|
300 | + } else { |
|
301 | + return $uid; |
|
302 | + } |
|
303 | + } |
|
304 | 304 | } |
@@ -42,223 +42,223 @@ |
||
42 | 42 | */ |
43 | 43 | class ProviderFactory implements IProviderFactory { |
44 | 44 | |
45 | - /** @var IServerContainer */ |
|
46 | - private $serverContainer; |
|
47 | - /** @var DefaultShareProvider */ |
|
48 | - private $defaultProvider = null; |
|
49 | - /** @var FederatedShareProvider */ |
|
50 | - private $federatedProvider = null; |
|
51 | - /** @var ShareByMailProvider */ |
|
52 | - private $shareByMailProvider; |
|
53 | - /** @var \OCA\Circles\ShareByCircleProvider; |
|
54 | - * ShareByCircleProvider */ |
|
55 | - private $shareByCircleProvider; |
|
56 | - |
|
57 | - /** |
|
58 | - * IProviderFactory constructor. |
|
59 | - * |
|
60 | - * @param IServerContainer $serverContainer |
|
61 | - */ |
|
62 | - public function __construct(IServerContainer $serverContainer) { |
|
63 | - $this->serverContainer = $serverContainer; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Create the default share provider. |
|
68 | - * |
|
69 | - * @return DefaultShareProvider |
|
70 | - */ |
|
71 | - protected function defaultShareProvider() { |
|
72 | - if ($this->defaultProvider === null) { |
|
73 | - $this->defaultProvider = new DefaultShareProvider( |
|
74 | - $this->serverContainer->getDatabaseConnection(), |
|
75 | - $this->serverContainer->getUserManager(), |
|
76 | - $this->serverContainer->getGroupManager(), |
|
77 | - $this->serverContainer->getLazyRootFolder() |
|
78 | - ); |
|
79 | - } |
|
80 | - |
|
81 | - return $this->defaultProvider; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Create the federated share provider |
|
86 | - * |
|
87 | - * @return FederatedShareProvider |
|
88 | - */ |
|
89 | - protected function federatedShareProvider() { |
|
90 | - if ($this->federatedProvider === null) { |
|
91 | - /* |
|
45 | + /** @var IServerContainer */ |
|
46 | + private $serverContainer; |
|
47 | + /** @var DefaultShareProvider */ |
|
48 | + private $defaultProvider = null; |
|
49 | + /** @var FederatedShareProvider */ |
|
50 | + private $federatedProvider = null; |
|
51 | + /** @var ShareByMailProvider */ |
|
52 | + private $shareByMailProvider; |
|
53 | + /** @var \OCA\Circles\ShareByCircleProvider; |
|
54 | + * ShareByCircleProvider */ |
|
55 | + private $shareByCircleProvider; |
|
56 | + |
|
57 | + /** |
|
58 | + * IProviderFactory constructor. |
|
59 | + * |
|
60 | + * @param IServerContainer $serverContainer |
|
61 | + */ |
|
62 | + public function __construct(IServerContainer $serverContainer) { |
|
63 | + $this->serverContainer = $serverContainer; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Create the default share provider. |
|
68 | + * |
|
69 | + * @return DefaultShareProvider |
|
70 | + */ |
|
71 | + protected function defaultShareProvider() { |
|
72 | + if ($this->defaultProvider === null) { |
|
73 | + $this->defaultProvider = new DefaultShareProvider( |
|
74 | + $this->serverContainer->getDatabaseConnection(), |
|
75 | + $this->serverContainer->getUserManager(), |
|
76 | + $this->serverContainer->getGroupManager(), |
|
77 | + $this->serverContainer->getLazyRootFolder() |
|
78 | + ); |
|
79 | + } |
|
80 | + |
|
81 | + return $this->defaultProvider; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Create the federated share provider |
|
86 | + * |
|
87 | + * @return FederatedShareProvider |
|
88 | + */ |
|
89 | + protected function federatedShareProvider() { |
|
90 | + if ($this->federatedProvider === null) { |
|
91 | + /* |
|
92 | 92 | * Check if the app is enabled |
93 | 93 | */ |
94 | - $appManager = $this->serverContainer->getAppManager(); |
|
95 | - if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
96 | - return null; |
|
97 | - } |
|
94 | + $appManager = $this->serverContainer->getAppManager(); |
|
95 | + if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
96 | + return null; |
|
97 | + } |
|
98 | 98 | |
99 | - /* |
|
99 | + /* |
|
100 | 100 | * TODO: add factory to federated sharing app |
101 | 101 | */ |
102 | - $l = $this->serverContainer->getL10N('federatedfilessharing'); |
|
103 | - $addressHandler = new AddressHandler( |
|
104 | - $this->serverContainer->getURLGenerator(), |
|
105 | - $l, |
|
106 | - $this->serverContainer->getCloudIdManager() |
|
107 | - ); |
|
108 | - $notifications = new Notifications( |
|
109 | - $addressHandler, |
|
110 | - $this->serverContainer->getHTTPClientService(), |
|
111 | - $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), |
|
112 | - $this->serverContainer->getJobList() |
|
113 | - ); |
|
114 | - $tokenHandler = new TokenHandler( |
|
115 | - $this->serverContainer->getSecureRandom() |
|
116 | - ); |
|
117 | - |
|
118 | - $this->federatedProvider = new FederatedShareProvider( |
|
119 | - $this->serverContainer->getDatabaseConnection(), |
|
120 | - $addressHandler, |
|
121 | - $notifications, |
|
122 | - $tokenHandler, |
|
123 | - $l, |
|
124 | - $this->serverContainer->getLogger(), |
|
125 | - $this->serverContainer->getLazyRootFolder(), |
|
126 | - $this->serverContainer->getConfig(), |
|
127 | - $this->serverContainer->getUserManager(), |
|
128 | - $this->serverContainer->getCloudIdManager() |
|
129 | - ); |
|
130 | - } |
|
131 | - |
|
132 | - return $this->federatedProvider; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Create the federated share provider |
|
137 | - * |
|
138 | - * @return ShareByMailProvider |
|
139 | - */ |
|
140 | - protected function getShareByMailProvider() { |
|
141 | - if ($this->shareByMailProvider === null) { |
|
142 | - /* |
|
102 | + $l = $this->serverContainer->getL10N('federatedfilessharing'); |
|
103 | + $addressHandler = new AddressHandler( |
|
104 | + $this->serverContainer->getURLGenerator(), |
|
105 | + $l, |
|
106 | + $this->serverContainer->getCloudIdManager() |
|
107 | + ); |
|
108 | + $notifications = new Notifications( |
|
109 | + $addressHandler, |
|
110 | + $this->serverContainer->getHTTPClientService(), |
|
111 | + $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), |
|
112 | + $this->serverContainer->getJobList() |
|
113 | + ); |
|
114 | + $tokenHandler = new TokenHandler( |
|
115 | + $this->serverContainer->getSecureRandom() |
|
116 | + ); |
|
117 | + |
|
118 | + $this->federatedProvider = new FederatedShareProvider( |
|
119 | + $this->serverContainer->getDatabaseConnection(), |
|
120 | + $addressHandler, |
|
121 | + $notifications, |
|
122 | + $tokenHandler, |
|
123 | + $l, |
|
124 | + $this->serverContainer->getLogger(), |
|
125 | + $this->serverContainer->getLazyRootFolder(), |
|
126 | + $this->serverContainer->getConfig(), |
|
127 | + $this->serverContainer->getUserManager(), |
|
128 | + $this->serverContainer->getCloudIdManager() |
|
129 | + ); |
|
130 | + } |
|
131 | + |
|
132 | + return $this->federatedProvider; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Create the federated share provider |
|
137 | + * |
|
138 | + * @return ShareByMailProvider |
|
139 | + */ |
|
140 | + protected function getShareByMailProvider() { |
|
141 | + if ($this->shareByMailProvider === null) { |
|
142 | + /* |
|
143 | 143 | * Check if the app is enabled |
144 | 144 | */ |
145 | - $appManager = $this->serverContainer->getAppManager(); |
|
146 | - if (!$appManager->isEnabledForUser('sharebymail')) { |
|
147 | - return null; |
|
148 | - } |
|
149 | - |
|
150 | - $settingsManager = new SettingsManager($this->serverContainer->getConfig()); |
|
151 | - |
|
152 | - $this->shareByMailProvider = new ShareByMailProvider( |
|
153 | - $this->serverContainer->getDatabaseConnection(), |
|
154 | - $this->serverContainer->getSecureRandom(), |
|
155 | - $this->serverContainer->getUserManager(), |
|
156 | - $this->serverContainer->getLazyRootFolder(), |
|
157 | - $this->serverContainer->getL10N('sharebymail'), |
|
158 | - $this->serverContainer->getLogger(), |
|
159 | - $this->serverContainer->getMailer(), |
|
160 | - $this->serverContainer->getURLGenerator(), |
|
161 | - $this->serverContainer->getActivityManager(), |
|
162 | - $settingsManager, |
|
163 | - $this->serverContainer->query(Defaults::class), |
|
164 | - $this->serverContainer->getHasher() |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - return $this->shareByMailProvider; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * Create the circle share provider |
|
174 | - * |
|
175 | - * @return FederatedShareProvider |
|
176 | - */ |
|
177 | - protected function getShareByCircleProvider() { |
|
178 | - |
|
179 | - $appManager = $this->serverContainer->getAppManager(); |
|
180 | - if (!$appManager->isEnabledForUser('circles')) { |
|
181 | - return null; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - if ($this->shareByCircleProvider === null) { |
|
186 | - |
|
187 | - $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
188 | - $this->serverContainer->getDatabaseConnection(), |
|
189 | - $this->serverContainer->getSecureRandom(), |
|
190 | - $this->serverContainer->getUserManager(), |
|
191 | - $this->serverContainer->getLazyRootFolder(), |
|
192 | - $this->serverContainer->getL10N('circles'), |
|
193 | - $this->serverContainer->getLogger(), |
|
194 | - $this->serverContainer->getURLGenerator() |
|
195 | - ); |
|
196 | - } |
|
197 | - |
|
198 | - return $this->shareByCircleProvider; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @inheritdoc |
|
204 | - */ |
|
205 | - public function getProvider($id) { |
|
206 | - $provider = null; |
|
207 | - if ($id === 'ocinternal') { |
|
208 | - $provider = $this->defaultShareProvider(); |
|
209 | - } else if ($id === 'ocFederatedSharing') { |
|
210 | - $provider = $this->federatedShareProvider(); |
|
211 | - } else if ($id === 'ocMailShare') { |
|
212 | - $provider = $this->getShareByMailProvider(); |
|
213 | - } else if ($id === 'ocCircleShare') { |
|
214 | - $provider = $this->getShareByCircleProvider(); |
|
215 | - } |
|
216 | - |
|
217 | - if ($provider === null) { |
|
218 | - throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
219 | - } |
|
220 | - |
|
221 | - return $provider; |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @inheritdoc |
|
226 | - */ |
|
227 | - public function getProviderForType($shareType) { |
|
228 | - $provider = null; |
|
229 | - |
|
230 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
231 | - $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
232 | - $shareType === \OCP\Share::SHARE_TYPE_LINK |
|
233 | - ) { |
|
234 | - $provider = $this->defaultShareProvider(); |
|
235 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
236 | - $provider = $this->federatedShareProvider(); |
|
237 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
238 | - $provider = $this->getShareByMailProvider(); |
|
239 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
240 | - $provider = $this->getShareByCircleProvider(); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - if ($provider === null) { |
|
245 | - throw new ProviderException('No share provider for share type ' . $shareType); |
|
246 | - } |
|
247 | - |
|
248 | - return $provider; |
|
249 | - } |
|
250 | - |
|
251 | - public function getAllProviders() { |
|
252 | - $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
253 | - $shareByMail = $this->getShareByMailProvider(); |
|
254 | - if ($shareByMail !== null) { |
|
255 | - $shares[] = $shareByMail; |
|
256 | - } |
|
257 | - $shareByCircle = $this->getShareByCircleProvider(); |
|
258 | - if ($shareByCircle !== null) { |
|
259 | - $shares[] = $shareByCircle; |
|
260 | - } |
|
261 | - |
|
262 | - return $shares; |
|
263 | - } |
|
145 | + $appManager = $this->serverContainer->getAppManager(); |
|
146 | + if (!$appManager->isEnabledForUser('sharebymail')) { |
|
147 | + return null; |
|
148 | + } |
|
149 | + |
|
150 | + $settingsManager = new SettingsManager($this->serverContainer->getConfig()); |
|
151 | + |
|
152 | + $this->shareByMailProvider = new ShareByMailProvider( |
|
153 | + $this->serverContainer->getDatabaseConnection(), |
|
154 | + $this->serverContainer->getSecureRandom(), |
|
155 | + $this->serverContainer->getUserManager(), |
|
156 | + $this->serverContainer->getLazyRootFolder(), |
|
157 | + $this->serverContainer->getL10N('sharebymail'), |
|
158 | + $this->serverContainer->getLogger(), |
|
159 | + $this->serverContainer->getMailer(), |
|
160 | + $this->serverContainer->getURLGenerator(), |
|
161 | + $this->serverContainer->getActivityManager(), |
|
162 | + $settingsManager, |
|
163 | + $this->serverContainer->query(Defaults::class), |
|
164 | + $this->serverContainer->getHasher() |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + return $this->shareByMailProvider; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * Create the circle share provider |
|
174 | + * |
|
175 | + * @return FederatedShareProvider |
|
176 | + */ |
|
177 | + protected function getShareByCircleProvider() { |
|
178 | + |
|
179 | + $appManager = $this->serverContainer->getAppManager(); |
|
180 | + if (!$appManager->isEnabledForUser('circles')) { |
|
181 | + return null; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + if ($this->shareByCircleProvider === null) { |
|
186 | + |
|
187 | + $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
188 | + $this->serverContainer->getDatabaseConnection(), |
|
189 | + $this->serverContainer->getSecureRandom(), |
|
190 | + $this->serverContainer->getUserManager(), |
|
191 | + $this->serverContainer->getLazyRootFolder(), |
|
192 | + $this->serverContainer->getL10N('circles'), |
|
193 | + $this->serverContainer->getLogger(), |
|
194 | + $this->serverContainer->getURLGenerator() |
|
195 | + ); |
|
196 | + } |
|
197 | + |
|
198 | + return $this->shareByCircleProvider; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @inheritdoc |
|
204 | + */ |
|
205 | + public function getProvider($id) { |
|
206 | + $provider = null; |
|
207 | + if ($id === 'ocinternal') { |
|
208 | + $provider = $this->defaultShareProvider(); |
|
209 | + } else if ($id === 'ocFederatedSharing') { |
|
210 | + $provider = $this->federatedShareProvider(); |
|
211 | + } else if ($id === 'ocMailShare') { |
|
212 | + $provider = $this->getShareByMailProvider(); |
|
213 | + } else if ($id === 'ocCircleShare') { |
|
214 | + $provider = $this->getShareByCircleProvider(); |
|
215 | + } |
|
216 | + |
|
217 | + if ($provider === null) { |
|
218 | + throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
219 | + } |
|
220 | + |
|
221 | + return $provider; |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @inheritdoc |
|
226 | + */ |
|
227 | + public function getProviderForType($shareType) { |
|
228 | + $provider = null; |
|
229 | + |
|
230 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
231 | + $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
232 | + $shareType === \OCP\Share::SHARE_TYPE_LINK |
|
233 | + ) { |
|
234 | + $provider = $this->defaultShareProvider(); |
|
235 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
236 | + $provider = $this->federatedShareProvider(); |
|
237 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
238 | + $provider = $this->getShareByMailProvider(); |
|
239 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
240 | + $provider = $this->getShareByCircleProvider(); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + if ($provider === null) { |
|
245 | + throw new ProviderException('No share provider for share type ' . $shareType); |
|
246 | + } |
|
247 | + |
|
248 | + return $provider; |
|
249 | + } |
|
250 | + |
|
251 | + public function getAllProviders() { |
|
252 | + $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
253 | + $shareByMail = $this->getShareByMailProvider(); |
|
254 | + if ($shareByMail !== null) { |
|
255 | + $shares[] = $shareByMail; |
|
256 | + } |
|
257 | + $shareByCircle = $this->getShareByCircleProvider(); |
|
258 | + if ($shareByCircle !== null) { |
|
259 | + $shares[] = $shareByCircle; |
|
260 | + } |
|
261 | + |
|
262 | + return $shares; |
|
263 | + } |
|
264 | 264 | } |