From 86cc0c5de26e26d297c53a73bc70ae4f80ecd8e7 Mon Sep 17 00:00:00 2001 From: Herb Date: Mon, 21 Oct 2019 18:23:39 -0400 Subject: [PATCH] Backdrop support for adding roles and perms --- .../civicrm_webtest/civicrm_webtest.install | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/drupal/modules/civicrm_webtest/civicrm_webtest.install b/tools/drupal/modules/civicrm_webtest/civicrm_webtest.install index 9e4ae1695e..e77c9f2aca 100644 --- a/tools/drupal/modules/civicrm_webtest/civicrm_webtest.install +++ b/tools/drupal/modules/civicrm_webtest/civicrm_webtest.install @@ -4,7 +4,14 @@ * Implementation of hook_enable */ function civicrm_webtest_enable() { - user_role_grant_permissions(1, [ + $anonymous = 1; + + // If Backdrop + if (function_exists('config_get')) { + $anonymous = 'Anonymous'; + } + + user_role_grant_permissions($anonymous, [ 'access CiviMail subscribe/unsubscribe pages', 'access all custom data', 'access uploaded files', @@ -15,6 +22,7 @@ function civicrm_webtest_enable() { ]); $roles = user_roles(); + if (!in_array('civicrm_webtest_user', $roles)) { $role = new stdClass(); $role->name = 'civicrm_webtest_user'; @@ -25,6 +33,17 @@ function civicrm_webtest_enable() { $rid = array_search('civicrm_webtest_user', $roles); } + // If Backdrop + if (function_exists('config_get')) { + $rid = 'civicrm_webtest_user'; + if (!isset($roles[$rid])) { + $role = new stdClass(); + $role->name = $rid; + $role->label = 'CiviCRM Webtest User'; + user_role_save($role); + } + } + user_role_grant_permissions($rid, [ // FIXME: whoa, why do we bother with users if both need admin rights? 'access AJAX API', -- 2.25.1