diff --git a/app/models/user.rb b/app/models/user.rb index 27a884fa4..83f09b605 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -67,6 +67,7 @@ class User < ApplicationRecord MFA_TEMPLATE_ID = "6bdf5ee1-8e01-4be1-b1f9-747061d8a24c".freeze RESET_PASSWORD_TEMPLATE_ID = "2c410c19-80a7-481c-a531-2bcb3264f8e6".freeze SET_PASSWORD_TEMPLATE_ID = "257460a6-6616-4640-a3f9-17c3d73d9e91".freeze + BETA_ONBOARDING_TEMPLATE_ID = "b48bc2cd-5887-4611-8296-d0ab3ed0e7fd".freeze def reset_password_notify_template last_sign_in_at ? RESET_PASSWORD_TEMPLATE_ID : SET_PASSWORD_TEMPLATE_ID @@ -82,6 +83,16 @@ class User < ApplicationRecord DeviseNotifyMailer.new.send_email(email, template_id, personalisation) end + def send_beta_onboarding_email + return unless URI::MailTo::EMAIL_REGEXP.match?(email) + + template_id = BETA_ONBOARDING_TEMPLATE_ID + url = edit_user_password_url({ host: ENV["APP_HOST"] }) + token = Devise.token_generator.generate(User, :reset_password_token) + personalisation = { name: name || email, link: "#{url}?reset_password_token=#{token}" } + DeviseNotifyMailer.new.send_email(email, template_id, personalisation) + end + def assignable_roles return {} unless data_coordinator? || support? return ROLES if support? diff --git a/lib/tasks/onboarding_emails.rake b/lib/tasks/onboarding_emails.rake new file mode 100644 index 000000000..4624055ef --- /dev/null +++ b/lib/tasks/onboarding_emails.rake @@ -0,0 +1,14 @@ +include Rails.application.routes.url_helpers + +namespace :onboarding_emails do + desc "Send onboarding emails to private beta users" + task :send, %i[organisation_id] => :environment do |_task, args| + organisation_id = args[:organisation_id] + raise "Organisation id must be provided" unless organisation_id + + organisation = Organisation.find(organisation_id) + raise "Organisation #{organisation_id} does not exist" unless organisation + + organisation.users.each(&:send_beta_onboarding_email) + end +end diff --git a/spec/features/reset_password.html.erb b/spec/features/reset_password.html.erb deleted file mode 100644 index 1bf271dab..000000000 --- a/spec/features/reset_password.html.erb +++ /dev/null @@ -1,31 +0,0 @@ -<% content_for :title, "Reset your password" %> - -<% content_for :before_content do %> - <%= govuk_back_link( - text: "Back", - href: :back, - ) %> -<% end %> - -<%= form_for(@user, as: :user, url: password_path(User), html: { method: :put }) do |f| %> - <%= f.hidden_field :reset_password_token %> -