diff --git a/app/controllers/discourse_ai/ai_helper/assistant_controller.rb b/app/controllers/discourse_ai/ai_helper/assistant_controller.rb index 52b61115..a17df448 100644 --- a/app/controllers/discourse_ai/ai_helper/assistant_controller.rb +++ b/app/controllers/discourse_ai/ai_helper/assistant_controller.rb @@ -72,7 +72,11 @@ module DiscourseAi RateLimiter.new(current_user, "ai_assistant", 6, 3.minutes).performed! - render json: DiscourseAi::AiHelper::SemanticCategorizer.new(params[:text]).categories, + render json: + DiscourseAi::AiHelper::SemanticCategorizer.new( + params[:text], + current_user, + ).categories, status: 200 end @@ -81,7 +85,9 @@ module DiscourseAi RateLimiter.new(current_user, "ai_assistant", 6, 3.minutes).performed! - render json: DiscourseAi::AiHelper::SemanticCategorizer.new(params[:text]).tags, status: 200 + render json: + DiscourseAi::AiHelper::SemanticCategorizer.new(params[:text], current_user).tags, + status: 200 end private diff --git a/lib/modules/ai_helper/semantic_categorizer.rb b/lib/modules/ai_helper/semantic_categorizer.rb index 34528ab9..5acb3f5b 100644 --- a/lib/modules/ai_helper/semantic_categorizer.rb +++ b/lib/modules/ai_helper/semantic_categorizer.rb @@ -2,7 +2,8 @@ module DiscourseAi module AiHelper class SemanticCategorizer - def initialize(text) + def initialize(text, user) + @user = user @text = text end @@ -22,6 +23,7 @@ module DiscourseAi ::Topic .joins(:category) .where(id: candidate_ids) + .where("categories.id IN (?)", Category.topic_create_allowed(@user.guardian).pluck(:id)) .order("array_position(ARRAY#{candidate_ids}, topics.id)") .pluck("categories.slug") .map @@ -52,6 +54,7 @@ module DiscourseAi ::Topic .joins(:topic_tags, :tags) .where(id: candidate_ids) + .where("tags.id IN (?)", DiscourseTagging.visible_tags(@user.guardian).pluck(:id)) .group("topics.id") .order("array_position(ARRAY#{candidate_ids}, topics.id)") .pluck("array_agg(tags.name)")