1212use Exception ;
1313use OC \Files \FileInfo ;
1414use OC \Files \Storage \Wrapper \Wrapper ;
15+ use OCA \Files \Helper ;
1516use OCA \Files_Sharing \Exceptions \SharingRightsException ;
1617use OCA \Files_Sharing \External \Storage ;
18+ use OCA \Files_Sharing \ResponseDefinitions ;
1719use OCA \Files_Sharing \SharedStorage ;
18- use OCA \Files \Helper ;
1920use OCP \App \IAppManager ;
2021use OCP \AppFramework \Http \Attribute \BruteForceProtection ;
2122use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
23+ use OCP \AppFramework \Http \Attribute \UserRateLimit ;
2224use OCP \AppFramework \Http \DataResponse ;
23- use OCP \AppFramework \Http \JSONResponse ;
2425use OCP \AppFramework \OCS \OCSBadRequestException ;
2526use OCP \AppFramework \OCS \OCSException ;
2627use 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 }
0 commit comments