From 7203482899fed428265d6a29223e55aa3dd81f48 Mon Sep 17 00:00:00 2001
From: Frederik Wouters <woutefr@cronos.be>
Date: Mon, 13 Jan 2025 10:23:40 +0100
Subject: [PATCH] re-add permission for this module

---
 .../ai_content_suggestions.module                    | 12 ++++++++----
 .../ai_content_suggestions.permissions.yml           |  3 +++
 2 files changed, 11 insertions(+), 4 deletions(-)
 create mode 100644 modules/ai_content_suggestions/ai_content_suggestions.permissions.yml

diff --git a/modules/ai_content_suggestions/ai_content_suggestions.module b/modules/ai_content_suggestions/ai_content_suggestions.module
index 6e4fcbdef..9afd1828a 100644
--- a/modules/ai_content_suggestions/ai_content_suggestions.module
+++ b/modules/ai_content_suggestions/ai_content_suggestions.module
@@ -30,8 +30,12 @@ function ai_content_suggestions_form_taxonomy_term_tags_form_alter(&$form, FormS
  *   The form state.
  */
 function ai_content_suggestions_alter_form(array &$form, FormStateInterface $form_state): void {
-  \Drupal::service('ai_content_suggestions.form_alter')->alter($form, $form_state);
-  $form['#cache']['contexts'][] = 'user.permissions';
-  $form['#cache']['contexts'][] = 'ai_content_suggestions_plugins';
-  $form['#cache']['contexts'][] = 'ai_providers';
+  $user = \Drupal::currentUser();
+  $hasPermission = $user->hasPermission('access ai content suggestion tools');
+  if ($hasPermission) {
+    \Drupal::service('ai_content_suggestions.form_alter')->alter($form, $form_state);
+    $form['#cache']['contexts'][] = 'user.permissions';
+    $form['#cache']['contexts'][] = 'ai_content_suggestions_plugins';
+    $form['#cache']['contexts'][] = 'ai_providers';
+  }
 }
diff --git a/modules/ai_content_suggestions/ai_content_suggestions.permissions.yml b/modules/ai_content_suggestions/ai_content_suggestions.permissions.yml
new file mode 100644
index 000000000..d9e84a068
--- /dev/null
+++ b/modules/ai_content_suggestions/ai_content_suggestions.permissions.yml
@@ -0,0 +1,3 @@
+access ai content suggestion tools:
+  title: 'Access AI Content suggestion tools'
+  description: 'Permit access to content tools provided by the AI Content suggestions module.'
-- 
GitLab