@@ -442,6 +442,7 @@ public function deleteShare(string $id): DataResponse {
442442 * @param string $sendPasswordByTalk
443443 * @param string $expireDate
444444 * @param string $label
445+ * @param string $attributes
445446 *
446447 * @return DataResponse
447448 * @throws NotFoundException
@@ -462,7 +463,8 @@ public function createShare(
462463 string $ sendPasswordByTalk = null ,
463464 string $ expireDate = '' ,
464465 string $ note = '' ,
465- string $ label = ''
466+ string $ label = '' ,
467+ string $ attributes = null
466468 ): DataResponse {
467469 $ share = $ this ->shareManager ->newShare ();
468470
@@ -680,7 +682,7 @@ public function createShare(
680682 $ share ->setNote ($ note );
681683 }
682684
683- $ share = $ this ->setShareAttributes ($ share , $ this -> request -> getParam ( ' attributes ' , null ) );
685+ $ share = $ this ->setShareAttributes ($ share , $ attributes );
684686
685687 try {
686688 $ share = $ this ->shareManager ->createShare ($ share );
@@ -1043,6 +1045,7 @@ private function hasPermission(int $permissionsSet, int $permissionsToCheck): bo
10431045 * @param string $note
10441046 * @param string $label
10451047 * @param string $hideDownload
1048+ * @param string $attributes
10461049 * @return DataResponse
10471050 * @throws LockedException
10481051 * @throws NotFoundException
@@ -1059,7 +1062,8 @@ public function updateShare(
10591062 string $ expireDate = null ,
10601063 string $ note = null ,
10611064 string $ label = null ,
1062- string $ hideDownload = null
1065+ string $ hideDownload = null ,
1066+ string $ attributes = null
10631067 ): DataResponse {
10641068 try {
10651069 $ share = $ this ->getShareById ($ id );
@@ -1077,8 +1081,6 @@ public function updateShare(
10771081 throw new OCSForbiddenException ('You are not allowed to edit incoming shares ' );
10781082 }
10791083
1080- $ shareAttributes = $ this ->request ->getParam ('attributes ' , null );
1081-
10821084 if (
10831085 $ permissions === null &&
10841086 $ password === null &&
@@ -1088,7 +1090,7 @@ public function updateShare(
10881090 $ note === null &&
10891091 $ label === null &&
10901092 $ hideDownload === null &&
1091- $ shareAttributes === null
1093+ $ attributes === null
10921094 ) {
10931095 throw new OCSBadRequestException ($ this ->l ->t ('Wrong or no update parameter given ' ));
10941096 }
@@ -1227,7 +1229,7 @@ public function updateShare(
12271229 }
12281230 }
12291231
1230- $ share = $ this ->setShareAttributes ($ share , $ shareAttributes );
1232+ $ share = $ this ->setShareAttributes ($ share , $ attributes );
12311233
12321234 try {
12331235 $ share = $ this ->shareManager ->updateShare ($ share );
@@ -1848,18 +1850,23 @@ private function mergeFormattedShares(array &$shares, array $newShares) {
18481850
18491851 /**
18501852 * @param IShare $share
1851- * @param string[][] |null $formattedShareAttributes
1853+ * @param string|null $attributesString
18521854 * @return IShare modified share
18531855 */
1854- private function setShareAttributes (IShare $ share , $ formattedShareAttributes ) {
1856+ private function setShareAttributes (IShare $ share , ? string $ attributesString ) {
18551857 $ newShareAttributes = $ this ->shareManager ->newShare ()->newAttributes ();
1856- if ($ formattedShareAttributes !== null ) {
1857- foreach ($ formattedShareAttributes as $ formattedAttr ) {
1858- $ newShareAttributes ->setAttribute (
1859- $ formattedAttr ['scope ' ],
1860- $ formattedAttr ['key ' ],
1861- (bool ) \json_decode ($ formattedAttr ['enabled ' ])
1862- );
1858+ if ($ attributesString !== null ) {
1859+ $ formattedShareAttributes = \json_decode ($ attributesString , true );
1860+ if (is_array ($ formattedShareAttributes )) {
1861+ foreach ($ formattedShareAttributes as $ formattedAttr ) {
1862+ $ newShareAttributes ->setAttribute (
1863+ $ formattedAttr ['scope ' ],
1864+ $ formattedAttr ['key ' ],
1865+ is_string ($ formattedAttr ['enabled ' ]) ? (bool ) \json_decode ($ formattedAttr ['enabled ' ]) : $ formattedAttr ['enabled ' ]
1866+ );
1867+ }
1868+ } else {
1869+ throw new OCSBadRequestException ('Invalid share attributes provided: \" ' . $ attributesString . '\" ' );
18631870 }
18641871 }
18651872 $ share ->setAttributes ($ newShareAttributes );
0 commit comments