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