Commit 48c02068 authored by Patrick Bajao's avatar Patrick Bajao

Move review related controllers/workers outside EE

Another step to moving Review feature to Core.

This focuses on moving DraftsController and related workers,
serializers, policies, and controller methods.

This also includes moving `submit_review` quick action outside EE.
parent 8c527001
...@@ -162,8 +162,13 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic ...@@ -162,8 +162,13 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
def renderable_notes def renderable_notes
define_diff_comment_vars unless @notes define_diff_comment_vars unless @notes
@notes draft_notes =
if current_user
merge_request.draft_notes.authored_by(current_user)
else
[]
end
@notes.concat(draft_notes)
end end
end end
Projects::MergeRequests::DiffsController.prepend_if_ee('EE::Projects::MergeRequests::DiffsController')
...@@ -19,14 +19,11 @@ class NewNoteWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -19,14 +19,11 @@ class NewNoteWorker # rubocop:disable Scalability/IdempotentWorker
Gitlab::AppLogger.error("NewNoteWorker: couldn't find note with ID=#{note_id}, skipping job") Gitlab::AppLogger.error("NewNoteWorker: couldn't find note with ID=#{note_id}, skipping job")
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
# EE-only method
def skip_notification?(note) def skip_notification?(note)
false note.review.present?
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
NewNoteWorker.prepend_if_ee('EE::NewNoteWorker')
---
title: Move review related controllers/workers outside EE
merge_request: 32663
author:
type: changed
...@@ -55,6 +55,15 @@ resources :merge_requests, concerns: :awardable, except: [:new, :create, :show], ...@@ -55,6 +55,15 @@ resources :merge_requests, concerns: :awardable, except: [:new, :create, :show],
delete :resolve, action: :unresolve delete :resolve, action: :unresolve
end end
end end
scope module: :merge_requests do
resources :drafts, only: [:index, :update, :create, :destroy] do
collection do
post :publish
delete :discard
end
end
end
end end
scope path: 'merge_requests', controller: 'merge_requests/creations' do scope path: 'merge_requests', controller: 'merge_requests/creations' do
......
# frozen_string_literal: true
module EE
module Projects
module MergeRequests
module DiffsController
extend ActiveSupport::Concern
def renderable_notes
draft_notes =
if current_user
merge_request.draft_notes.authored_by(current_user)
else
[]
end
super.concat(draft_notes)
end
end
end
end
end
# frozen_string_literal: true
module EE
module NewNoteWorker
extend ActiveSupport::Concern
private
# If a note belongs to a review
# We do not want to send a standalone
# notification
def skip_notification?(note)
note.review.present?
end
end
end
...@@ -21,13 +21,4 @@ resources :merge_requests, only: [], constraints: { id: /\d+/ } do ...@@ -21,13 +21,4 @@ resources :merge_requests, only: [], constraints: { id: /\d+/ } do
resources :approvers, only: :destroy resources :approvers, only: :destroy
delete 'approvers', to: 'approvers#destroy_via_user_id', as: :approver_via_user_id delete 'approvers', to: 'approvers#destroy_via_user_id', as: :approver_via_user_id
resources :approver_groups, only: :destroy resources :approver_groups, only: :destroy
scope module: :merge_requests do
resources :drafts, only: [:index, :update, :create, :destroy] do
collection do
post :publish
delete :discard
end
end
end
end end
...@@ -20,23 +20,6 @@ module EE ...@@ -20,23 +20,6 @@ module EE
@execution_message[:approve] = _('Approved the current merge request.') @execution_message[:approve] = _('Approved the current merge request.')
end end
end end
desc _('Submit a review')
explanation _('Submit the current review.')
types MergeRequest
condition do
quick_action_target.persisted?
end
command :submit_review do
next if params[:review_id]
result = DraftNotes::PublishService.new(quick_action_target, current_user).execute
@execution_message[:submit_review] = if result[:status] == :success
_('Submitted the current review.')
else
result[:message]
end
end
end end
end end
end end
......
...@@ -10,10 +10,6 @@ FactoryBot.modify do ...@@ -10,10 +10,6 @@ FactoryBot.modify do
trait :on_vulnerability do trait :on_vulnerability do
noteable { association(:vulnerability, project: project) } noteable { association(:vulnerability, project: project) }
end end
trait :with_review do
review
end
end end
end end
......
...@@ -765,30 +765,6 @@ describe QuickActions::InterpretService do ...@@ -765,30 +765,6 @@ describe QuickActions::InterpretService do
end end
end end
context 'submit_review command' do
using RSpec::Parameterized::TableSyntax
where(:note) do
[
'I like it',
'/submit_review'
]
end
with_them do
let(:merge_request) { create(:merge_request, source_project: project) }
let(:content) { '/submit_review' }
let!(:draft_note) { create(:draft_note, note: note, merge_request: merge_request, author: current_user) }
it 'submits the users current review' do
_, _, message = service.execute(content, merge_request)
expect { draft_note.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect(message).to eq('Submitted the current review.')
end
end
end
shared_examples 'weight command' do shared_examples 'weight command' do
it 'populates weight specified by the /weight command' do it 'populates weight specified by the /weight command' do
_, updates = service.execute(content, issuable) _, updates = service.execute(content, issuable)
......
# frozen_string_literal: true
require 'spec_helper'
describe NewNoteWorker do
context 'when skip_notification' do
it 'does not create a new note notification' do
note = create(:note, :with_review)
expect_any_instance_of(NotificationService).not_to receive(:new_note)
subject.perform(note.id)
end
end
end
...@@ -104,6 +104,23 @@ module Gitlab ...@@ -104,6 +104,23 @@ module Gitlab
command :target_branch do |branch_name| command :target_branch do |branch_name|
@updates[:target_branch] = branch_name if project.repository.branch_exists?(branch_name) @updates[:target_branch] = branch_name if project.repository.branch_exists?(branch_name)
end end
desc _('Submit a review')
explanation _('Submit the current review.')
types MergeRequest
condition do
quick_action_target.persisted?
end
command :submit_review do
next if params[:review_id]
result = DraftNotes::PublishService.new(quick_action_target, current_user).execute
@execution_message[:submit_review] = if result[:status] == :success
_('Submitted the current review.')
else
result[:message]
end
end
end end
def merge_orchestration_service def merge_orchestration_service
......
...@@ -300,7 +300,7 @@ describe Projects::MergeRequests::DraftsController do ...@@ -300,7 +300,7 @@ describe Projects::MergeRequests::DraftsController do
it 'publishes a draft note with quick actions and applies them' do it 'publishes a draft note with quick actions and applies them' do
project.add_developer(user2) project.add_developer(user2)
create(:draft_note, merge_request: merge_request, author: user, create(:draft_note, merge_request: merge_request, author: user,
note: "/assign #{user.to_reference} #{user2.to_reference}") note: "/assign #{user2.to_reference}")
expect(merge_request.assignees).to be_empty expect(merge_request.assignees).to be_empty
...@@ -308,7 +308,7 @@ describe Projects::MergeRequests::DraftsController do ...@@ -308,7 +308,7 @@ describe Projects::MergeRequests::DraftsController do
.and change { DraftNote.count }.by(-1) .and change { DraftNote.count }.by(-1)
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(merge_request.reload.assignee_ids).to match_array([user.id, user2.id]) expect(merge_request.reload.assignee_ids).to match_array([user2.id])
expect(Note.last.system?).to be true expect(Note.last.system?).to be true
end end
......
...@@ -183,6 +183,10 @@ FactoryBot.define do ...@@ -183,6 +183,10 @@ FactoryBot.define do
confidential { true } confidential { true }
end end
trait :with_review do
review
end
transient do transient do
in_reply_to { nil } in_reply_to { nil }
end end
......
...@@ -1621,6 +1621,29 @@ describe QuickActions::InterpretService do ...@@ -1621,6 +1621,29 @@ describe QuickActions::InterpretService do
expect(message).to eq("Created branch '#{branch_name}' and a merge request to resolve this issue.") expect(message).to eq("Created branch '#{branch_name}' and a merge request to resolve this issue.")
end end
end end
context 'submit_review command' do
using RSpec::Parameterized::TableSyntax
where(:note) do
[
'I like it',
'/submit_review'
]
end
with_them do
let(:content) { '/submit_review' }
let!(:draft_note) { create(:draft_note, note: note, merge_request: merge_request, author: developer) }
it 'submits the users current review' do
_, _, message = service.execute(content, merge_request)
expect { draft_note.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect(message).to eq('Submitted the current review.')
end
end
end
end end
describe '#explain' do describe '#explain' do
......
...@@ -49,4 +49,14 @@ describe NewNoteWorker do ...@@ -49,4 +49,14 @@ describe NewNoteWorker do
described_class.new.perform(unexistent_note_id) described_class.new.perform(unexistent_note_id)
end end
end end
context 'when note is with review' do
it 'does not create a new note notification' do
note = create(:note, :with_review)
expect_any_instance_of(NotificationService).not_to receive(:new_note)
subject.perform(note.id)
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