From dcf180a651c0f1a18e1fc55bc0ac11c650f619ad Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 29 Jan 2021 12:53:50 +0000 Subject: [PATCH] Fix Plausible loading for authenticated users Return early within the Plausible if the user is authenticated so that it doesn't pick up when I'm adding or editing content on the site. Though the role is configured in the Plausible module's admin form, the conditions in the code don't exclude it. I'll look into this further and submit a patch upstream along with some tests. References #350 --- composer.json | 3 +++ composer.lock | 10 +++++----- .../plausible/return-if-authenticated.patch | 20 +++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 tools/patches/plausible/return-if-authenticated.patch diff --git a/composer.json b/composer.json index b272852..7673484 100644 --- a/composer.json +++ b/composer.json @@ -114,6 +114,9 @@ ] }, "patches": { + "drupal/plausible": { + "Return early if user is not anonymous": "tools/patches/plausible/return-if-authenticated.patch" + } } } } diff --git a/composer.lock b/composer.lock index 2afdc38..4582f4b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fe496bbcb4eef8b520c250b2c4d70d83", + "content-hash": "6aa7c4e54ecdea98cfca107f6be3cc9e", "packages": [ { "name": "asm89/stack-cors", @@ -8229,12 +8229,12 @@ "version": "1.9.1", "source": { "type": "git", - "url": "https://github.com/webmozart/assert.git", + "url": "https://github.com/webmozarts/assert.git", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", "shasum": "" }, @@ -8272,8 +8272,8 @@ "validate" ], "support": { - "issues": "https://github.com/webmozart/assert/issues", - "source": "https://github.com/webmozart/assert/tree/master" + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.9.1" }, "time": "2020-07-08T17:02:28+00:00" }, diff --git a/tools/patches/plausible/return-if-authenticated.patch b/tools/patches/plausible/return-if-authenticated.patch new file mode 100644 index 0000000..b547323 --- /dev/null +++ b/tools/patches/plausible/return-if-authenticated.patch @@ -0,0 +1,20 @@ +diff --git a/plausible.module b/plausible.module +index ce5a826..aa78dc5 100644 +--- a/plausible.module ++++ b/plausible.module +@@ -16,9 +16,14 @@ use Drupal\plausible\Component\Render\PlausibleJavaScriptSnippet; + function plausible_page_attachments(array &$attachments) { + $account = \Drupal::currentUser(); + +- if (! (_plausible_visibility_pages() && _plausible_visibility_roles($account))) { ++ if (!_plausible_visibility_pages()) { + return; + } ++ ++ if ($account->isAuthenticated()) { ++ return; ++ } ++ + $config = \Drupal::config('plausible.settings'); + $attachments['#attached']['html_head'][] = [ + [