Skip to content

Commit

Permalink
Merge pull request #7536 from fjordllc/bugfix/exclude-@mentor-in-the-…
Browse files Browse the repository at this point in the history
…code-from-notification

コード内のメンションは通知対象外にするように実装
  • Loading branch information
komagata authored Apr 24, 2024
2 parents 212bb69 + dd9f2ec commit 4dd4fca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/concerns/mentioner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ def find_users_from_login_names(names)

def find_users_from_mentions(mentions)
names = extract_login_names_from_mentions(mentions)
names.concat(User.mentor.map(&:login_name)) if mentions.include?('@mentor')
names.concat(User.mentor.map(&:login_name)) if names.include?('mentor')
# find_users_from_login_names 内のwhereで重複は削除する
find_users_from_login_names(names)
end

def extract_login_names_from_mentions(mentions)
mentions.map { |s| s.gsub(/@/, '') }
code_block_regexp = /```.*?```|`.*?`/m
mentionable_without_code = mentionable.gsub(code_block_regexp, '')
mentions.map { |s| s.gsub(/@/, '') if mentionable_without_code.include?(s) }
end

def target_of_comment(commentable_class, commentable)
Expand Down
29 changes: 29 additions & 0 deletions test/system/notification/reports_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,33 @@ def assert_notify_only_at_first_published_of_report(
assert_text "#{student}さんが2回連続でsadアイコンの日報を提出しました。"
end
end

test 'mentioning in code blocks and inline code does not work' do
visit_with_auth '/notifications', 'komagata'
click_link '全て既読にする'

visit_with_auth '/reports', 'kimura'
click_link '日報作成'

mention_in_code = '```@mentor```, ` @mentor `'
within('form[name=report]') do
fill_in('report[title]', with: 'コードブロック内でメンション')
fill_in('report[description]', with: mention_in_code)
end

within('.learning-time__started-at') do
select '07'
select '30'
end
within('.learning-time__finished-at') do
select '08'
select '30'
end

click_button '提出'
logout

visit_with_auth '/notifications?status=unread', 'komagata'
assert_text '未読の通知はありません'
end
end

0 comments on commit 4dd4fca

Please sign in to comment.