Commit c699cd03 authored by Sean McGivern's avatar Sean McGivern

Merge branch '8199-epic-quick-actions-preview' into 'master'

Fix previewing quick actions for epics

See merge request gitlab-org/gitlab!19042
parents eafd98ec 7be8f1ce
......@@ -5,7 +5,7 @@ module PreviewMarkdown
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def preview_markdown
result = PreviewMarkdownService.new(@project, current_user, params).execute
result = PreviewMarkdownService.new(@project, current_user, markdown_service_params).execute
markdown_params =
case controller_name
......@@ -26,6 +26,8 @@ module PreviewMarkdown
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
private
def projects_filter_params
{
issuable_state_filter_enabled: true,
......@@ -33,10 +35,12 @@ module PreviewMarkdown
}
end
private
# Override this method to customise the markdown for your controller
def preview_markdown_params
{}
end
def markdown_service_params
params
end
end
......@@ -6,6 +6,7 @@ class GroupsController < Groups::ApplicationController
include ParamsBackwardCompatibility
include PreviewMarkdown
include RecordUserLastActivity
extend ::Gitlab::Utils::Override
respond_to :html
......@@ -233,6 +234,11 @@ class GroupsController < Groups::ApplicationController
@group.self_and_descendants.public_or_visible_to_user(current_user)
end
end
override :markdown_service_params
def markdown_service_params
params.merge(group: group)
end
end
GroupsController.prepend_if_ee('EE::GroupsController')
......@@ -66,7 +66,7 @@ module GitlabRoutingHelper
end
def preview_markdown_path(parent, *args)
return group_preview_markdown_path(parent) if parent.is_a?(Group)
return group_preview_markdown_path(parent, *args) if parent.is_a?(Group)
if @snippet.is_a?(PersonalSnippet)
preview_markdown_snippets_path
......
......@@ -16,8 +16,12 @@ class PreviewMarkdownService < BaseService
private
def quick_action_types
%w(Issue MergeRequest Commit)
end
def explain_quick_actions(text)
return text, [] unless %w(Issue MergeRequest Commit).include?(target_type)
return text, [] unless quick_action_types.include?(target_type)
quick_actions_service = QuickActions::InterpretService.new(project, current_user)
quick_actions_service.explain(text, find_commands_target)
......@@ -51,7 +55,7 @@ class PreviewMarkdownService < BaseService
def find_commands_target
QuickActions::TargetService
.new(project, current_user)
.new(project, current_user, group: params[:group])
.execute(target_type, target_id)
end
......@@ -63,3 +67,5 @@ class PreviewMarkdownService < BaseService
params[:target_id]
end
end
PreviewMarkdownService.prepend_if_ee('EE::PreviewMarkdownService')
......@@ -32,3 +32,5 @@ module QuickActions
end
end
end
QuickActions::TargetService.prepend_if_ee('EE::QuickActions::TargetService')
---
title: Fix previewing quick actions for epics
merge_request: 19042
author:
type: fixed
......@@ -40,6 +40,6 @@ class EpicEntity < IssuableEntity
end
expose :preview_note_path do |epic|
preview_markdown_path(epic.group, target_type: 'Epic', target_id: epic.id)
preview_markdown_path(epic.group, target_type: 'Epic', target_id: epic.iid)
end
end
# frozen_string_literal: true
module EE
module PreviewMarkdownService
def quick_action_types
super.push('Epic')
end
end
end
# frozen_string_literal: true
module EE
module QuickActions
module TargetService
def execute(type, type_id)
return epic(type_id) if type.casecmp('epic').zero?
super
end
private
# rubocop: disable CodeReuse/ActiveRecord
def epic(type_id)
group = params[:group]
EpicsFinder.new(current_user, group_id: group.id).find_by(iid: type_id) || group.epics.build
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe 'Epic quick actions', :js do
include Spec::Support::Helpers::Features::NotesHelpers
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:epic) { create(:epic, group: group) }
before do
stub_licensed_features(epics: true)
group.add_developer(user)
sign_in(user)
visit group_epic_path(group, epic)
end
context 'note with a quick action' do
it 'previews a note with quick action' do
preview_note('/title New Title')
expect(page).to have_content('Changes the title to "New Title".')
end
it 'executes the quick action' do
add_note('/title New Title')
expect(page).to have_content('Changed the title to "New Title".')
expect(epic.reload.title).to eq('New Title')
visit group_epic_path(group, epic)
expect(page).to have_content('New Title')
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe PreviewMarkdownService do
context 'preview epic text with quick action' do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:epic) { create(:epic, group: group) }
let(:params) do
{
text: '/title new title',
target_type: 'Epic',
target_id: epic.iid,
group: epic.group
}
end
let(:service) { described_class.new(nil, user, params) }
before do
stub_licensed_features(epics: true)
group.add_developer(user)
end
it 'explains quick actions effect' do
result = service.execute
expect(result[:commands]).to eq 'Changes the title to "new title".'
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe QuickActions::TargetService do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
let(:user) { create(:user) }
let(:service) { described_class.new(project, user, group: group) }
before do
group.add_maintainer(user)
stub_licensed_features(epics: true)
end
describe '#execute' do
context 'for epic' do
let(:type) { 'Epic' }
it 'finds target with valid id' do
epic = create(:epic, group: group)
target = service.execute(type, epic.iid)
expect(target).to eq(epic)
end
it 'builds a new target if id from a different group passed' do
epic = create(:epic)
target = service.execute(type, epic.iid)
expect(target).to be_new_record
expect(target.group).to eq(group)
end
end
end
end
......@@ -75,6 +75,12 @@ describe GitlabRoutingHelper do
expect(preview_markdown_path(group)).to eq("/groups/#{group.path}/preview_markdown")
end
it 'returns group preview markdown path for a group parent with args' do
group = create(:group)
expect(preview_markdown_path(group, { type_id: 5 })).to eq("/groups/#{group.path}/preview_markdown?type_id=5")
end
it 'returns project preview markdown path for a project parent' do
expect(preview_markdown_path(project)).to eq("/#{project.full_path}/preview_markdown")
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