Skip to content

Adds custom email create and destroy service

Marc Saleiko requested to merge ms-sd-custom-email-services into master

Feature context

Click to expand 👇

Right now it is not possible to customize the Service Desk email address (intake and sending) in its entirety. On self-hosted instances you have more control over the used addresses, but you will still have a rather cryptic target email address for a specific service desk in a project. For .com users it's currently not possible to customize the Service Desk email at all.

There is a proposal and a further exploration around this issue. A summary of the solution path is the following: Users set up their custom email to forward all emails to the cryptic Service Desk email and provide SMTP credentials so we can send emails on their behalf. This way customers seeking support will only see the custom email address in their communication.

There is further discussion about improving and changing the general infrastructure, but this approach is a MVC to solve the issue for our customers.

🗺 How does it contribute to the whole feature?

This MR is part of a series of MRs that will follow in order to complete this feature. See #329990 (comment 1227384943) for a detailed breakdown. Here's a summary:

  1. Using SMTP credentials. Foundation work. Add Service Desk custom email foundation (!108017 - merged)
  2. Verify email ownership, correct function and setup
  3. 🎯 Add settings and validation to Settings page. Part 1: Controller services for endpoint
  4. Ingest replies from custom email
  5. Add documentation

What does this MR do and why?

🎏 This feature is hidden behind a feature flag and not used on production yet.

This MR introduces two new services that pieces the previous work on custom email addresses together.

  1. The CreateService will be called from a controller action that will be triggered from a vue app on the Service Desk settings page. The service will then update the ServiceDeskSetting with the given custom_email, add the given credentials to a CustomEmailCredential record and trigger the verification process.
  2. The DestroyService will also be called from a controller action (also triggered via vue app). Apart from enabling or disabling the custom email address (after verification) there won't be a way to edit the custom email records. The only way to change the configuration is to delete the custom email address and it's records and start the process again. This service makes sure all records get deleted. Adds custom email create and destroy service
  3. I also touched ServiceDeskSetting::UpdateService because it didn't return ServiceResponse yet and it did not feel right to use a legacy result in this new service. Only minor changes to the calling controller and spec file.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

🚫 backend only

How to set up and validate locally

  1. Select a project that you didn't use for Service Desk custom email testing purposes before. Id 6 worked fine for me

  2. Get objects and enable feature flag for project

    project = Project.find 6
    user = User.first
    
    Feature.enable(:service_desk_custom_email, project)
  3. Trigger service with params (note, smtp_address must be resolvable, I use gmail for this)

    params = {
      custom_email: 'doesntexist@gmail.com',
      smtp_address: 'smtp.gmail.com',
      smtp_port: '587',
      smtp_username: 'doesntexist@gmail.com',
      smtp_password: 'supersecret'
    }
    
    response = ServiceDesk::CustomEmails::CreateService.new(
      project: project, 
      current_user: user, 
      params: params
    ).execute
  4. Reset project and check response and records (because these are not valid credentials, the verification record will eventually move to the failed state. But that's fine here. If you provide correct credentials it should be in started state).

    project.reset
    
    pp response
    pp project.service_desk_setting
    pp project.service_desk_custom_email_credential
    pp project.service_desk_custom_email_verification
  5. Now delete everything again

    response = ServiceDesk::CustomEmails::DestroyService.new(
      project: project, 
      current_user: user
    ).execute
  6. Reuse code from 4. to check the response and that we deleted everything.

  7. You can also disable the feature flag and see the service error plus message

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