@@ -241,8 +241,9 @@ private function getAllowedUsers(WebformInterface $webform): array {
241241 /**
242242 * Check if a user has access to a webform.
243243 *
244- * A user has access to a webform if the list of allowed users is empty or the
245- * user is included in the list.
244+ * A user has access to a webform if the user is
245+ * contained in the list of allowed users or the
246+ * user has been granted the 'view_any' webform permission.
246247 *
247248 * @param \Drupal\webform\WebformInterface $webform
248249 * The webform.
@@ -260,7 +261,7 @@ public function hasWebformAccess(WebformInterface $webform, $user): bool {
260261
261262 $ allowedUsers = $ this ->getAllowedUsers ($ webform );
262263
263- return isset ($ allowedUsers [$ userId ]);
264+ return isset ($ allowedUsers [$ userId ]) || $ webform -> access ( ' view_any ' ) ;
264265 }
265266
266267 /**
@@ -275,40 +276,6 @@ private function loadUsers(array $spec): array {
275276 ->loadMultiple (array_column ($ spec , 'target_id ' ));
276277 }
277278
278- /**
279- * Implements hook_file_download().
280- *
281- * Note: This is only used to deny access to a file that is attached to a
282- * webform (submission) that the user does not have permission to access.
283- * Permission to access private files are handled elsewhere.
284- *
285- * @phpstan-return int|array<string, string>|null
286- */
287- public function fileDownload (string $ uri ) {
288- $ request = $ this ->requestStack ->getCurrentRequest ();
289-
290- // We are only concerned with users authenticated via Key Auth (cf.
291- // os2forms_rest_api.services.yml).
292- if ($ user = $ this ->keyAuth ->authenticate ($ request )) {
293- // Find webform id from uri, see example uri.
294- // @Example: private://webform/some_webform_id/119/some_file_name.png
295- $ pattern = '/private:\/\/webform\/(?<webform>[^\/]*)/ ' ;
296- if (preg_match ($ pattern , $ uri , $ matches )) {
297- $ webform = $ this ->getWebform ($ matches ['webform ' ]);
298- if (NULL !== $ webform ) {
299- // Deny access to file if user does not have access to the webform.
300- if (!$ this ->hasWebformAccess ($ webform , $ user )) {
301- return -1 ;
302- }
303- }
304- }
305- }
306-
307- // We cannot deny access to the file. Let others handle the access control
308- // for the (private) file.
309- return NULL ;
310- }
311-
312279 /**
313280 * Return current user.
314281 *
0 commit comments