2019-09-14 00:06:25 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Issues
|
|
|
|
class ZoomLinkService < Issues::BaseService
|
|
|
|
def initialize(issue, user)
|
|
|
|
super(issue.project, user)
|
|
|
|
|
|
|
|
@issue = issue
|
2019-10-28 18:06:15 +00:00
|
|
|
@added_meeting = ZoomMeeting.canonical_meeting(@issue)
|
2019-09-14 00:06:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_link(link)
|
|
|
|
if can_add_link? && (link = parse_link(link))
|
2019-10-28 18:06:15 +00:00
|
|
|
begin
|
|
|
|
add_zoom_meeting(link)
|
|
|
|
success(_('Zoom meeting added'))
|
|
|
|
rescue ActiveRecord::RecordNotUnique
|
|
|
|
error(_('Failed to add a Zoom meeting'))
|
|
|
|
end
|
2019-09-14 00:06:25 +00:00
|
|
|
else
|
|
|
|
error(_('Failed to add a Zoom meeting'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_link
|
|
|
|
if can_remove_link?
|
2019-10-28 18:06:15 +00:00
|
|
|
remove_zoom_meeting
|
|
|
|
success(_('Zoom meeting removed'))
|
2019-09-14 00:06:25 +00:00
|
|
|
else
|
|
|
|
error(_('Failed to remove a Zoom meeting'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-28 18:06:15 +00:00
|
|
|
def can_add_link?
|
|
|
|
can_update_issue? && !@added_meeting
|
|
|
|
end
|
|
|
|
|
2019-09-14 00:06:25 +00:00
|
|
|
def can_remove_link?
|
2019-10-28 18:06:15 +00:00
|
|
|
can_update_issue? && !!@added_meeting
|
2019-09-14 00:06:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def parse_link(link)
|
|
|
|
Gitlab::ZoomLinkExtractor.new(link).links.last
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :issue
|
|
|
|
|
2019-10-18 00:07:45 +00:00
|
|
|
def track_meeting_added_event
|
|
|
|
::Gitlab::Tracking.event('IncidentManagement::ZoomIntegration', 'add_zoom_meeting', label: 'Issue ID', value: issue.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def track_meeting_removed_event
|
|
|
|
::Gitlab::Tracking.event('IncidentManagement::ZoomIntegration', 'remove_zoom_meeting', label: 'Issue ID', value: issue.id)
|
|
|
|
end
|
|
|
|
|
2019-10-28 18:06:15 +00:00
|
|
|
def add_zoom_meeting(link)
|
|
|
|
ZoomMeeting.create(
|
|
|
|
issue: @issue,
|
|
|
|
project: @issue.project,
|
|
|
|
issue_status: :added,
|
|
|
|
url: link
|
|
|
|
)
|
|
|
|
track_meeting_added_event
|
|
|
|
SystemNoteService.zoom_link_added(@issue, @project, current_user)
|
2019-09-14 00:06:25 +00:00
|
|
|
end
|
|
|
|
|
2019-10-28 18:06:15 +00:00
|
|
|
def remove_zoom_meeting
|
|
|
|
@added_meeting.update(issue_status: :removed)
|
|
|
|
track_meeting_removed_event
|
|
|
|
SystemNoteService.zoom_link_removed(@issue, @project, current_user)
|
2019-09-14 00:06:25 +00:00
|
|
|
end
|
|
|
|
|
2019-10-28 18:06:15 +00:00
|
|
|
def success(message)
|
|
|
|
ServiceResponse.success(message: message)
|
2019-09-14 00:06:25 +00:00
|
|
|
end
|
|
|
|
|
2019-10-28 18:06:15 +00:00
|
|
|
def error(message)
|
|
|
|
ServiceResponse.error(message: message)
|
2019-09-14 00:06:25 +00:00
|
|
|
end
|
|
|
|
|
2019-10-28 18:06:15 +00:00
|
|
|
def can_update_issue?
|
|
|
|
can?(current_user, :update_issue, project)
|
2019-09-14 00:06:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|