@@ -104,6 +104,12 @@ public function newShare(int $formId, int $shareType, string $shareWith = '', ar
104104 'permissions ' => $ permissions ,
105105 ]);
106106
107+ $ form = $ this ->formsService ->getFormIfAllowed ($ formId );
108+ if ($ this ->formsService ->isFormArchived ($ form )) {
109+ $ this ->logger ->debug ('This form is archived and can not be modified ' );
110+ throw new OCSForbiddenException ('This form is archived and can not be modified ' );
111+ }
112+
107113 // Only accept usable shareTypes
108114 if (array_search ($ shareType , Constants::SHARE_TYPES_USED ) === false ) {
109115 $ this ->logger ->debug ('Invalid shareType ' );
@@ -116,24 +122,6 @@ public function newShare(int $formId, int $shareType, string $shareWith = '', ar
116122 throw new OCSForbiddenException ('Link share not allowed. ' );
117123 }
118124
119- try {
120- $ form = $ this ->formMapper ->findById ($ formId );
121- } catch (IMapperException $ e ) {
122- $ this ->logger ->debug ('Could not find form ' , ['exception ' => $ e ]);
123- throw new OCSNotFoundException ('Could not find form ' );
124- }
125-
126- if ($ this ->formsService ->isFormArchived ($ form )) {
127- $ this ->logger ->debug ('This form is archived and can not be modified ' );
128- throw new OCSForbiddenException ('This form is archived and can not be modified ' );
129- }
130-
131- // Check for permission to share form
132- if ($ form ->getOwnerId () !== $ this ->currentUser ->getUID ()) {
133- $ this ->logger ->debug ('This form is not owned by the current user ' );
134- throw new OCSForbiddenException ('This form is not owned by the current user ' );
135- }
136-
137125 if (!$ this ->validatePermissions ($ permissions , $ shareType )) {
138126 throw new OCSBadRequestException ('Invalid permission given ' );
139127 }
@@ -194,6 +182,8 @@ public function newShare(int $formId, int $shareType, string $shareWith = '', ar
194182 throw new OCSBadRequestException ('Unknown shareType. ' );
195183 }
196184
185+ $ this ->formsService ->obtainFormLock ($ form );
186+
197187 $ share = new Share ();
198188 $ share ->setFormId ($ formId );
199189 $ share ->setShareType ($ shareType );
@@ -240,29 +230,24 @@ public function updateShare(int $formId, int $shareId, array $keyValuePairs): Da
240230 'keyValuePairs ' => $ keyValuePairs
241231 ]);
242232
233+ $ form = $ this ->formsService ->getFormIfAllowed ($ formId );
234+ if ($ this ->formsService ->isFormArchived ($ form )) {
235+ $ this ->logger ->debug ('This form is archived and can not be modified ' );
236+ throw new OCSForbiddenException ('This form is archived and can not be modified ' );
237+ }
238+
243239 try {
244240 $ formShare = $ this ->shareMapper ->findById ($ shareId );
245- $ form = $ this ->formMapper ->findById ($ formId );
246241 } catch (IMapperException $ e ) {
247242 $ this ->logger ->debug ('Could not find share ' , ['exception ' => $ e ]);
248243 throw new OCSNotFoundException ('Could not find share ' );
249244 }
250245
251- if ($ this ->formsService ->isFormArchived ($ form )) {
252- $ this ->logger ->debug ('This form is archived and can not be modified ' );
253- throw new OCSForbiddenException ('This form is archived and can not be modified ' );
254- }
255-
256246 if ($ formId !== $ formShare ->getFormId ()) {
257247 $ this ->logger ->debug ('This share doesn \'t belong to the given Form ' );
258248 throw new OCSBadRequestException ('Share doesn \'t belong to given Form ' );
259249 }
260250
261- if ($ form ->getOwnerId () !== $ this ->currentUser ->getUID ()) {
262- $ this ->logger ->debug ('This form is not owned by the current user ' );
263- throw new OCSForbiddenException ('This form is not owned by the current user ' );
264- }
265-
266251 // Don't allow empty array
267252 if (sizeof ($ keyValuePairs ) === 0 ) {
268253 $ this ->logger ->info ('Empty keyValuePairs, will not update. ' );
@@ -279,6 +264,8 @@ public function updateShare(int $formId, int $shareId, array $keyValuePairs): Da
279264 throw new OCSBadRequestException ('Invalid permission given ' );
280265 }
281266
267+ $ this ->formsService ->obtainFormLock ($ form );
268+
282269 $ formShare ->setPermissions ($ keyValuePairs ['permissions ' ]);
283270 $ formShare = $ this ->shareMapper ->update ($ formShare );
284271
@@ -338,28 +325,25 @@ public function deleteShare(int $formId, int $shareId): DataResponse {
338325 'shareId ' => $ shareId ,
339326 ]);
340327
328+ $ form = $ this ->formsService ->getFormIfAllowed ($ formId );
329+ if ($ this ->formsService ->isFormArchived ($ form )) {
330+ $ this ->logger ->debug ('This form is archived and can not be modified ' );
331+ throw new OCSForbiddenException ('This form is archived and can not be modified ' );
332+ }
333+
341334 try {
342335 $ share = $ this ->shareMapper ->findById ($ shareId );
343- $ form = $ this ->formMapper ->findById ($ formId );
344336 } catch (IMapperException $ e ) {
345337 $ this ->logger ->debug ('Could not find share ' , ['exception ' => $ e ]);
346338 throw new OCSNotFoundException ('Could not find share ' );
347339 }
348340
349- if ($ this ->formsService ->isFormArchived ($ form )) {
350- $ this ->logger ->debug ('This form is archived and can not be modified ' );
351- throw new OCSForbiddenException ('This form is archived and can not be modified ' );
352- }
353-
354341 if ($ formId !== $ share ->getFormId ()) {
355342 $ this ->logger ->debug ('This share doesn \'t belong to the given Form ' );
356343 throw new OCSBadRequestException ('Share doesn \'t belong to given Form ' );
357344 }
358345
359- if ($ form ->getOwnerId () !== $ this ->currentUser ->getUID ()) {
360- $ this ->logger ->debug ('This form is not owned by the current user ' );
361- throw new OCSForbiddenException ('This form is not owned by the current user ' );
362- }
346+ $ this ->formsService ->obtainFormLock ($ form );
363347
364348 $ this ->shareMapper ->delete ($ share );
365349 $ this ->formMapper ->update ($ form );
0 commit comments