summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskjnldsv <skjnldsv@protonmail.com>2024-07-09 11:09:01 +0200
committerJohn Molakvoæ <skjnldsv@users.noreply.github.com>2024-07-12 20:14:30 +0200
commit30f9ef414ed3a6079354ea2204714216f4533dc9 (patch)
tree98048cf9bde9e00c58e07d62d4138555d4a9ba20
parent5ce4bb368fd1a76293508b3838ec3c003fdfd439 (diff)
downloadnextcloud-server-30f9ef414ed3a6079354ea2204714216f4533dc9.tar.gz
nextcloud-server-30f9ef414ed3a6079354ea2204714216f4533dc9.zip
fix: psalm, cs, autoloader and lint
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php35
-rw-r--r--apps/files_sharing/src/components/NewFileRequestDialog.vue10
-rw-r--r--apps/files_sharing/src/new/newFileRequest.ts2
-rw-r--r--apps/sharebymail/lib/ShareByMailProvider.php23
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/composer/composer/installed.php4
-rw-r--r--lib/private/Share20/DefaultShareProvider.php3
-rw-r--r--lib/public/Share/IAttributes.php2
-rw-r--r--lib/public/Share/IShareProviderWithNotification.php2
10 files changed, 46 insertions, 37 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index f6180ad499a..8a4f8ae025c 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -12,15 +12,16 @@ namespace OCA\Files_Sharing\Controller;
use Exception;
use OC\Files\FileInfo;
use OC\Files\Storage\Wrapper\Wrapper;
+use OCA\Files\Helper;
use OCA\Files_Sharing\Exceptions\SharingRightsException;
use OCA\Files_Sharing\External\Storage;
+use OCA\Files_Sharing\ResponseDefinitions;
use OCA\Files_Sharing\SharedStorage;
-use OCA\Files\Helper;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
+use OCP\AppFramework\Http\Attribute\UserRateLimit;
use OCP\AppFramework\Http\DataResponse;
-use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSForbiddenException;
@@ -523,6 +524,7 @@ class ShareAPIController extends OCSController {
* @param string $note Note for the share
* @param string $label Label for the share (only used in link and email)
* @param string|null $attributes Additional attributes for the share
+ * @param 'false'|'true'|null $sendMail Send a mail to the recipient
*
* @return DataResponse<Http::STATUS_OK, Files_SharingShare, array{}>
* @throws OCSBadRequestException Unknown share type
@@ -545,7 +547,7 @@ class ShareAPIController extends OCSController {
string $note = '',
string $label = '',
?string $attributes = null,
- ?string $mailSend = null
+ ?string $sendMail = null
): DataResponse {
$share = $this->shareManager->newShare();
@@ -636,8 +638,8 @@ class ShareAPIController extends OCSController {
$this->checkInheritedAttributes($share);
// Handle mail send
- if ($mailSend === 'true' || $mailSend === 'false') {
- $share->setMailSend($mailSend === 'true');
+ if ($sendMail === 'true' || $sendMail === 'false') {
+ $share->setMailSend($sendMail === 'true');
}
if ($shareType === IShare::TYPE_USER) {
@@ -1132,7 +1134,7 @@ class ShareAPIController extends OCSController {
* @param string|null $label New label
* @param string|null $hideDownload New condition if the download should be hidden
* @param string|null $attributes New additional attributes
- * @param string|null $mailSend if the share should be send by mail.
+ * @param string|null $sendMail if the share should be send by mail.
* Considering the share already exists, no mail will be send after the share is updated.
* You will have to use the sendMail action to send the mail.
* @param string|null $shareWith New recipient for email shares
@@ -1154,7 +1156,7 @@ class ShareAPIController extends OCSController {
?string $label = null,
?string $hideDownload = null,
?string $attributes = null,
- ?string $mailSend = null,
+ ?string $sendMail = null,
): DataResponse {
try {
$share = $this->getShareById($id);
@@ -1182,7 +1184,7 @@ class ShareAPIController extends OCSController {
$label === null &&
$hideDownload === null &&
$attributes === null &&
- $mailSend === null
+ $sendMail === null
) {
throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
}
@@ -1197,8 +1199,8 @@ class ShareAPIController extends OCSController {
$this->checkInheritedAttributes($share);
// Handle mail send
- if ($mailSend === 'true' || $mailSend === 'false') {
- $share->setMailSend($mailSend === 'true');
+ if ($sendMail === 'true' || $sendMail === 'false') {
+ $share->setMailSend($sendMail === 'true');
}
/**
@@ -2061,13 +2063,14 @@ class ShareAPIController extends OCSController {
}
/**
+ * Send a mail notification again for a share.
+ * The mail_send option must be enabled for the given share.
* @param string $id
- * @param string[] $emails a list of emails to send the notification to
- * @return void
+ * @param string $password optional, the password to check against. Necessary for password protected shares.
*/
#[NoAdminRequired]
- #[BruteForceProtection(action: 'sendShareEmail')]
- public function sendShareEmail(string $id, $password = '') {
+ #[UserRateLimit(limit: 5, period: 120)]
+ public function sendShareEmail(string $id, $password = ''): DataResponse {
try {
$share = $this->getShareById($id);
@@ -2082,7 +2085,7 @@ class ShareAPIController extends OCSController {
// For mail and link shares, the user must be
// the owner of the share, not only the file owner.
if ($share->getShareType() === IShare::TYPE_EMAIL
- || $share->getShareType() === IShare::TYPE_LINK){
+ || $share->getShareType() === IShare::TYPE_LINK) {
if ($share->getSharedBy() !== $this->currentUser) {
throw new OCSForbiddenException('You are not allowed to send mail notifications');
}
@@ -2099,7 +2102,7 @@ class ShareAPIController extends OCSController {
// the password clear, it is just a temporary
// object manipulation. The password will stay
// encrypted in the database.
- if ($share->getPassword() && $share->getPassword() !== $password) {
+ if ($share->getPassword() !== null && $share->getPassword() !== $password) {
if (!$this->shareManager->checkPassword($share, $password)) {
throw new OCSBadRequestException($this->l->t('Wrong password'));
}
diff --git a/apps/files_sharing/src/components/NewFileRequestDialog.vue b/apps/files_sharing/src/components/NewFileRequestDialog.vue
index d6fec8f20e2..2f3eab0b091 100644
--- a/apps/files_sharing/src/components/NewFileRequestDialog.vue
+++ b/apps/files_sharing/src/components/NewFileRequestDialog.vue
@@ -252,7 +252,7 @@ export default defineComponent({
const expireDate = this.deadline ? this.deadline.toISOString().split('T')[0] : undefined
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares')
try {
- const request = await axios.post(shareUrl, {
+ const request = await axios.post<OCSResponse>(shareUrl, {
shareType: Type.SHARE_TYPE_EMAIL,
permissions: Permission.CREATE,
@@ -269,7 +269,7 @@ export default defineComponent({
value: true,
key: 'enabled',
scope: 'fileRequest',
- }])
+ }]),
})
// If not an ocs request
@@ -310,12 +310,12 @@ export default defineComponent({
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares/' + this.share.id)
try {
// Convert link share to email share
- const request = await axios.put(shareUrl, {
+ const request = await axios.put<OCSResponse>(shareUrl, {
attributes: JSON.stringify([{
value: this.emails,
key: 'emails',
scope: 'shareWith',
- }])
+ }]),
})
// If not an ocs request
@@ -341,7 +341,7 @@ export default defineComponent({
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares/' + this.share.id + '/send-email')
try {
// Convert link share to email share
- const request = await axios.post(shareUrl, {
+ const request = await axios.post<OCSResponse>(shareUrl, {
password: this.password || undefined,
})
diff --git a/apps/files_sharing/src/new/newFileRequest.ts b/apps/files_sharing/src/new/newFileRequest.ts
index 07adacd67d3..b7e5b3f2144 100644
--- a/apps/files_sharing/src/new/newFileRequest.ts
+++ b/apps/files_sharing/src/new/newFileRequest.ts
@@ -16,7 +16,7 @@ export const entry = {
iconSvgInline: FileUploadSvg,
order: 30,
enabled(): boolean {
- // determine requirements
+ // TODO: determine requirements
// 1. user can share the root folder
// 2. OR user can create subfolders ?
return true
diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php
index b1a159fb770..b2a7233548f 100644
--- a/apps/sharebymail/lib/ShareByMailProvider.php
+++ b/apps/sharebymail/lib/ShareByMailProvider.php
@@ -81,7 +81,7 @@ class ShareByMailProvider extends DefaultShareProvider implements IShareProvider
// Check if file is not already shared with the given email,
// if we have an email at all.
$alreadyShared = $this->getSharedWith($shareWith, IShare::TYPE_EMAIL, $share->getNode(), 1, 0);
- if ($shareWith !== '' && !empty($alreadyShared)){
+ if ($shareWith !== '' && !empty($alreadyShared)) {
$message = 'Sharing %1$s failed, because this item is already shared with the account %2$s';
$message_t = $this->l->t('Sharing %1$s failed, because this item is already shared with the account %2$s', [$share->getNode()->getName(), $shareWith]);
$this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']);
@@ -238,12 +238,12 @@ class ShareByMailProvider extends DefaultShareProvider implements IShareProvider
$shareId = $share->getId();
$emails = $this->getSharedWithEmails($share);
- $validEmails = array_filter($emails, function ($email) {
+ $validEmails = array_filter($emails, function (string $email) {
return $this->mailer->validateMailAddress($email);
});
if (count($validEmails) === 0) {
- $this->removeShareFromTable($shareId);
+ $this->removeShareFromTable((int)$shareId);
$e = new HintException('Failed to send share by mail. Could not find a valid email address: ' . join(', ', $emails),
$this->l->t('Failed to send share by email. Got an invalid email address'));
$this->logger->error('Failed to send share by mail. Could not find a valid email address ' . join(', ', $emails), [
@@ -256,7 +256,7 @@ class ShareByMailProvider extends DefaultShareProvider implements IShareProvider
$this->sendEmail($share, $validEmails);
// If we have a password set, we send it to the recipient
- if ($share->getPassword()) {
+ if ($share->getPassword() !== null) {
// Sends share password to receiver when it's a permanent one (otherwise she will have to request it via the showShare UI)
// or to owner when the password shall be given during a Talk session
$passwordExpire = $this->config->getSystemValue('sharing.enable_mail_link_password_expiration', false);
@@ -275,14 +275,14 @@ class ShareByMailProvider extends DefaultShareProvider implements IShareProvider
'app' => 'sharebymail',
'exception' => $hintException,
]);
- $this->removeShareFromTable($shareId);
+ $this->removeShareFromTable((int)$shareId);
throw $hintException;
} catch (\Exception $e) {
$this->logger->error('Failed to send share by mail.', [
'app' => 'sharebymail',
'exception' => $e,
]);
- $this->removeShareFromTable($shareId);
+ $this->removeShareFromTable((int)$shareId);
throw new HintException('Failed to send share by mail',
$this->l->t('Failed to send share by email'));
}
@@ -381,13 +381,13 @@ class ShareByMailProvider extends DefaultShareProvider implements IShareProvider
* 1. the password is empty
* 2. the setting to send the password by mail is disabled
* 3. the share is set to send the password by talk
- *
+ *
* @param IShare $share
* @param string $password
* @param array $emails
* @return bool
*/
- protected function sendPassword(IShare $share, string $password, array $emails) {
+ protected function sendPassword(IShare $share, string $password, array $emails): bool {
$filename = $share->getNode()->getName();
$initiator = $share->getSharedBy();
$shareWith = $share->getSharedWith();
@@ -463,10 +463,11 @@ class ShareByMailProvider extends DefaultShareProvider implements IShareProvider
$failedRecipients = $this->mailer->send($message);
if (!empty($failedRecipients)) {
$this->logger->error('Share password mail could not be sent to: ' . implode(', ', $failedRecipients));
- return;
+ return false;
}
$this->createPasswordSendActivity($share, $shareWith, false);
+ return true;
}
protected function sendNote(IShare $share): void {
@@ -1179,8 +1180,10 @@ class ShareByMailProvider extends DefaultShareProvider implements IShareProvider
* Extract the emails from the share
* It can be a single email, from the share_with field
* or a list of emails from the emails attributes field.
+ * @param IShare $share
+ * @return string[]
*/
- protected function getSharedWithEmails(IShare $share) {
+ protected function getSharedWithEmails(IShare $share): array {
$attributes = $share->getAttributes();
if ($attributes === null) {
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index c4a4484f0a6..4ee453f0260 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -682,6 +682,7 @@ return array(
'OCP\\Share\\IShare' => $baseDir . '/lib/public/Share/IShare.php',
'OCP\\Share\\IShareHelper' => $baseDir . '/lib/public/Share/IShareHelper.php',
'OCP\\Share\\IShareProvider' => $baseDir . '/lib/public/Share/IShareProvider.php',
+ 'OCP\\Share\\IShareProviderWithNotification' => $baseDir . '/lib/public/Share/IShareProviderWithNotification.php',
'OCP\\Share_Backend' => $baseDir . '/lib/public/Share_Backend.php',
'OCP\\Share_Backend_Collection' => $baseDir . '/lib/public/Share_Backend_Collection.php',
'OCP\\Share_Backend_File_Dependent' => $baseDir . '/lib/public/Share_Backend_File_Dependent.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 34b31711323..d6cbb1ac886 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -715,6 +715,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Share\\IShare' => __DIR__ . '/../../..' . '/lib/public/Share/IShare.php',
'OCP\\Share\\IShareHelper' => __DIR__ . '/../../..' . '/lib/public/Share/IShareHelper.php',
'OCP\\Share\\IShareProvider' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProvider.php',
+ 'OCP\\Share\\IShareProviderWithNotification' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderWithNotification.php',
'OCP\\Share_Backend' => __DIR__ . '/../../..' . '/lib/public/Share_Backend.php',
'OCP\\Share_Backend_Collection' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_Collection.php',
'OCP\\Share_Backend_File_Dependent' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_File_Dependent.php',
diff --git a/lib/composer/composer/installed.php b/lib/composer/composer/installed.php
index efdbecf06c5..5fe8d8f7f49 100644
--- a/lib/composer/composer/installed.php
+++ b/lib/composer/composer/installed.php
@@ -3,7 +3,7 @@
'name' => '__root__',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
- 'reference' => 'e0b9ff4fa255b4dd4c1e3881e26dff18053e129a',
+ 'reference' => 'b99276fdfbac6b1ff243807b8b5b8161f0f67a24',
'type' => 'library',
'install_path' => __DIR__ . '/../../../',
'aliases' => array(),
@@ -13,7 +13,7 @@
'__root__' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
- 'reference' => 'e0b9ff4fa255b4dd4c1e3881e26dff18053e129a',
+ 'reference' => 'b99276fdfbac6b1ff243807b8b5b8161f0f67a24',
'type' => 'library',
'install_path' => __DIR__ . '/../../../',
'aliases' => array(),
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php
index d1d818222e2..a2a6483f8d5 100644
--- a/lib/private/Share20/DefaultShareProvider.php
+++ b/lib/private/Share20/DefaultShareProvider.php
@@ -53,7 +53,8 @@ class DefaultShareProvider implements IShareProviderWithNotification {
private IURLGenerator $urlGenerator,
private ITimeFactory $timeFactory,
private LoggerInterface $logger,
- ) {}
+ ) {
+ }
/**
* Return the identifier of this provider.
diff --git a/lib/public/Share/IAttributes.php b/lib/public/Share/IAttributes.php
index 7ad2765354f..cb68cc9ebb3 100644
--- a/lib/public/Share/IAttributes.php
+++ b/lib/public/Share/IAttributes.php
@@ -21,7 +21,7 @@ interface IAttributes {
* @return IAttributes The modified object
* @since 25.0.0
*/
- public function setAttribute($scope, $key, $enabled);
+ public function setAttribute($scope, $key, $value);
/**
* Returns if attribute is enabled/disabled for given scope id and key.
diff --git a/lib/public/Share/IShareProviderWithNotification.php b/lib/public/Share/IShareProviderWithNotification.php
index 8a595f46dfd..afd1429c1f0 100644
--- a/lib/public/Share/IShareProviderWithNotification.php
+++ b/lib/public/Share/IShareProviderWithNotification.php
@@ -17,7 +17,7 @@ interface IShareProviderWithNotification extends IShareProvider {
* Send a mail notification to the recipient of a share
* @param IShare $share
* @return bool True if the mail was sent successfully
- * @throws Exception If the mail could not be sent
+ * @throws \Exception If the mail could not be sent
* @since 30.0.0
*/
public function sendMailNotification(IShare $share): bool;