Commit fe6f4c1b authored by Sean McGivern's avatar Sean McGivern

Merge branch 'servicedesk-check' into 'master'

Show service desk address field only if enabled

See merge request gitlab-org/gitlab!48232
parents 8b40c796 11815435
......@@ -30,6 +30,10 @@ export default {
required: false,
default: '',
},
customEmailEnabled: {
type: Boolean,
required: false,
},
selectedTemplate: {
type: String,
required: false,
......@@ -140,6 +144,7 @@ export default {
:is-enabled="isEnabled"
:incoming-email="incomingEmail"
:custom-email="updatedCustomEmail"
:custom-email-enabled="customEmailEnabled"
:initial-selected-template="selectedTemplate"
:initial-outgoing-name="outgoingName"
:initial-project-key="projectKey"
......
......@@ -31,6 +31,10 @@ export default {
required: false,
default: '',
},
customEmailEnabled: {
type: Boolean,
required: false,
},
initialSelectedTemplate: {
type: String,
required: false,
......@@ -69,7 +73,7 @@ export default {
return [''].concat(this.templates);
},
hasProjectKeySupport() {
return Boolean(this.glFeatures.serviceDeskCustomAddress);
return Boolean(this.customEmailEnabled);
},
email() {
return this.customEmail || this.incomingEmail;
......
......@@ -18,6 +18,7 @@ export default () => {
endpoint: dataset.endpoint,
incomingEmail: dataset.incomingEmail,
customEmail: dataset.customEmail,
customEmailEnabled: parseBoolean(dataset.customEmailEnabled),
selectedTemplate: dataset.selectedTemplate,
outgoingName: dataset.outgoingName,
projectKey: dataset.projectKey,
......@@ -31,6 +32,7 @@ export default () => {
endpoint: this.endpoint,
incomingEmail: this.incomingEmail,
customEmail: this.customEmail,
customEmailEnabled: this.customEmailEnabled,
selectedTemplate: this.selectedTemplate,
outgoingName: this.outgoingName,
projectKey: this.projectKey,
......
......@@ -35,7 +35,6 @@ class ProjectsController < Projects::ApplicationController
before_action :export_rate_limit, only: [:export, :download_export, :generate_new_export]
before_action only: [:edit] do
push_frontend_feature_flag(:service_desk_custom_address, @project)
push_frontend_feature_flag(:approval_suggestions, @project, default_enabled: true)
end
......
......@@ -2507,8 +2507,7 @@ class Project < ApplicationRecord
end
def service_desk_custom_address
return unless ::Gitlab::ServiceDeskEmail.enabled?
return unless ::Feature.enabled?(:service_desk_custom_address, self)
return unless service_desk_custom_address_enabled?
key = service_desk_setting&.project_key
return unless key.present?
......@@ -2516,6 +2515,10 @@ class Project < ApplicationRecord
::Gitlab::ServiceDeskEmail.address_for_key("#{full_path_slug}-#{key}")
end
def service_desk_custom_address_enabled?
::Gitlab::ServiceDeskEmail.enabled? && ::Feature.enabled?(:service_desk_custom_address, self)
end
def root_namespace
if namespace.has_parent?
namespace.root_ancestor
......
......@@ -12,6 +12,7 @@
enabled: "#{@project.service_desk_enabled}",
incoming_email: (@project.service_desk_incoming_address if @project.service_desk_enabled),
custom_email: (@project.service_desk_custom_address if @project.service_desk_enabled),
custom_email_enabled: "#{@project.service_desk_custom_address_enabled?}",
selected_template: "#{@project.service_desk_setting&.issue_template_key}",
outgoing_name: "#{@project.service_desk_setting&.outgoing_name}",
project_key: "#{@project.service_desk_setting&.project_key}",
......
......@@ -14,20 +14,57 @@ RSpec.describe 'Service Desk Setting', :js do
allow_any_instance_of(Project).to receive(:present).with(current_user: user).and_return(presenter)
allow(::Gitlab::IncomingEmail).to receive(:enabled?) { true }
allow(::Gitlab::IncomingEmail).to receive(:supports_wildcard?) { true }
visit edit_project_path(project)
end
it 'shows activation checkbox' do
visit edit_project_path(project)
expect(page).to have_selector("#service-desk-checkbox")
end
it 'shows incoming email after activating' do
find("#service-desk-checkbox").click
wait_for_requests
project.reload
expect(project.service_desk_enabled).to be_truthy
expect(project.service_desk_address).to be_present
expect(find('[data-testid="incoming-email"]').value).to eq(project.service_desk_address)
context 'when service_desk_email is disabled' do
before do
allow(::Gitlab::ServiceDeskEmail).to receive(:enabled?).and_return(false)
visit edit_project_path(project)
end
it 'shows incoming email but not project name suffix after activating' do
find("#service-desk-checkbox").click
wait_for_requests
project.reload
expect(project.service_desk_enabled).to be_truthy
expect(project.service_desk_address).to be_present
expect(find('[data-testid="incoming-email"]').value).to eq(project.service_desk_incoming_address)
expect(page).not_to have_selector('#service-desk-project-suffix')
end
end
context 'when service_desk_email is enabled' do
before do
allow(::Gitlab::ServiceDeskEmail).to receive(:enabled?) { true }
allow(::Gitlab::ServiceDeskEmail).to receive(:address_for_key) { 'address-suffix@example.com' }
visit edit_project_path(project)
end
it 'allows setting of custom address suffix' do
find("#service-desk-checkbox").click
wait_for_requests
project.reload
expect(find('[data-testid="incoming-email"]').value).to eq(project.service_desk_incoming_address)
page.within '#js-service-desk' do
fill_in('service-desk-project-suffix', with: 'foo')
click_button 'Save changes'
end
wait_for_requests
expect(find('[data-testid="incoming-email"]').value).to eq('address-suffix@example.com')
end
end
end
......@@ -1535,6 +1535,42 @@ RSpec.describe Project, factory_default: :keep do
end
end
describe '.service_desk_custom_address_enabled?' do
let_it_be(:project) { create(:project, service_desk_enabled: true) }
subject(:address_enabled) { project.service_desk_custom_address_enabled? }
context 'when service_desk_email is enabled' do
before do
allow(::Gitlab::ServiceDeskEmail).to receive(:enabled?).and_return(true)
end
it 'returns true' do
expect(address_enabled).to be_truthy
end
context 'when service_desk_custom_address flag is disabled' do
before do
stub_feature_flags(service_desk_custom_address: false)
end
it 'returns false' do
expect(address_enabled).to be_falsey
end
end
end
context 'when service_desk_email is disabled' do
before do
allow(::Gitlab::ServiceDeskEmail).to receive(:enabled?).and_return(false)
end
it 'returns false when service_desk_email is disabled' do
expect(address_enabled).to be_falsey
end
end
end
describe '.find_by_service_desk_project_key' do
it 'returns the correct project' do
project1 = create(:project)
......
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