2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-02 06:38:35 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Issues::CreateService do
|
2021-04-08 14:09:32 -04:00
|
|
|
include AfterNextHelpers
|
|
|
|
|
2021-12-13 19:14:57 -05:00
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be_with_reload(:project) { create(:project, group: group) }
|
2020-09-14 11:09:28 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
2014-04-02 06:38:35 -04:00
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
let(:spam_params) { double }
|
|
|
|
|
2021-10-12 23:12:30 -04:00
|
|
|
describe '.rate_limiter_scoped_and_keyed' do
|
|
|
|
it 'is set via the rate_limit call' do
|
|
|
|
expect(described_class.rate_limiter_scoped_and_keyed).to be_a(RateLimitedService::RateLimiterScopedAndKeyed)
|
|
|
|
|
|
|
|
expect(described_class.rate_limiter_scoped_and_keyed.key).to eq(:issues_create)
|
2021-11-04 20:13:17 -04:00
|
|
|
expect(described_class.rate_limiter_scoped_and_keyed.opts[:scope]).to eq(%i[project current_user external_author])
|
2021-10-12 23:12:30 -04:00
|
|
|
expect(described_class.rate_limiter_scoped_and_keyed.rate_limiter_klass).to eq(Gitlab::ApplicationRateLimiter)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#rate_limiter_bypassed' do
|
|
|
|
let(:subject) { described_class.new(project: project, spam_params: {}) }
|
|
|
|
|
|
|
|
it 'is nil by default' do
|
|
|
|
expect(subject.rate_limiter_bypassed).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-21 07:40:52 -04:00
|
|
|
describe '#execute' do
|
2020-09-14 11:09:28 -04:00
|
|
|
let_it_be(:assignee) { create(:user) }
|
|
|
|
let_it_be(:milestone) { create(:milestone, project: project) }
|
2021-04-12 08:09:15 -04:00
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
let(:issue) { described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_spam_services
|
|
|
|
end
|
2016-04-21 06:25:21 -04:00
|
|
|
|
2016-04-21 07:40:52 -04:00
|
|
|
context 'when params are valid' do
|
2020-09-14 11:09:28 -04:00
|
|
|
let_it_be(:labels) { create_pair(:label, project: project) }
|
2016-04-21 06:46:48 -04:00
|
|
|
|
2020-09-14 11:09:28 -04:00
|
|
|
before_all do
|
2021-06-11 14:10:13 -04:00
|
|
|
project.add_guest(user)
|
|
|
|
project.add_guest(assignee)
|
2016-04-21 06:25:21 -04:00
|
|
|
end
|
2016-02-15 13:13:52 -05:00
|
|
|
|
2016-04-21 06:25:21 -04:00
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Awesome issue',
|
2016-02-15 13:13:52 -05:00
|
|
|
description: 'please fix',
|
2017-05-04 08:11:15 -04:00
|
|
|
assignee_ids: [assignee.id],
|
2016-04-21 06:46:48 -04:00
|
|
|
label_ids: labels.map(&:id),
|
2016-09-27 05:29:06 -04:00
|
|
|
milestone_id: milestone.id,
|
2020-10-01 14:10:20 -04:00
|
|
|
milestone: milestone,
|
2016-09-27 05:29:06 -04:00
|
|
|
due_date: Date.tomorrow }
|
2014-04-02 06:38:35 -04:00
|
|
|
end
|
|
|
|
|
2016-09-27 05:29:06 -04:00
|
|
|
it 'creates the issue with the given params' do
|
2020-09-08 17:08:53 -04:00
|
|
|
expect(Issuable::CommonSystemNotesService).to receive_message_chain(:new, :execute)
|
|
|
|
|
2016-09-27 05:29:06 -04:00
|
|
|
expect(issue).to be_persisted
|
|
|
|
expect(issue.title).to eq('Awesome issue')
|
2021-09-10 11:11:12 -04:00
|
|
|
expect(issue.assignees).to eq([assignee])
|
|
|
|
expect(issue.labels).to match_array(labels)
|
|
|
|
expect(issue.milestone).to eq(milestone)
|
|
|
|
expect(issue.due_date).to eq(Date.tomorrow)
|
|
|
|
expect(issue.work_item_type.base_type).to eq('issue')
|
2016-09-27 05:29:06 -04:00
|
|
|
end
|
|
|
|
|
2020-09-08 17:08:53 -04:00
|
|
|
context 'when skip_system_notes is true' do
|
2021-06-21 08:07:45 -04:00
|
|
|
let(:issue) { described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute(skip_system_notes: true) }
|
2020-09-08 17:08:53 -04:00
|
|
|
|
|
|
|
it 'does not call Issuable::CommonSystemNotesService' do
|
|
|
|
expect(Issuable::CommonSystemNotesService).not_to receive(:new)
|
|
|
|
|
|
|
|
issue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-14 11:09:28 -04:00
|
|
|
it_behaves_like 'not an incident issue'
|
|
|
|
|
2021-11-09 16:10:00 -05:00
|
|
|
context 'when issue is incident type' do
|
2020-09-10 17:08:28 -04:00
|
|
|
before do
|
2020-09-14 11:09:28 -04:00
|
|
|
opts.merge!(issue_type: 'incident')
|
2020-09-10 17:08:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:current_user) { user }
|
2020-09-14 11:09:28 -04:00
|
|
|
let(:incident_label_attributes) { attributes_for(:label, :incident) }
|
2020-09-10 17:08:28 -04:00
|
|
|
|
|
|
|
subject { issue }
|
|
|
|
|
2021-11-09 16:10:00 -05:00
|
|
|
context 'as reporter' do
|
|
|
|
let_it_be(:reporter) { create(:user) }
|
2020-09-14 11:09:28 -04:00
|
|
|
|
2021-11-09 16:10:00 -05:00
|
|
|
let(:user) { reporter }
|
2020-09-14 11:09:28 -04:00
|
|
|
|
2021-11-09 16:10:00 -05:00
|
|
|
before_all do
|
|
|
|
project.add_reporter(reporter)
|
2020-09-14 11:09:28 -04:00
|
|
|
end
|
|
|
|
|
2021-11-09 16:10:00 -05:00
|
|
|
it_behaves_like 'incident issue'
|
|
|
|
it_behaves_like 'has incident label'
|
|
|
|
|
|
|
|
it 'does create an incident label' do
|
|
|
|
expect { subject }
|
|
|
|
.to change { Label.where(incident_label_attributes).count }.by(1)
|
2020-09-14 11:09:28 -04:00
|
|
|
end
|
2021-11-09 16:10:00 -05:00
|
|
|
|
|
|
|
context 'when invalid' do
|
|
|
|
before do
|
|
|
|
opts.merge!(title: '')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not apply an incident label prematurely' do
|
|
|
|
expect { subject }.to not_change(LabelLink, :count).and not_change(Issue, :count)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as guest' do
|
|
|
|
it_behaves_like 'not an incident issue'
|
2020-09-14 11:09:28 -04:00
|
|
|
end
|
2020-09-10 17:08:28 -04:00
|
|
|
end
|
|
|
|
|
2017-09-19 07:55:56 -04:00
|
|
|
it 'refreshes the number of open issues', :use_clean_rails_memory_store_caching do
|
2021-09-08 08:12:01 -04:00
|
|
|
expect do
|
|
|
|
issue
|
|
|
|
|
|
|
|
BatchLoader::Executor.clear_current
|
|
|
|
end.to change { project.open_issues_count }.from(0).to(1)
|
2017-08-17 11:21:25 -04:00
|
|
|
end
|
|
|
|
|
2021-06-11 14:10:13 -04:00
|
|
|
context 'when current user cannot set issue metadata in the project' do
|
|
|
|
let_it_be(:non_member) { create(:user) }
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2021-06-11 14:10:13 -04:00
|
|
|
it 'filters out params that cannot be set without the :set_issue_metadata permission' do
|
2021-06-21 08:07:45 -04:00
|
|
|
issue = described_class.new(project: project, current_user: non_member, params: opts, spam_params: spam_params).execute
|
2016-09-27 05:29:06 -04:00
|
|
|
|
|
|
|
expect(issue).to be_persisted
|
|
|
|
expect(issue.title).to eq('Awesome issue')
|
2017-01-28 19:14:56 -05:00
|
|
|
expect(issue.description).to eq('please fix')
|
2017-05-04 08:11:15 -04:00
|
|
|
expect(issue.assignees).to be_empty
|
2016-09-27 05:29:06 -04:00
|
|
|
expect(issue.labels).to be_empty
|
|
|
|
expect(issue.milestone).to be_nil
|
|
|
|
expect(issue.due_date).to be_nil
|
|
|
|
end
|
2020-10-01 14:10:20 -04:00
|
|
|
|
2021-06-11 14:10:13 -04:00
|
|
|
it 'can create confidential issues' do
|
2021-06-21 08:07:45 -04:00
|
|
|
issue = described_class.new(project: project, current_user: non_member, params: { confidential: true }, spam_params: spam_params).execute
|
2020-10-01 14:10:20 -04:00
|
|
|
|
|
|
|
expect(issue.confidential).to be_truthy
|
|
|
|
end
|
2016-09-27 05:29:06 -04:00
|
|
|
end
|
2016-02-15 13:13:52 -05:00
|
|
|
|
2020-09-04 11:08:46 -04:00
|
|
|
it 'moves the issue to the end, in an asynchronous worker' do
|
2021-12-02 16:10:16 -05:00
|
|
|
expect(Issues::PlacementWorker).to receive(:perform_async).with(be_nil, Integer)
|
2020-08-26 20:10:33 -04:00
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2020-08-26 20:10:33 -04:00
|
|
|
end
|
|
|
|
|
2016-09-19 16:21:39 -04:00
|
|
|
context 'when label belongs to project group' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:group_labels) { create_pair(:group_label, group: group) }
|
|
|
|
|
|
|
|
let(:opts) do
|
|
|
|
{
|
|
|
|
title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
label_ids: group_labels.map(&:id)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2020-09-03 14:08:29 -04:00
|
|
|
project.update!(group: group)
|
2016-09-19 16:21:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns group labels' do
|
|
|
|
expect(issue.labels).to match_array group_labels
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-21 07:40:52 -04:00
|
|
|
context 'when label belongs to different project' do
|
2016-04-21 06:20:05 -04:00
|
|
|
let(:label) { create(:label) }
|
2016-04-21 06:25:21 -04:00
|
|
|
|
2016-04-21 06:20:05 -04:00
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
label_ids: [label.id] }
|
|
|
|
end
|
|
|
|
|
2016-05-23 14:16:35 -04:00
|
|
|
it 'does not assign label' do
|
2016-05-23 19:37:59 -04:00
|
|
|
expect(issue.labels).not_to include label
|
2016-04-21 06:20:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-28 14:09:35 -04:00
|
|
|
context 'when labels is nil' do
|
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
labels: nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not assign label' do
|
|
|
|
expect(issue.labels).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when labels is nil and label_ids is present' do
|
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
labels: nil,
|
|
|
|
label_ids: labels.map(&:id) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns group labels' do
|
|
|
|
expect(issue.labels).to match_array labels
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-21 07:40:52 -04:00
|
|
|
context 'when milestone belongs to different project' do
|
2016-04-21 06:20:05 -04:00
|
|
|
let(:milestone) { create(:milestone) }
|
2016-04-21 06:25:21 -04:00
|
|
|
|
2016-04-21 06:20:05 -04:00
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
milestone_id: milestone.id }
|
|
|
|
end
|
|
|
|
|
2016-04-21 06:25:21 -04:00
|
|
|
it 'does not assign milestone' do
|
2016-05-23 19:37:59 -04:00
|
|
|
expect(issue.milestone).not_to eq milestone
|
2016-04-21 06:20:05 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-12 15:05:10 -04:00
|
|
|
|
2017-05-10 16:54:10 -04:00
|
|
|
context 'when assignee is set' do
|
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
assignees: [assignee] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'invalidates open issues counter for assignees when issue is assigned' do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(assignee)
|
2017-05-10 16:54:10 -04:00
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2017-05-10 16:54:10 -04:00
|
|
|
|
|
|
|
expect(assignee.assigned_open_issues_count).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-01 05:09:49 -04:00
|
|
|
context 'when duplicate label titles are given' do
|
|
|
|
let(:label) { create(:label, project: project) }
|
|
|
|
|
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
labels: [label.title, label.title] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns the label once' do
|
|
|
|
expect(issue.labels).to contain_exactly(label)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-03 17:09:39 -04:00
|
|
|
context 'when sentry identifier is given' do
|
|
|
|
before do
|
|
|
|
sentry_attributes = { sentry_issue_attributes: { sentry_issue_identifier: 42 } }
|
|
|
|
opts.merge!(sentry_attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not assign the sentry error' do
|
|
|
|
expect(issue.sentry_issue).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user is reporter or above' do
|
|
|
|
before do
|
|
|
|
project.add_reporter(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns the sentry error' do
|
|
|
|
expect(issue.sentry_issue).to be_kind_of(SentryIssue)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-30 18:11:46 -04:00
|
|
|
it 'executes issue hooks when issue is not confidential' do
|
|
|
|
opts = { title: 'Title', description: 'Description', confidential: false }
|
|
|
|
|
|
|
|
expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :issue_hooks)
|
2021-06-30 02:07:17 -04:00
|
|
|
expect(project).to receive(:execute_integrations).with(an_instance_of(Hash), :issue_hooks)
|
2016-08-30 18:11:46 -04:00
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2016-08-30 18:11:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'executes confidential issue hooks when issue is confidential' do
|
2016-08-12 15:05:10 -04:00
|
|
|
opts = { title: 'Title', description: 'Description', confidential: true }
|
|
|
|
|
2016-08-30 18:11:46 -04:00
|
|
|
expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :confidential_issue_hooks)
|
2021-06-30 02:07:17 -04:00
|
|
|
expect(project).to receive(:execute_integrations).with(an_instance_of(Hash), :confidential_issue_hooks)
|
2016-08-12 15:05:10 -04:00
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2016-08-12 15:05:10 -04:00
|
|
|
end
|
2020-02-13 19:09:07 -05:00
|
|
|
|
2021-11-11 13:14:04 -05:00
|
|
|
context 'when rate limiting is in effect', :freeze_time, :clean_gitlab_redis_rate_limiting do
|
2021-11-04 20:13:17 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_feature_flags(rate_limited_service_issues_create: true)
|
|
|
|
stub_application_setting(issues_create_limit: 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
2.times { described_class.new(project: project, current_user: user, params: opts, spam_params: double).execute }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when too many requests are sent by one user' do
|
|
|
|
it 'raises an error' do
|
2021-11-11 13:14:04 -05:00
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
end.to raise_error(RateLimitedService::RateLimitedError)
|
2021-11-04 20:13:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates 1 issue' do
|
2021-11-11 13:14:04 -05:00
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
rescue RateLimitedService::RateLimitedError
|
|
|
|
end.to change { Issue.count }.by(1)
|
2021-11-04 20:13:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-12 13:12:20 -05:00
|
|
|
context 'when limit is higher than count of issues being created' do
|
2021-11-04 20:13:17 -04:00
|
|
|
before do
|
2021-11-12 13:12:20 -05:00
|
|
|
stub_application_setting(issues_create_limit: 2)
|
2021-11-04 20:13:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates 2 issues' do
|
2021-11-11 13:14:04 -05:00
|
|
|
expect { subject }.to change { Issue.count }.by(2)
|
2021-11-04 20:13:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-13 19:09:07 -05:00
|
|
|
context 'after_save callback to store_mentions' do
|
|
|
|
context 'when mentionable attributes change' do
|
|
|
|
let(:opts) { { title: 'Title', description: "Description with #{user.to_reference}" } }
|
|
|
|
|
|
|
|
it 'saves mentions' do
|
|
|
|
expect_next_instance_of(Issue) do |instance|
|
|
|
|
expect(instance).to receive(:store_mentions!).and_call_original
|
|
|
|
end
|
|
|
|
expect(issue.user_mentions.count).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when save fails' do
|
|
|
|
let(:opts) { { title: '', label_ids: labels.map(&:id), milestone_id: milestone.id } }
|
|
|
|
|
|
|
|
it 'does not call store_mentions' do
|
|
|
|
expect_next_instance_of(Issue) do |instance|
|
|
|
|
expect(instance).not_to receive(:store_mentions!).and_call_original
|
|
|
|
end
|
|
|
|
expect(issue.valid?).to be false
|
|
|
|
expect(issue.user_mentions.count).to eq 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-03-04 19:07:49 -05:00
|
|
|
|
2021-02-25 13:11:05 -05:00
|
|
|
it 'schedules a namespace onboarding create action worker' do
|
|
|
|
expect(Namespaces::OnboardingIssueCreatedWorker).to receive(:perform_async).with(project.namespace.id)
|
|
|
|
|
|
|
|
issue
|
|
|
|
end
|
2014-04-02 06:38:35 -04:00
|
|
|
end
|
2016-06-30 11:34:19 -04:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
context 'issue create service' do
|
|
|
|
context 'assignees' do
|
2020-09-14 11:09:28 -04:00
|
|
|
before_all do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
it 'removes assignee when user id is invalid' do
|
|
|
|
opts = { title: 'Title', description: 'Description', assignee_ids: [-1] }
|
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
issue = described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
expect(issue.assignees).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes assignee when user id is 0' do
|
2019-01-16 07:09:29 -05:00
|
|
|
opts = { title: 'Title', description: 'Description', assignee_ids: [0] }
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
issue = described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
expect(issue.assignees).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves assignee when user id is valid' do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(assignee)
|
2017-05-04 08:11:15 -04:00
|
|
|
opts = { title: 'Title', description: 'Description', assignee_ids: [assignee.id] }
|
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
issue = described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
expect(issue.assignees).to eq([assignee])
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when issuable feature is private" do
|
|
|
|
before do
|
2020-09-03 14:08:29 -04:00
|
|
|
project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE,
|
2017-05-04 08:11:15 -04:00
|
|
|
merge_requests_access_level: ProjectFeature::PRIVATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
levels = [Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PUBLIC]
|
|
|
|
|
|
|
|
levels.each do |level|
|
|
|
|
it "removes not authorized assignee when project is #{Gitlab::VisibilityLevel.level_name(level)}" do
|
2020-09-03 14:08:29 -04:00
|
|
|
project.update!(visibility_level: level)
|
2017-05-04 08:11:15 -04:00
|
|
|
opts = { title: 'Title', description: 'Description', assignee_ids: [assignee.id] }
|
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
issue = described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
expect(issue.assignees).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-12-14 16:39:53 -05:00
|
|
|
|
2020-06-29 11:08:56 -04:00
|
|
|
it_behaves_like 'issuable record that supports quick actions' do
|
2021-06-21 08:07:45 -04:00
|
|
|
let(:issuable) { described_class.new(project: project, current_user: user, params: params, spam_params: spam_params).execute }
|
2020-06-29 11:08:56 -04:00
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2017-05-31 01:50:53 -04:00
|
|
|
context 'Quick actions' do
|
2021-12-13 19:14:57 -05:00
|
|
|
context 'with assignee, milestone, and contact in params and command' do
|
|
|
|
let_it_be(:contact) { create(:contact, group: group) }
|
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
let(:opts) do
|
|
|
|
{
|
|
|
|
assignee_ids: [create(:user).id],
|
|
|
|
milestone_id: 1,
|
|
|
|
title: 'Title',
|
2021-12-13 19:14:57 -05:00
|
|
|
description: %(/assign @#{assignee.username}\n/milestone %"#{milestone.name}"),
|
|
|
|
add_contacts: [contact.email]
|
2017-05-04 08:11:15 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-09-14 11:09:28 -04:00
|
|
|
before_all do
|
2021-12-13 19:14:57 -05:00
|
|
|
group.add_maintainer(user)
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(assignee)
|
2017-05-04 08:11:15 -04:00
|
|
|
end
|
|
|
|
|
2021-12-13 19:14:57 -05:00
|
|
|
it 'assigns, sets milestone, and sets contact to issuable from command' do
|
2017-05-04 08:11:15 -04:00
|
|
|
expect(issue).to be_persisted
|
|
|
|
expect(issue.assignees).to eq([assignee])
|
|
|
|
expect(issue.milestone).to eq(milestone)
|
2021-12-13 19:14:57 -05:00
|
|
|
expect(issue.issue_customer_relations_contacts.last.contact).to eq(contact)
|
2017-05-04 08:11:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
context 'resolving discussions' do
|
2020-09-14 11:09:28 -04:00
|
|
|
let_it_be(:discussion) { create(:diff_note_on_merge_request).to_discussion }
|
|
|
|
let_it_be(:merge_request) { discussion.noteable }
|
|
|
|
let_it_be(:project) { merge_request.source_project }
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2020-09-14 11:09:28 -04:00
|
|
|
before_all do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
describe 'for a single discussion' do
|
2017-03-10 03:19:12 -05:00
|
|
|
let(:opts) { { discussion_to_resolve: discussion.id, merge_request_to_resolve_discussions_of: merge_request.iid } }
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
it 'resolves the discussion' do
|
2021-06-21 08:07:45 -04:00
|
|
|
described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2016-12-22 07:31:12 -05:00
|
|
|
discussion.first_note.reload
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
expect(discussion.resolved?).to be(true)
|
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
it 'added a system note to the discussion' do
|
2021-06-21 08:07:45 -04:00
|
|
|
described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
reloaded_discussion = MergeRequest.find(merge_request.id).discussions.first
|
|
|
|
|
|
|
|
expect(reloaded_discussion.last_note.system).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns the title and description for the issue' do
|
2021-06-21 08:07:45 -04:00
|
|
|
issue = described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2016-12-22 07:31:12 -05:00
|
|
|
|
|
|
|
expect(issue.title).not_to be_nil
|
|
|
|
expect(issue.description).not_to be_nil
|
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
it 'can set nil explicitly to the title and description' do
|
2021-05-11 23:10:21 -04:00
|
|
|
issue = described_class.new(project: project, current_user: user,
|
|
|
|
params: {
|
|
|
|
merge_request_to_resolve_discussions_of: merge_request,
|
|
|
|
description: nil,
|
|
|
|
title: nil
|
2021-06-21 08:07:45 -04:00
|
|
|
},
|
|
|
|
spam_params: spam_params).execute
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
expect(issue.description).to be_nil
|
|
|
|
expect(issue.title).to be_nil
|
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
describe 'for a merge request' do
|
2017-03-10 03:19:12 -05:00
|
|
|
let(:opts) { { merge_request_to_resolve_discussions_of: merge_request.iid } }
|
2016-12-22 07:31:12 -05:00
|
|
|
|
|
|
|
it 'resolves the discussion' do
|
2021-06-21 08:07:45 -04:00
|
|
|
described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2016-12-22 07:31:12 -05:00
|
|
|
discussion.first_note.reload
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
expect(discussion.resolved?).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'added a system note to the discussion' do
|
2021-06-21 08:07:45 -04:00
|
|
|
described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2016-12-22 07:31:12 -05:00
|
|
|
|
|
|
|
reloaded_discussion = MergeRequest.find(merge_request.id).discussions.first
|
|
|
|
|
|
|
|
expect(reloaded_discussion.last_note.system).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns the title and description for the issue' do
|
2021-06-21 08:07:45 -04:00
|
|
|
issue = described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute
|
2016-12-22 07:31:12 -05:00
|
|
|
|
|
|
|
expect(issue.title).not_to be_nil
|
|
|
|
expect(issue.description).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can set nil explicitly to the title and description' do
|
2021-05-11 23:10:21 -04:00
|
|
|
issue = described_class.new(project: project, current_user: user,
|
|
|
|
params: {
|
|
|
|
merge_request_to_resolve_discussions_of: merge_request,
|
|
|
|
description: nil,
|
|
|
|
title: nil
|
2021-06-21 08:07:45 -04:00
|
|
|
},
|
|
|
|
spam_params: spam_params).execute
|
2016-12-22 07:31:12 -05:00
|
|
|
|
|
|
|
expect(issue.description).to be_nil
|
|
|
|
expect(issue.title).to be_nil
|
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
end
|
2017-01-27 11:25:39 -05:00
|
|
|
|
|
|
|
context 'checking spam' do
|
2021-01-27 04:09:01 -05:00
|
|
|
let(:params) do
|
2017-01-27 11:25:39 -05:00
|
|
|
{
|
2021-06-21 08:07:45 -04:00
|
|
|
title: 'Spam issue'
|
2017-01-27 11:25:39 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-01-27 04:09:01 -05:00
|
|
|
subject do
|
2021-06-21 08:07:45 -04:00
|
|
|
described_class.new(project: project, current_user: user, params: params, spam_params: spam_params)
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
|
2021-01-27 04:09:01 -05:00
|
|
|
it 'executes SpamActionService' do
|
|
|
|
expect_next_instance_of(
|
|
|
|
Spam::SpamActionService,
|
|
|
|
{
|
2021-06-21 08:07:45 -04:00
|
|
|
spammable: kind_of(Issue),
|
|
|
|
spam_params: spam_params,
|
|
|
|
user: an_instance_of(User),
|
2021-01-27 04:09:01 -05:00
|
|
|
action: :create
|
|
|
|
}
|
|
|
|
) do |instance|
|
2021-06-21 08:07:45 -04:00
|
|
|
expect(instance).to receive(:execute)
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
|
2021-01-27 04:09:01 -05:00
|
|
|
subject.execute
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
end
|
2014-04-02 06:38:35 -04:00
|
|
|
end
|
|
|
|
end
|