Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot
2023-09-05 00:09:51 +00:00
parent f796768612
commit dccf00df71
8 changed files with 149 additions and 3 deletions

View File

@ -139,6 +139,9 @@ module Emails
return mail if !service_desk_custom_email_enabled? && !force
return mail unless @service_desk_setting.custom_email_credential.present?
# Only set custom email reply address if it's enabled, not when we force it.
inject_service_desk_custom_email_reply_address unless force
mail.delivery_method(::Mail::SMTP, @service_desk_setting.custom_email_credential.delivery_options)
end
@ -146,6 +149,15 @@ module Emails
Feature.enabled?(:service_desk_custom_email, @project) && @service_desk_setting&.custom_email_enabled?
end
def inject_service_desk_custom_email_reply_address
return unless Feature.enabled?(:service_desk_custom_email_reply, @project)
reply_address = Gitlab::Email::ServiceDesk::CustomEmail.reply_address(@issue, reply_key)
headers['Reply-To'] = Mail::Address.new(reply_address).tap do |address|
address.display_name = reply_display_name(@issue)
end
end
def service_desk_sender_email_address
return unless service_desk_custom_email_enabled?

View File

@ -0,0 +1,8 @@
---
name: service_desk_custom_email_reply
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/130336
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/423880
milestone: '16.4'
type: development
group: group::incubation
default_enabled: false

View File

@ -18,6 +18,9 @@ Bear in mind that the syntax is very specific. Remove any spaces in the argument
before/after the brackets. Also, some shells (for example, Zsh) can interpret the open/close brackets
(`[]`) separately. You may want to either escape the brackets or use double quotes.
You can only import repositories that are in the namespace of the owner of the GitHub personal access token being used to import. For more information, see
[issue 424105](https://gitlab.com/gitlab-org/gitlab/-/issues/424105).
Prerequisite:
- At least the Maintainer role on the destination group to import to.

View File

@ -327,7 +327,7 @@ GitLab analyzers obtain dependency information using one of the following two me
The following package managers use lockfiles that GitLab analyzers are capable of parsing directly:
| Package Manager | Supported File Format Versions | Tested Versions |
| Package Manager | Supported File Format Versions | Tested Package Manager Versions |
| ------ | ------ | ------ |
| Bundler | Not applicable | [1.17.3](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/ruby-bundler/default/Gemfile.lock#L118), [2.1.4](https://gitlab.com/gitlab-org/security-products/tests/ruby-bundler/-/blob/bundler2-FREEZE/Gemfile.lock#L118) |
| Composer | Not applicable | [1.x](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/php-composer/default/composer.lock) |

View File

@ -0,0 +1,25 @@
# frozen_string_literal: true
module Gitlab
module Email
module ServiceDesk
# Doesn't include Gitlab::Email::Common because a custom email doesn't
# support all features and methods of ingestable email addresses like
# incoming_email and service_desk_email.
module CustomEmail
class << self
def reply_address(issue, reply_key)
return if reply_key.nil?
custom_email = issue&.project&.service_desk_setting&.custom_email
return if custom_email.nil?
# Reply keys for custom email addresses always go before the @.
# We don't have a placeholder.
custom_email.sub('@', "+#{reply_key}@")
end
end
end
end
end
end

View File

@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe 'sidekiq' do
RSpec.describe 'sidekiq', feature_category: :build do
describe 'enable_reliable_fetch?' do
subject { enable_reliable_fetch? }

View File

@ -0,0 +1,37 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Email::ServiceDesk::CustomEmail, feature_category: :service_desk do
let(:reply_key) { 'b7721fc7e8419911a8bea145236a0519' }
let(:custom_email) { 'support@example.com' }
let(:email_with_reply_key) { 'support+b7721fc7e8419911a8bea145236a0519@example.com' }
describe '.reply_address' do
let_it_be(:project) { create(:project) }
subject(:reply_address) { described_class.reply_address(nil, nil) }
it { is_expected.to be nil }
context 'with reply key' do
subject(:reply_address) { described_class.reply_address(nil, reply_key) }
it { is_expected.to be nil }
context 'with issue' do
let_it_be(:issue) { create(:issue, project: project) }
subject(:reply_address) { described_class.reply_address(issue, reply_key) }
it { is_expected.to be nil }
context 'with service_desk_setting and custom email' do
let!(:service_desk_setting) { create(:service_desk_setting, custom_email: custom_email, project: project) }
it { is_expected.to eq(email_with_reply_key) }
end
end
end
end
end

View File

@ -26,6 +26,16 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do
issue.issue_email_participants.create!(email: email)
end
before do
# Because we use global project and custom email instances, make sure
# custom email is disabled in all regular cases to avoid flakiness.
unless service_desk_setting.custom_email_verification.started?
service_desk_setting.custom_email_verification.mark_as_started!(user)
end
service_desk_setting.update!(custom_email_enabled: false) unless service_desk_setting.custom_email_enabled?
end
shared_examples 'a service desk notification email' do |attachments_count|
it 'builds the email correctly' do
aggregate_failures do
@ -42,6 +52,10 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do
expect(subject.parts[1].content_type).to include('text/html')
end
end
it 'uses system noreply address as Reply-To address' do
expect(subject.reply_to.first).to eq(Gitlab.config.gitlab.email_reply_to)
end
end
shared_examples 'a service desk notification email with template content' do |template_key, attachments_count|
@ -145,6 +159,41 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do
end
end
shared_examples 'a service desk notification email that uses custom email' do
before do
# Access via service_desk_setting to avoid flakiness
unless service_desk_setting.custom_email_verification.finished?
service_desk_setting.custom_email_verification.error = nil
service_desk_setting.custom_email_verification.mark_as_finished!
end
# Reset because we access changed records through these objects
service_desk_setting.reset
project.reset
service_desk_setting.update!(custom_email_enabled: true) unless service_desk_setting.custom_email_enabled?
end
it 'uses SMTP delivery method and custom email settings' do
expect_service_desk_custom_email_delivery_options(service_desk_setting)
end
it 'generates Reply-To address from custom email' do
reply_address = subject.reply_to.first
expected_reply_address = service_desk_setting.custom_email.sub('@', "+#{SentNotification.last.reply_key}@")
expect(reply_address).to eq(expected_reply_address)
end
context 'when feature flag service_desk_custom_email_reply is disabled' do
before do
stub_feature_flags(service_desk_custom_email_reply: false)
end
it { is_expected.to have_header 'Reply-To', /<reply+(.*)@#{Gitlab.config.gitlab.host}>\Z/ }
end
end
describe '.service_desk_thank_you_email' do
let_it_be(:reply_in_subject) { true }
let_it_be(:expected_text) do
@ -234,6 +283,12 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do
end
end
end
context 'when custom email is enabled' do
subject { Notify.service_desk_thank_you_email(issue.id) }
it_behaves_like 'a service desk notification email that uses custom email'
end
end
describe '.service_desk_new_note_email' do
@ -435,6 +490,12 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do
it_behaves_like 'a service desk notification email with template content', 'new_note'
end
end
context 'when custom email is enabled' do
subject { Notify.service_desk_new_note_email(issue.id, note.id, email) }
it_behaves_like 'a service desk notification email that uses custom email'
end
end
describe '.service_desk_custom_email_verification_email' do
@ -474,7 +535,7 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do
end
it 'contains verification token' do
is_expected.to have_body_text("Verification token: #{verification.token}")
is_expected.to have_body_text("Verification token: #{service_desk_setting.custom_email_verification.token}")
end
end