Skip to content

Commit 30f9ef4

Browse files
committed
fix: psalm, cs, autoloader and lint
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 5ce4bb3 commit 30f9ef4

File tree

10 files changed

+46
-37
lines changed

10 files changed

+46
-37
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
use Exception;
1313
use OC\Files\FileInfo;
1414
use OC\Files\Storage\Wrapper\Wrapper;
15+
use OCA\Files\Helper;
1516
use OCA\Files_Sharing\Exceptions\SharingRightsException;
1617
use OCA\Files_Sharing\External\Storage;
18+
use OCA\Files_Sharing\ResponseDefinitions;
1719
use OCA\Files_Sharing\SharedStorage;
18-
use OCA\Files\Helper;
1920
use OCP\App\IAppManager;
2021
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
2122
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
23+
use OCP\AppFramework\Http\Attribute\UserRateLimit;
2224
use OCP\AppFramework\Http\DataResponse;
23-
use OCP\AppFramework\Http\JSONResponse;
2425
use OCP\AppFramework\OCS\OCSBadRequestException;
2526
use OCP\AppFramework\OCS\OCSException;
2627
use OCP\AppFramework\OCS\OCSForbiddenException;
@@ -523,6 +524,7 @@ public function deleteShare(string $id): DataResponse {
523524
* @param string $note Note for the share
524525
* @param string $label Label for the share (only used in link and email)
525526
* @param string|null $attributes Additional attributes for the share
527+
* @param 'false'|'true'|null $sendMail Send a mail to the recipient
526528
*
527529
* @return DataResponse<Http::STATUS_OK, Files_SharingShare, array{}>
528530
* @throws OCSBadRequestException Unknown share type
@@ -545,7 +547,7 @@ public function createShare(
545547
string $note = '',
546548
string $label = '',
547549
?string $attributes = null,
548-
?string $mailSend = null
550+
?string $sendMail = null
549551
): DataResponse {
550552
$share = $this->shareManager->newShare();
551553

@@ -636,8 +638,8 @@ public function createShare(
636638
$this->checkInheritedAttributes($share);
637639

638640
// Handle mail send
639-
if ($mailSend === 'true' || $mailSend === 'false') {
640-
$share->setMailSend($mailSend === 'true');
641+
if ($sendMail === 'true' || $sendMail === 'false') {
642+
$share->setMailSend($sendMail === 'true');
641643
}
642644

643645
if ($shareType === IShare::TYPE_USER) {
@@ -1132,7 +1134,7 @@ private function hasPermission(int $permissionsSet, int $permissionsToCheck): bo
11321134
* @param string|null $label New label
11331135
* @param string|null $hideDownload New condition if the download should be hidden
11341136
* @param string|null $attributes New additional attributes
1135-
* @param string|null $mailSend if the share should be send by mail.
1137+
* @param string|null $sendMail if the share should be send by mail.
11361138
* Considering the share already exists, no mail will be send after the share is updated.
11371139
* You will have to use the sendMail action to send the mail.
11381140
* @param string|null $shareWith New recipient for email shares
@@ -1154,7 +1156,7 @@ public function updateShare(
11541156
?string $label = null,
11551157
?string $hideDownload = null,
11561158
?string $attributes = null,
1157-
?string $mailSend = null,
1159+
?string $sendMail = null,
11581160
): DataResponse {
11591161
try {
11601162
$share = $this->getShareById($id);
@@ -1182,7 +1184,7 @@ public function updateShare(
11821184
$label === null &&
11831185
$hideDownload === null &&
11841186
$attributes === null &&
1185-
$mailSend === null
1187+
$sendMail === null
11861188
) {
11871189
throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
11881190
}
@@ -1197,8 +1199,8 @@ public function updateShare(
11971199
$this->checkInheritedAttributes($share);
11981200

11991201
// Handle mail send
1200-
if ($mailSend === 'true' || $mailSend === 'false') {
1201-
$share->setMailSend($mailSend === 'true');
1202+
if ($sendMail === 'true' || $sendMail === 'false') {
1203+
$share->setMailSend($sendMail === 'true');
12021204
}
12031205

12041206
/**
@@ -2061,13 +2063,14 @@ private function checkInheritedAttributes(IShare $share): void {
20612063
}
20622064

20632065
/**
2066+
* Send a mail notification again for a share.
2067+
* The mail_send option must be enabled for the given share.
20642068
* @param string $id
2065-
* @param string[] $emails a list of emails to send the notification to
2066-
* @return void
2069+
* @param string $password optional, the password to check against. Necessary for password protected shares.
20672070
*/
20682071
#[NoAdminRequired]
2069-
#[BruteForceProtection(action: 'sendShareEmail')]
2070-
public function sendShareEmail(string $id, $password = '') {
2072+
#[UserRateLimit(limit: 5, period: 120)]
2073+
public function sendShareEmail(string $id, $password = ''): DataResponse {
20712074
try {
20722075
$share = $this->getShareById($id);
20732076

@@ -2082,7 +2085,7 @@ public function sendShareEmail(string $id, $password = '') {
20822085
// For mail and link shares, the user must be
20832086
// the owner of the share, not only the file owner.
20842087
if ($share->getShareType() === IShare::TYPE_EMAIL
2085-
|| $share->getShareType() === IShare::TYPE_LINK){
2088+
|| $share->getShareType() === IShare::TYPE_LINK) {
20862089
if ($share->getSharedBy() !== $this->currentUser) {
20872090
throw new OCSForbiddenException('You are not allowed to send mail notifications');
20882091
}
@@ -2099,7 +2102,7 @@ public function sendShareEmail(string $id, $password = '') {
20992102
// the password clear, it is just a temporary
21002103
// object manipulation. The password will stay
21012104
// encrypted in the database.
2102-
if ($share->getPassword() && $share->getPassword() !== $password) {
2105+
if ($share->getPassword() !== null && $share->getPassword() !== $password) {
21032106
if (!$this->shareManager->checkPassword($share, $password)) {
21042107
throw new OCSBadRequestException($this->l->t('Wrong password'));
21052108
}

apps/files_sharing/src/components/NewFileRequestDialog.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export default defineComponent({
252252
const expireDate = this.deadline ? this.deadline.toISOString().split('T')[0] : undefined
253253
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares')
254254
try {
255-
const request = await axios.post(shareUrl, {
255+
const request = await axios.post<OCSResponse>(shareUrl, {
256256
shareType: Type.SHARE_TYPE_EMAIL,
257257
permissions: Permission.CREATE,
258258
@@ -269,7 +269,7 @@ export default defineComponent({
269269
value: true,
270270
key: 'enabled',
271271
scope: 'fileRequest',
272-
}])
272+
}]),
273273
})
274274
275275
// If not an ocs request
@@ -310,12 +310,12 @@ export default defineComponent({
310310
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares/' + this.share.id)
311311
try {
312312
// Convert link share to email share
313-
const request = await axios.put(shareUrl, {
313+
const request = await axios.put<OCSResponse>(shareUrl, {
314314
attributes: JSON.stringify([{
315315
value: this.emails,
316316
key: 'emails',
317317
scope: 'shareWith',
318-
}])
318+
}]),
319319
})
320320
321321
// If not an ocs request
@@ -341,7 +341,7 @@ export default defineComponent({
341341
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares/' + this.share.id + '/send-email')
342342
try {
343343
// Convert link share to email share
344-
const request = await axios.post(shareUrl, {
344+
const request = await axios.post<OCSResponse>(shareUrl, {
345345
password: this.password || undefined,
346346
})
347347

apps/files_sharing/src/new/newFileRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const entry = {
1616
iconSvgInline: FileUploadSvg,
1717
order: 30,
1818
enabled(): boolean {
19-
// determine requirements
19+
// TODO: determine requirements
2020
// 1. user can share the root folder
2121
// 2. OR user can create subfolders ?
2222
return true

apps/sharebymail/lib/ShareByMailProvider.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function create(IShare $share): IShare {
8181
// Check if file is not already shared with the given email,
8282
// if we have an email at all.
8383
$alreadyShared = $this->getSharedWith($shareWith, IShare::TYPE_EMAIL, $share->getNode(), 1, 0);
84-
if ($shareWith !== '' && !empty($alreadyShared)){
84+
if ($shareWith !== '' && !empty($alreadyShared)) {
8585
$message = 'Sharing %1$s failed, because this item is already shared with the account %2$s';
8686
$message_t = $this->l->t('Sharing %1$s failed, because this item is already shared with the account %2$s', [$share->getNode()->getName(), $shareWith]);
8787
$this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']);
@@ -238,12 +238,12 @@ public function sendMailNotification(IShare $share): bool {
238238
$shareId = $share->getId();
239239

240240
$emails = $this->getSharedWithEmails($share);
241-
$validEmails = array_filter($emails, function ($email) {
241+
$validEmails = array_filter($emails, function (string $email) {
242242
return $this->mailer->validateMailAddress($email);
243243
});
244244

245245
if (count($validEmails) === 0) {
246-
$this->removeShareFromTable($shareId);
246+
$this->removeShareFromTable((int)$shareId);
247247
$e = new HintException('Failed to send share by mail. Could not find a valid email address: ' . join(', ', $emails),
248248
$this->l->t('Failed to send share by email. Got an invalid email address'));
249249
$this->logger->error('Failed to send share by mail. Could not find a valid email address ' . join(', ', $emails), [
@@ -256,7 +256,7 @@ public function sendMailNotification(IShare $share): bool {
256256
$this->sendEmail($share, $validEmails);
257257

258258
// If we have a password set, we send it to the recipient
259-
if ($share->getPassword()) {
259+
if ($share->getPassword() !== null) {
260260
// Sends share password to receiver when it's a permanent one (otherwise she will have to request it via the showShare UI)
261261
// or to owner when the password shall be given during a Talk session
262262
$passwordExpire = $this->config->getSystemValue('sharing.enable_mail_link_password_expiration', false);
@@ -275,14 +275,14 @@ public function sendMailNotification(IShare $share): bool {
275275
'app' => 'sharebymail',
276276
'exception' => $hintException,
277277
]);
278-
$this->removeShareFromTable($shareId);
278+
$this->removeShareFromTable((int)$shareId);
279279
throw $hintException;
280280
} catch (\Exception $e) {
281281
$this->logger->error('Failed to send share by mail.', [
282282
'app' => 'sharebymail',
283283
'exception' => $e,
284284
]);
285-
$this->removeShareFromTable($shareId);
285+
$this->removeShareFromTable((int)$shareId);
286286
throw new HintException('Failed to send share by mail',
287287
$this->l->t('Failed to send share by email'));
288288
}
@@ -381,13 +381,13 @@ protected function sendEmail(IShare $share, array $emails): void {
381381
* 1. the password is empty
382382
* 2. the setting to send the password by mail is disabled
383383
* 3. the share is set to send the password by talk
384-
*
384+
*
385385
* @param IShare $share
386386
* @param string $password
387387
* @param array $emails
388388
* @return bool
389389
*/
390-
protected function sendPassword(IShare $share, string $password, array $emails) {
390+
protected function sendPassword(IShare $share, string $password, array $emails): bool {
391391
$filename = $share->getNode()->getName();
392392
$initiator = $share->getSharedBy();
393393
$shareWith = $share->getSharedWith();
@@ -463,10 +463,11 @@ protected function sendPassword(IShare $share, string $password, array $emails)
463463
$failedRecipients = $this->mailer->send($message);
464464
if (!empty($failedRecipients)) {
465465
$this->logger->error('Share password mail could not be sent to: ' . implode(', ', $failedRecipients));
466-
return;
466+
return false;
467467
}
468468

469469
$this->createPasswordSendActivity($share, $shareWith, false);
470+
return true;
470471
}
471472

472473
protected function sendNote(IShare $share): void {
@@ -1179,8 +1180,10 @@ public function getAllShares(): iterable {
11791180
* Extract the emails from the share
11801181
* It can be a single email, from the share_with field
11811182
* or a list of emails from the emails attributes field.
1183+
* @param IShare $share
1184+
* @return string[]
11821185
*/
1183-
protected function getSharedWithEmails(IShare $share) {
1186+
protected function getSharedWithEmails(IShare $share): array {
11841187
$attributes = $share->getAttributes();
11851188

11861189
if ($attributes === null) {

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@
682682
'OCP\\Share\\IShare' => $baseDir . '/lib/public/Share/IShare.php',
683683
'OCP\\Share\\IShareHelper' => $baseDir . '/lib/public/Share/IShareHelper.php',
684684
'OCP\\Share\\IShareProvider' => $baseDir . '/lib/public/Share/IShareProvider.php',
685+
'OCP\\Share\\IShareProviderWithNotification' => $baseDir . '/lib/public/Share/IShareProviderWithNotification.php',
685686
'OCP\\Share_Backend' => $baseDir . '/lib/public/Share_Backend.php',
686687
'OCP\\Share_Backend_Collection' => $baseDir . '/lib/public/Share_Backend_Collection.php',
687688
'OCP\\Share_Backend_File_Dependent' => $baseDir . '/lib/public/Share_Backend_File_Dependent.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
715715
'OCP\\Share\\IShare' => __DIR__ . '/../../..' . '/lib/public/Share/IShare.php',
716716
'OCP\\Share\\IShareHelper' => __DIR__ . '/../../..' . '/lib/public/Share/IShareHelper.php',
717717
'OCP\\Share\\IShareProvider' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProvider.php',
718+
'OCP\\Share\\IShareProviderWithNotification' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderWithNotification.php',
718719
'OCP\\Share_Backend' => __DIR__ . '/../../..' . '/lib/public/Share_Backend.php',
719720
'OCP\\Share_Backend_Collection' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_Collection.php',
720721
'OCP\\Share_Backend_File_Dependent' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_File_Dependent.php',

lib/composer/composer/installed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'name' => '__root__',
44
'pretty_version' => 'dev-master',
55
'version' => 'dev-master',
6-
'reference' => 'e0b9ff4fa255b4dd4c1e3881e26dff18053e129a',
6+
'reference' => 'b99276fdfbac6b1ff243807b8b5b8161f0f67a24',
77
'type' => 'library',
88
'install_path' => __DIR__ . '/../../../',
99
'aliases' => array(),
@@ -13,7 +13,7 @@
1313
'__root__' => array(
1414
'pretty_version' => 'dev-master',
1515
'version' => 'dev-master',
16-
'reference' => 'e0b9ff4fa255b4dd4c1e3881e26dff18053e129a',
16+
'reference' => 'b99276fdfbac6b1ff243807b8b5b8161f0f67a24',
1717
'type' => 'library',
1818
'install_path' => __DIR__ . '/../../../',
1919
'aliases' => array(),

lib/private/Share20/DefaultShareProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public function __construct(
5353
private IURLGenerator $urlGenerator,
5454
private ITimeFactory $timeFactory,
5555
private LoggerInterface $logger,
56-
) {}
56+
) {
57+
}
5758

5859
/**
5960
* Return the identifier of this provider.

lib/public/Share/IAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface IAttributes {
2121
* @return IAttributes The modified object
2222
* @since 25.0.0
2323
*/
24-
public function setAttribute($scope, $key, $enabled);
24+
public function setAttribute($scope, $key, $value);
2525

2626
/**
2727
* Returns if attribute is enabled/disabled for given scope id and key.

lib/public/Share/IShareProviderWithNotification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface IShareProviderWithNotification extends IShareProvider {
1717
* Send a mail notification to the recipient of a share
1818
* @param IShare $share
1919
* @return bool True if the mail was sent successfully
20-
* @throws Exception If the mail could not be sent
20+
* @throws \Exception If the mail could not be sent
2121
* @since 30.0.0
2222
*/
2323
public function sendMailNotification(IShare $share): bool;

0 commit comments

Comments
 (0)