Commit 2f680d64 authored by Robert Speicher's avatar Robert Speicher

Merge branch...

Merge branch '63547-add-system-notes-for-when-a-zoom-call-was-added-removed-from-an-issue' into 'master'

Resolve "Add system notes for when a zoom call was added/removed from an issue"

Closes #63547

See merge request gitlab-org/gitlab-ce!30857
parents bdecc719 6613a577
...@@ -21,6 +21,7 @@ module SystemNoteHelper ...@@ -21,6 +21,7 @@ module SystemNoteHelper
'discussion' => 'comment', 'discussion' => 'comment',
'moved' => 'arrow-right', 'moved' => 'arrow-right',
'outdated' => 'pencil-square', 'outdated' => 'pencil-square',
'pinned_embed' => 'thumbtack',
'duplicate' => 'issue-duplicate', 'duplicate' => 'issue-duplicate',
'locked' => 'lock', 'locked' => 'lock',
'unlocked' => 'lock-open', 'unlocked' => 'lock-open',
......
...@@ -16,7 +16,7 @@ class SystemNoteMetadata < ApplicationRecord ...@@ -16,7 +16,7 @@ class SystemNoteMetadata < ApplicationRecord
commit description merge confidential visible label assignee cross_reference commit description merge confidential visible label assignee cross_reference
title time_tracking branch milestone discussion task moved title time_tracking branch milestone discussion task moved
opened closed merged duplicate locked unlocked opened closed merged duplicate locked unlocked
outdated tag due_date outdated tag due_date pinned_embed
].freeze ].freeze
validates :note, presence: true validates :note, presence: true
......
...@@ -358,6 +358,7 @@ class IssuableBaseService < BaseService ...@@ -358,6 +358,7 @@ class IssuableBaseService < BaseService
assignees: issuable.assignees.to_a assignees: issuable.assignees.to_a
} }
associations[:total_time_spent] = issuable.total_time_spent if issuable.respond_to?(:total_time_spent) associations[:total_time_spent] = issuable.total_time_spent if issuable.respond_to?(:total_time_spent)
associations[:description] = issuable.description
associations associations
end end
......
...@@ -61,6 +61,8 @@ module Issues ...@@ -61,6 +61,8 @@ module Issues
if added_mentions.present? if added_mentions.present?
notification_service.async.new_mentions_in_issue(issue, added_mentions, current_user) notification_service.async.new_mentions_in_issue(issue, added_mentions, current_user)
end end
ZoomNotesService.new(issue, project, current_user, old_description: old_associations[:description]).execute
end end
def handle_task_changes(issuable) def handle_task_changes(issuable)
......
...@@ -597,6 +597,14 @@ module SystemNoteService ...@@ -597,6 +597,14 @@ module SystemNoteService
note_text =~ /\A#{cross_reference_note_prefix}/i note_text =~ /\A#{cross_reference_note_prefix}/i
end end
def zoom_link_added(issue, project, author)
create_note(NoteSummary.new(issue, project, author, _('a Zoom call was added to this issue'), action: 'pinned_embed'))
end
def zoom_link_removed(issue, project, author)
create_note(NoteSummary.new(issue, project, author, _('a Zoom call was removed from this issue'), action: 'pinned_embed'))
end
private private
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
......
# frozen_string_literal: true
class ZoomNotesService
def initialize(issue, project, current_user, old_description: nil)
@issue = issue
@project = project
@current_user = current_user
@old_description = old_description
end
def execute
return if @issue.description == @old_description
if zoom_link_added?
zoom_link_added_notification
elsif zoom_link_removed?
zoom_link_removed_notification
end
end
private
def zoom_link_added?
has_zoom_link?(@issue.description) && !has_zoom_link?(@old_description)
end
def zoom_link_removed?
!has_zoom_link?(@issue.description) && has_zoom_link?(@old_description)
end
def has_zoom_link?(text)
Gitlab::ZoomLinkExtractor.new(text).match?
end
def zoom_link_added_notification
SystemNoteService.zoom_link_added(@issue, @project, @current_user)
end
def zoom_link_removed_notification
SystemNoteService.zoom_link_removed(@issue, @project, @current_user)
end
end
---
title: Add system notes for when a Zoom call was added/removed from an issue
merge_request: 30857
author: Jacopo Beschi @jacopo-beschi
type: added
...@@ -17,5 +17,9 @@ module Gitlab ...@@ -17,5 +17,9 @@ module Gitlab
def links def links
@text.scan(ZOOM_REGEXP) @text.scan(ZOOM_REGEXP)
end end
def match?
ZOOM_REGEXP.match?(@text)
end
end end
end end
...@@ -13030,6 +13030,12 @@ msgstr "" ...@@ -13030,6 +13030,12 @@ msgstr ""
msgid "Your request for access has been queued for review." msgid "Your request for access has been queued for review."
msgstr "" msgstr ""
msgid "a Zoom call was added to this issue"
msgstr ""
msgid "a Zoom call was removed from this issue"
msgstr ""
msgid "a deleted user" msgid "a deleted user"
msgstr "" msgstr ""
......
...@@ -20,5 +20,15 @@ describe Gitlab::ZoomLinkExtractor do ...@@ -20,5 +20,15 @@ describe Gitlab::ZoomLinkExtractor do
it { is_expected.to eq(links) } it { is_expected.to eq(links) }
end end
describe '#match?' do
it 'is true when a zoom link found' do
expect(described_class.new('issue text https://zoom.us/j/123')).to be_match
end
it 'is false when no zoom link found' do
expect(described_class.new('issue text')).not_to be_match
end
end
end end
end end
...@@ -226,6 +226,15 @@ describe Issues::UpdateService, :mailer do ...@@ -226,6 +226,15 @@ describe Issues::UpdateService, :mailer do
end end
end end
it 'creates zoom_link_added system note when a zoom link is added to the description' do
update_issue(description: 'Changed description https://zoom.us/j/5873603787')
note = find_note('a Zoom call was added')
expect(note).not_to be_nil
expect(note.note).to eq('a Zoom call was added to this issue')
end
context 'when issue turns confidential' do context 'when issue turns confidential' do
let(:opts) do let(:opts) do
{ {
......
...@@ -91,7 +91,8 @@ describe MergeRequests::UpdateService, :mailer do ...@@ -91,7 +91,8 @@ describe MergeRequests::UpdateService, :mailer do
labels: [], labels: [],
mentioned_users: [user2], mentioned_users: [user2],
assignees: [user3], assignees: [user3],
total_time_spent: 0 total_time_spent: 0,
description: "FYI #{user2.to_reference}"
} }
) )
end end
......
...@@ -513,6 +513,30 @@ describe SystemNoteService do ...@@ -513,6 +513,30 @@ describe SystemNoteService do
end end
end end
describe '.zoom_link_added' do
subject { described_class.zoom_link_added(issue, project, author) }
it_behaves_like 'a system note' do
let(:action) { 'pinned_embed' }
end
it 'sets the zoom link added note text' do
expect(subject.note).to eq('a Zoom call was added to this issue')
end
end
describe '.zoom_link_removed' do
subject { described_class.zoom_link_removed(issue, project, author) }
it_behaves_like 'a system note' do
let(:action) { 'pinned_embed' }
end
it 'sets the zoom link removed note text' do
expect(subject.note).to eq('a Zoom call was removed from this issue')
end
end
describe '.cross_reference' do describe '.cross_reference' do
subject { described_class.cross_reference(noteable, mentioner, author) } subject { described_class.cross_reference(noteable, mentioner, author) }
......
# frozen_string_literal: true
require 'spec_helper'
describe ZoomNotesService do
describe '#execute' do
let(:issue) { OpenStruct.new(description: description) }
let(:project) { Object.new }
let(:user) { Object.new }
let(:description) { 'an issue description' }
let(:old_description) { nil }
subject { described_class.new(issue, project, user, old_description: old_description) }
shared_examples 'no notifications' do
it "doesn't create notifications" do
expect(SystemNoteService).not_to receive(:zoom_link_added)
expect(SystemNoteService).not_to receive(:zoom_link_removed)
subject.execute
end
end
it_behaves_like 'no notifications'
context 'when the zoom link exists in both description and old_description' do
let(:description) { 'a changed issue description https://zoom.us/j/123' }
let(:old_description) { 'an issue description https://zoom.us/j/123' }
it_behaves_like 'no notifications'
end
context "when the zoom link doesn't exist in both description and old_description" do
let(:description) { 'a changed issue description' }
let(:old_description) { 'an issue description' }
it_behaves_like 'no notifications'
end
context 'when description == old_description' do
let(:old_description) { 'an issue description' }
it_behaves_like 'no notifications'
end
context 'when the description contains a zoom link and old_description is nil' do
let(:description) { 'a changed issue description https://zoom.us/j/123' }
it 'creates a zoom_link_added notification' do
expect(SystemNoteService).to receive(:zoom_link_added).with(issue, project, user)
expect(SystemNoteService).not_to receive(:zoom_link_removed)
subject.execute
end
end
context 'when the zoom link has been added to the description' do
let(:description) { 'a changed issue description https://zoom.us/j/123' }
let(:old_description) { 'an issue description' }
it 'creates a zoom_link_added notification' do
expect(SystemNoteService).to receive(:zoom_link_added).with(issue, project, user)
expect(SystemNoteService).not_to receive(:zoom_link_removed)
subject.execute
end
end
context 'when the zoom link has been removed from the description' do
let(:description) { 'a changed issue description' }
let(:old_description) { 'an issue description https://zoom.us/j/123' }
it 'creates a zoom_link_removed notification' do
expect(SystemNoteService).not_to receive(:zoom_link_added).with(issue, project, user)
expect(SystemNoteService).to receive(:zoom_link_removed)
subject.execute
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment