Commit d9d30da8 authored by allison.browne's avatar allison.browne

Transition zoom quick action code to use new model

parent 7479b1e6
......@@ -281,10 +281,7 @@ module IssuablesHelper
}
data[:hasClosingMergeRequest] = issuable.merge_requests_count(current_user) != 0 if issuable.is_a?(Issue)
zoom_links = Gitlab::ZoomLinkExtractor.new(issuable.description).links
data[:zoomMeetingUrl] = zoom_links.last if zoom_links.any?
data[:zoomMeetingUrl] = issuable&.zoom_meetings.added_to_issue.first&.url
if parent.is_a?(Group)
data[:groupPath] = parent.path
......
......@@ -66,6 +66,7 @@ module Issuable
has_many :label_links, as: :target, dependent: :destroy, inverse_of: :target # rubocop:disable Cop/ActiveRecordDependent
has_many :labels, through: :label_links
has_many :todos, as: :target, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :zoom_meetings
has_one :metrics
......
......@@ -40,6 +40,7 @@ class Issue < ApplicationRecord
has_many :issue_assignees
has_many :assignees, class_name: "User", through: :issue_assignees
has_many :zoom_meetings
validates :project, presence: true
......
......@@ -6,30 +6,31 @@ module Issues
super(issue.project, user)
@issue = issue
@added_meeting = fetch_added_meeting
end
def add_link(link)
if can_add_link? && (link = parse_link(link))
success(_('Zoom meeting added'), append_to_description(link))
success(_('Zoom meeting added'), create_zoom_meeting(link))
else
error(_('Failed to add a Zoom meeting'))
end
end
def can_add_link?
can? && !link_in_issue_description?
end
def remove_link
if can_remove_link?
success(_('Zoom meeting removed'), remove_from_description)
success(_('Zoom meeting removed'), remove_zoom_meeting)
else
error(_('Failed to remove a Zoom meeting'))
end
end
def can_add_link?
can? && !@added_meeting
end
def can_remove_link?
can? && link_in_issue_description?
can? && @added_meeting
end
def parse_link(link)
......@@ -40,40 +41,37 @@ module Issues
attr_reader :issue
def issue_description
issue.description || ''
def fetch_added_meeting
ZoomMeeting.where(issue: @issue).added_to_issue.first
end
def success(message, description)
ServiceResponse
.success(message: message, payload: { description: description })
def create_zoom_meeting(link)
meeting = ZoomMeeting.create(
issue: @issue,
project: @issue.project,
issue_status: :added,
url: link
)
issue.zoom_meetings
end
def error(message)
ServiceResponse.error(message: message)
def remove_zoom_meeting
@added_meeting.issue_status = :removed
@added_meeting.save
issue.zoom_meetings
end
def append_to_description(link)
"#{issue_description}\n\n#{link}"
def success(message, zoom_meetings)
ServiceResponse.success(
message: message,
payload: { zoom_meetings: zoom_meetings }
)
end
def remove_from_description
link = parse_link(issue_description)
return issue_description unless link
issue_description.delete_suffix(link).rstrip
end
def link_in_issue_description?
link = extract_link_from_issue_description
return unless link
Gitlab::ZoomLinkExtractor.new(link).match?
def error(message)
ServiceResponse.error(message: message)
end
def extract_link_from_issue_description
issue_description[/(\S+)\z/, 1]
end
def can?
current_user.can?(:update_issue, project)
......
......@@ -3175,8 +3175,8 @@ ActiveRecord::Schema.define(version: 2019_10_04_133612) do
t.string "tag"
t.text "description"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "description_html"
t.integer "cached_markdown_version"
t.integer "author_id"
......@@ -3739,24 +3739,24 @@ ActiveRecord::Schema.define(version: 2019_10_04_133612) do
t.bigint "author_id", null: false
t.bigint "updated_by_id"
t.bigint "last_edited_by_id"
t.date "start_date"
t.date "due_date"
t.datetime_with_timezone "last_edited_at"
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
t.string "title", limit: 255, null: false
t.text "title_html", null: false
t.text "description"
t.text "description_html"
t.bigint "start_date_sourcing_milestone_id"
t.bigint "due_date_sourcing_milestone_id"
t.bigint "closed_by_id"
t.datetime_with_timezone "last_edited_at"
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
t.datetime_with_timezone "closed_at"
t.date "start_date"
t.date "due_date"
t.integer "state", limit: 2, default: 1, null: false
t.integer "severity", limit: 2, null: false
t.boolean "severity_overridden", default: false
t.integer "confidence", limit: 2, null: false
t.boolean "severity_overridden", default: false
t.boolean "confidence_overridden", default: false
t.string "title", limit: 255, null: false
t.text "title_html", null: false
t.text "description"
t.text "description_html"
t.index ["author_id"], name: "index_vulnerabilities_on_author_id"
t.index ["closed_by_id"], name: "index_vulnerabilities_on_closed_by_id"
t.index ["due_date_sourcing_milestone_id"], name: "index_vulnerabilities_on_due_date_sourcing_milestone_id"
......
......@@ -174,16 +174,17 @@ module Gitlab
params '<Zoom URL>'
types Issue
condition do
zoom_link_service.can_add_link?
@zoom_service = zoom_link_service
@zoom_service.can_add_link?
end
parse_params do |link|
zoom_link_service.parse_link(link)
@zoom_service.parse_link(link)
end
command :zoom do |link|
result = zoom_link_service.add_link(link)
result = @zoom_service.add_link(link)
if result.success?
@updates[:description] = result.payload[:description]
@updates[:zoom_meetings] = result.payload[:zoom_meetings]
end
@execution_message[:zoom] = result.message
......@@ -194,13 +195,14 @@ module Gitlab
execution_message _('Zoom meeting removed')
types Issue
condition do
zoom_link_service.can_remove_link?
@zoom_service = zoom_link_service
@zoom_service.can_remove_link?
end
command :remove_zoom do
result = zoom_link_service.remove_link
result = @zoom_service.remove_link
if result.success?
@updates[:description] = result.payload[:description]
@updates[:zoom_meetings] = result.payload[:zoom_meetings]
end
@execution_message[:remove_zoom] = result.message
......
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