diff --git a/Gemfile.lock b/Gemfile.lock index eb8cd09c4..5c3b6877b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/basecamp/actiontext-lexical - revision: e6a47a42272d9e9250b47f6ea90caef8e8807c55 + revision: d372bcc8ecc5e725086a68992387b86f80210605 branch: prompts specs: actiontext-lexical (0.1.0) diff --git a/app/models/concerns/mentions.rb b/app/models/concerns/mentions.rb index 79ca110bd..86d017533 100644 --- a/app/models/concerns/mentions.rb +++ b/app/models/concerns/mentions.rb @@ -19,6 +19,10 @@ module Mentions private def scan_mentionees + mentionees_from_plain_text | mentionees_from_rich_text + end + + def mentionees_from_plain_text scan_mentioned_handles.filter_map do |mention| mentionable_users.find { |user| user.mentionable_handles.include?(mention) } end @@ -28,6 +32,14 @@ module Mentions mentionable_content.scan(/(? { Mention.count }, +1 do perform_enqueued_jobs only: Mention::CreateJob do collections(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, @david?" @@ -13,6 +13,27 @@ class MentionsTest < ActiveSupport::TestCase end end + test "create mentions from rich text mentions" do + assert_difference -> { Mention.count }, +1 do + perform_enqueued_jobs only: Mention::CreateJob do + attachment = ActionText::Attachment.from_attachable(users(:david)) + collections(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, #{attachment.to_html}?" + end + end + end + + test "can't mention users that don't have access to the collection" do + collections(:writebook).update! all_access: false + collections(:writebook).accesses.revoke_from(users(:david)) + + assert_no_difference -> { Mention.count }, +1 do + perform_enqueued_jobs only: Mention::CreateJob do + attachment = ActionText::Attachment.from_attachable(users(:david)) + collections(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, #{attachment.to_html}?" + end + end + end + test "mentionees are added as watchers of the card" do perform_enqueued_jobs only: Mention::CreateJob do card = collections(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup @kevin?"