diff --git a/modules/custom/social_gdpr/social_gdpr.install b/modules/custom/social_gdpr/social_gdpr.install index 70024a25fca..9a69616b2c3 100644 --- a/modules/custom/social_gdpr/social_gdpr.install +++ b/modules/custom/social_gdpr/social_gdpr.install @@ -30,6 +30,9 @@ function _social_gdpr_set_permissions() { user_role_grant_permissions($role->id(), $permissions); } } + + // Only for AN. + user_role_grant_permissions('anonymous', ['without consent']); } /** @@ -43,9 +46,7 @@ function _social_gdpr_set_permissions() { */ function _social_gdpr_get_permissions($role) { // Anonymous. - $permissions['anonymous'] = [ - 'without consent', - ]; + $permissions['anonymous'] = []; // Authenticated. $permissions['authenticated'] = array_merge($permissions['anonymous'], []); @@ -67,10 +68,6 @@ function _social_gdpr_get_permissions($role) { 'change inform and consent setting status', ]); - // An authenticated user should give consent when it necessary. - $id = array_search('without consent', $permissions['authenticated']); - unset($permissions['authenticated'][$id]); - if (isset($permissions[$role])) { return $permissions[$role]; } diff --git a/tests/behat/features/bootstrap/SocialDrupalContext.php b/tests/behat/features/bootstrap/SocialDrupalContext.php index ca0c169fb2c..fdad03ff425 100644 --- a/tests/behat/features/bootstrap/SocialDrupalContext.php +++ b/tests/behat/features/bootstrap/SocialDrupalContext.php @@ -306,4 +306,26 @@ public function iFillInCustomFieldsForThis($type) { // needed to fill in custom required fields for the used type. } + /** + * @Given I am logged in as :name with the :permissions permission(s) + */ + public function assertLoggedInWithPermissionsByName($name, $permissions) { + // Create a temporary role with given permissions. + $permissions = array_map('trim', explode(',', $permissions)); + $role = $this->getDriver()->roleCreate($permissions); + + $manager = $this->getUserManager(); + + // Change internal current user. + $manager->setCurrentUser($manager->getUser($name)); + $user = $manager->getUser($name); + + // Assign the temporary role with given permissions. + $this->getDriver()->userAddRole($user, $role); + $this->roles[] = $role; + + // Login. + $this->login($user); + } + } diff --git a/tests/behat/features/capabilities/gdpr/create-data-policy.feature b/tests/behat/features/capabilities/gdpr/create-data-policy.feature index b4dd3574b00..f95dc8f4c40 100644 --- a/tests/behat/features/capabilities/gdpr/create-data-policy.feature +++ b/tests/behat/features/capabilities/gdpr/create-data-policy.feature @@ -16,7 +16,7 @@ Feature: Create data policy and view new policy Given I am logged in as "behatuser" Then I should be on the homepage - Given I am logged in as "behatsitemanager" + Given I am logged in as "behatsitemanager" with the "without consent" permission And I am on "admin/config/people/data-policy" Then I should be on "data-policy/revisions" And I should see the heading "Revisions" in the "Hero block" region diff --git a/tests/behat/features/capabilities/gdpr/data-policy-revisions.feature b/tests/behat/features/capabilities/gdpr/data-policy-revisions.feature index 5e0dfbfe2ea..e6e45641123 100644 --- a/tests/behat/features/capabilities/gdpr/data-policy-revisions.feature +++ b/tests/behat/features/capabilities/gdpr/data-policy-revisions.feature @@ -8,8 +8,12 @@ Feature: Manage data policy revisions Given I enable the module "social_gdpr" - Given I am logged in as a user with the "sitemanager" role and I have the following fields: - | name | behatsitemanager | + Given users: + | name | mail | status | roles | + | behatsitemanager | behatsitemanager@example.com | 1 | sitemanager | + + + Given I am logged in as "behatsitemanager" with the "without consent" permission When I am on "data-policy/revisions/add" Then I should see "Active" in the ".form-item-active-revision:not(.form-disabled) .control-label" element And I should see "Create new revision" in the ".form-item-new-revision.form-disabled .control-label" element @@ -29,7 +33,7 @@ Feature: Manage data policy revisions And I wait for AJAX to finish Then I should see the text "First version of the data policy." - When I am logged in as "behatsitemanager" + When I am logged in as "behatsitemanager" with the "without consent" permission And I am on "data-policy/revisions" And I click the xth "0" element with the css ".revision-2 .dropdown-toggle" # Press "Edit" button in operations drop-down menu @@ -45,7 +49,7 @@ Feature: Manage data policy revisions And I wait for AJAX to finish Then I should see the text "Second version of the data policy." - When I am logged in as "behatsitemanager" + When I am logged in as "behatsitemanager" with the "without consent" permission And I am on "data-policy/revisions/add" And I fill in the "Description" WYSIWYG editor with "Third version of the data policy." And I check the box "Active" diff --git a/tests/behat/features/capabilities/gdpr/inform-block.feature b/tests/behat/features/capabilities/gdpr/inform-block.feature index ea647c6a8df..4f3a3c2ef66 100644 --- a/tests/behat/features/capabilities/gdpr/inform-block.feature +++ b/tests/behat/features/capabilities/gdpr/inform-block.feature @@ -1,5 +1,5 @@ @api @gdpr @inform-block @DS-5586 @stability @stability-4 -Feature: Inform about personal data colleciton +Feature: Inform about personal data collection Benefit: So I can make an informed decision. Role: As a LU Goal/desire: I want to understand what data the site collects about me diff --git a/tests/behat/features/capabilities/gdpr/user-consent.feature b/tests/behat/features/capabilities/gdpr/user-consent.feature index 343511f73c0..abf09de1d88 100644 --- a/tests/behat/features/capabilities/gdpr/user-consent.feature +++ b/tests/behat/features/capabilities/gdpr/user-consent.feature @@ -15,7 +15,7 @@ Feature: Give user consent Given I enable the module "social_gdpr" - Given I am logged in as "behatsitemanager" + Given I am logged in as "behatsitemanager" with the "without consent" permission When I am on "admin/config/people/data-policy/settings" Then I should see the heading "Data policy settings" in the "Admin page title block" region And I should see checked the box "Enforce consent" @@ -40,7 +40,7 @@ Feature: Give user consent When I click "here" Then I should be on "data-policy-agreement" - When I am logged in as "behatsitemanager" + When I am logged in as "behatsitemanager" with the "without consent" permission And I am on "admin/reports/data-policy-agreements" Then I should not see the text "User consents not found." And I should see "Undecided" in the "td.views-field-state" element @@ -52,7 +52,7 @@ Feature: Give user consent And I press "Save" Then I should be on the homepage - When I am logged in as "behatsitemanager" + When I am logged in as "behatsitemanager" with the "without consent" permission And I am on "admin/reports/data-policy-agreements" Then I should see "Not agree" in the "td.views-field-state" element @@ -62,7 +62,7 @@ Feature: Give user consent And I press "Save" Then I should be on the homepage - When I am logged in as "behatsitemanager" + When I am logged in as "behatsitemanager" with the "without consent" permission And I am on "admin/reports/data-policy-agreements" Then I should see "Agree" in the "td.views-field-state" element @@ -71,7 +71,7 @@ Feature: Give user consent And I am logged in as "behatuser3" And I click "here" And I press "Save" - And I am logged in as "behatsitemanager" + And I am logged in as "behatsitemanager" with the "without consent" permission And I am on "admin/reports/data-policy-agreements" Then I should see the link "behatuser1" And I should see the link "behatuser2"