@@ -331,31 +331,39 @@ public function canEditForm(Form $form): bool {
331331 * @param Form $form The form for which the results visibility is being checked.
332332 * @return bool True if the user can see the results, false otherwise.
333333 */
334- /**
335- * Can the current user see results of a form
336- *
337- * @param Form $form
338- * @return boolean
339- */
340334 public function canSeeResults (Form $ form ): bool {
341335 return $ this ->submissionMapper ->countSubmissions ($ form ->getId (), $ this ->currentUser ->getUID ()) > 0
342336 || in_array (Constants::PERMISSION_RESULTS , $ this ->getPermissions ($ form ));
343337 }
344338
345339 /**
346- * Can the current user delete results of a form
340+ * Determines if the current user has permission to delete the results of a given form.
347341 *
348- * @param Form $form
349- * @return boolean
342+ * A user can delete the results of a form if the form is not archived and one of the following conditions is met:
343+ * - The user has the "results_delete" permission.
344+ * - The user has not submitted any responses, and the form allows editing.
345+ * - The form is not archived.
346+ *
347+ * @param Form $form The form for which the results deletion permission is being checked.
348+ * @return bool True if the user can delete the results, false otherwise.
350349 */
351350 public function canDeleteResults (Form $ form ): bool {
352- // Check permissions
353- if (! in_array (Constants:: PERMISSION_RESULTS_DELETE , $ this ->getPermissions ($ form) )) {
351+ // Do not allow deleting results on archived forms
352+ if ($ this ->isFormArchived ($ form )) {
354353 return false ;
355354 }
355+
356+ // Allow deleting results if the current user has the "results_delete" permission
357+ if (in_array (Constants::PERMISSION_RESULTS_DELETE , $ this ->getPermissions ($ form ))) {
358+ return true ;
359+ }
356360
357- // Do not allow deleting results on archived forms
358- return !$ this ->isFormArchived ($ form );
361+ // Allow deleting results if the current user has already submitted
362+ if ($ form ->getAllowEdit () && $ this ->submissionMapper ->countSubmissions ($ form ->getId (), $ this ->currentUser ->getUID ()) > 0 ) {
363+ return true ;
364+ }
365+
366+ return false ;
359367 }
360368
361369 /**
0 commit comments