Skip to content

Fixes rerunning custom email verification when already verified

What does this MR do and why?

The Service Desk custom email feature allows users to use their own email address for Service Desk. They forward emails to the project specific Service Desk email address and configure SMTP settings so we can send Service Desk emails on their behalf. Before they can enable the feature, we have a verification process (that sends a verification email) that checks for email ownership and whether all technical requirements are met.

Fixes rerunning custom email verification when already verified

Now when ingesting a verification email we exit early if the custom email address for Service Desk has already been verified and might also be enabled.

Previously we reran the verification process which lead to disabling the custom email setting which was not intended.

Screenshots or screen recordings

🚫 backend only

How to set up and validate locally

  1. If you haven't set up incoming_email or service_desk_email for email ingestion, please add this to your gitlab.yml file in the development: section. Please restart GDK with gdk restart:
    incoming_email:
      enabled: true
      address: "incoming+%{key}@example.com"
    This will allow you to see the Service Desk section in the settings and generate project-specific email addresses.
  2. Select a project and user and enable the feature flag
    project = Project.find(7)
    current_user = User.first
    Feature.enable(:service_desk_custom_email, project)
  3. Create Service Desk custom email records
    custom_email = 'support@example.com'
    
    setting = ServiceDeskSetting.find_or_create_by!(project_id: project.id)
    setting.update!(custom_email: custom_email)
    
    credential = ServiceDesk::CustomEmailCredential.create!(
      project_id: project.id,
      smtp_address: 'smtp.gmail.com', # we need a valid smtp address
      smtp_port: 587,
      smtp_username: custom_email,
      smtp_password: 'supersecret'
    )
    
    verification = ServiceDesk::CustomEmailVerification.new(
      project_id: project.id
    )
    verification.mark_as_started!(current_user)
  4. Mark verification as finished and enable the configuration so outgoing Service Desk emails are sent using these credentials
    verification.mark_as_finished!
    
    project.reset
    setting.reset
    
    setting.update!(custom_email_enabled: true)
  5. Ingest a verification email. The ServiceResponse of the service should be an error.
    service_desk_address = project.service_desk_incoming_address
    
    email_raw = <<~EMAIL
      Delivered-To: #{service_desk_address}
      From: Flight Support <support@example.com>
      Date: Mon, 23 Jan 2023 17:50:46 +0100
      To: custom-support+verify@example.com
      Subject: Verify custom email address support@example.com for Flight
    
      This email is auto-generated. It verifies the ownership of the entered Service Desk custom email address and 
      correct functionality of email forwarding.
    
      Verification token: ZROT4ZZXA-Y6
      -- 
    
      You're receiving this email because of your account on 127.0.0.1.
    EMAIL
    
    ::ServiceDesk::CustomEmailVerifications::UpdateService.new(
      project: project.reset,
      current_user: nil,
      params: {
        mail: email_raw
      }
    ).execute
    The response should look similar to this:
    <ServiceResponse:0x000000015ddeb7b0 @http_status=nil, @message="Custom email address has already been verified.", @payload={}, @reason=nil, @status=:error>
  6. Check whether custom email is still enabled
    setting.reset.custom_email_enabled?
  7. (Optional) Clean everything up and disable flag
    ::ServiceDesk::CustomEmails::DestroyService.new(
      project: project,
      current_user: current_user
    ).execute
    Feature.disable(:service_desk_custom_email, false)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Marc Saleiko

Merge request reports