From 8460840bd5cebb031f9a380f90868eaf43309d59 Mon Sep 17 00:00:00 2001
From: Liam Morland <lkmorlan@uwaterloo.ca>
Date: Tue, 4 Aug 2020 16:42:09 -0400
Subject: [PATCH] ISTWCMS-2508: Hide access control that should not be
 available

---
 uw_cfg_common.module | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/uw_cfg_common.module b/uw_cfg_common.module
index 24895087..5551661f 100644
--- a/uw_cfg_common.module
+++ b/uw_cfg_common.module
@@ -20,6 +20,42 @@ function uw_cfg_common_form_layout_builder_configure_section_alter(array &$form,
   $form['layout_builder_style']['#default_value'] = $form['layout_builder_style']['#default_value'] ?: 'uw-contained-width';
 }
 
+/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function uw_cfg_common_form_webform_settings_access_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void {
+  // Remove sections for access control that should not be available.
+  $sections_to_remove = [
+    'update_any',
+    'update_own',
+    'delete_own',
+    'administer',
+    'configuration',
+  ];
+  foreach ($sections_to_remove as $section) {
+    unset($form['access'][$section]);
+  }
+
+  // Remove all but user-based access for submissions and test.
+  $permissions_to_edit = [
+    'create',
+    'view_any',
+    'delete_any',
+    'purge_any',
+    'view_own',
+    'test',
+  ];
+  $access_types_to_remove = [
+    'roles',
+    'permissions',
+  ];
+  foreach ($permissions_to_edit as $permission) {
+    foreach ($access_types_to_remove as $type) {
+      unset($form['access'][$permission][$type]);
+    }
+  }
+}
+
 /**
  * Implements hook_form_FORM_ID_alter().
  */
-- 
GitLab