debian-mirror-gitlab/app/mailers/previews/notify_preview.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

400 lines
11 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class NotifyPreview < ActionMailer::Preview
def note_merge_request_email_for_individual_note
note_email(:note_merge_request_email) do
note = <<-MD.strip_heredoc
This is an individual note on a merge request :smiley:
In this notification email, we expect to see:
- The note contents (that's what you're looking at)
2018-12-05 23:21:45 +05:30
- A link to view this note on GitLab
2017-08-17 22:00:37 +05:30
- An explanation for why the user is receiving this notification
MD
create_note(noteable_type: 'merge_request', noteable_id: merge_request.id, note: note)
end
end
def note_merge_request_email_for_discussion
note_email(:note_merge_request_email) do
note = <<-MD.strip_heredoc
This is a new discussion on a merge request :smiley:
In this notification email, we expect to see:
- A line saying who started this discussion
- The note contents (that's what you're looking at)
2018-12-05 23:21:45 +05:30
- A link to view this discussion on GitLab
2017-08-17 22:00:37 +05:30
- An explanation for why the user is receiving this notification
MD
create_note(noteable_type: 'merge_request', noteable_id: merge_request.id, type: 'DiscussionNote', note: note)
end
end
def note_merge_request_email_for_diff_discussion
note_email(:note_merge_request_email) do
note = <<-MD.strip_heredoc
This is a new discussion on a merge request :smiley:
In this notification email, we expect to see:
- A line saying who started this discussion and on what file
- The diff
- The note contents (that's what you're looking at)
2018-12-05 23:21:45 +05:30
- A link to view this discussion on GitLab
2017-08-17 22:00:37 +05:30
- An explanation for why the user is receiving this notification
MD
position = Gitlab::Diff::Position.new(
old_path: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb",
old_line: nil,
new_line: 14,
diff_refs: merge_request.diff_refs
)
create_note(noteable_type: 'merge_request', noteable_id: merge_request.id, type: 'DiffNote', position: position, note: note)
end
end
2023-05-27 22:25:52 +05:30
def access_token_created_email
Notify.access_token_created_email(user, 'token_name').message
end
def access_token_revoked_email
Notify.access_token_revoked_email(user, 'token_name').message
end
2021-04-17 20:07:23 +05:30
def new_mention_in_merge_request_email
2022-10-11 01:57:18 +05:30
Notify.new_mention_in_merge_request_email(user.id, merge_request.id, user.id).message
2021-04-17 20:07:23 +05:30
end
2018-05-09 12:01:36 +05:30
def closed_issue_email
Notify.closed_issue_email(user.id, issue.id, user.id).message
end
def issue_status_changed_email
Notify.issue_status_changed_email(user.id, issue.id, 'closed', user.id).message
end
2018-12-13 13:39:08 +05:30
def removed_milestone_issue_email
Notify.removed_milestone_issue_email(user.id, issue.id, user.id)
end
def changed_milestone_issue_email
Notify.changed_milestone_issue_email(user.id, issue.id, milestone, user.id)
end
2019-02-15 15:39:39 +05:30
def import_issues_csv_email
2019-12-26 22:10:19 +05:30
Notify.import_issues_csv_email(user.id, project.id, { success: 3, errors: [5, 6, 7], valid_file: true })
2019-02-15 15:39:39 +05:30
end
2023-05-27 22:25:52 +05:30
def import_work_items_csv_email
Notify.import_work_items_csv_email(user.id, project.id, { success: 4, error_lines: [2, 3, 4], parse_error: false })
end
2020-04-22 19:07:51 +05:30
def issues_csv_email
Notify.issues_csv_email(user, project, '1997,Ford,E350', { truncated: false, rows_expected: 3, rows_written: 3 }).message
end
2021-06-08 01:23:25 +05:30
def new_issue_email
Notify.new_issue_email(user.id, issue.id).message
end
2021-04-17 20:07:23 +05:30
def new_merge_request_email
Notify.new_merge_request_email(user.id, merge_request.id).message
end
2018-05-09 12:01:36 +05:30
def closed_merge_request_email
2022-10-11 01:57:18 +05:30
Notify.closed_merge_request_email(user.id, merge_request.id, user.id).message
2018-05-09 12:01:36 +05:30
end
def merge_request_status_email
2021-04-17 20:07:23 +05:30
Notify.merge_request_status_email(user.id, merge_request.id, 'reopened', user.id).message
end
def merge_request_unmergeable_email
Notify.merge_request_unmergeable_email(user.id, merge_request.id, 'conflict').message
2018-05-09 12:01:36 +05:30
end
def merged_merge_request_email
Notify.merged_merge_request_email(user.id, merge_request.id, user.id).message
end
2018-12-13 13:39:08 +05:30
def removed_milestone_merge_request_email
Notify.removed_milestone_merge_request_email(user.id, merge_request.id, user.id)
end
def changed_milestone_merge_request_email
Notify.changed_milestone_merge_request_email(user.id, merge_request.id, milestone, user.id)
end
2018-05-09 12:01:36 +05:30
def member_access_denied_email
Notify.member_access_denied_email('project', project.id, user.id).message
end
def member_access_granted_email
2019-10-12 21:52:04 +05:30
Notify.member_access_granted_email(member.source_type, member.id).message
2018-05-09 12:01:36 +05:30
end
def member_access_requested_email
2019-12-26 22:10:19 +05:30
Notify.member_access_requested_email(member.source_type, member.id, user.id).message
2018-05-09 12:01:36 +05:30
end
def member_invite_accepted_email
2019-12-26 22:10:19 +05:30
Notify.member_invite_accepted_email(member.source_type, member.id).message
2018-05-09 12:01:36 +05:30
end
def member_invite_declined_email
Notify.member_invite_declined_email(
'project',
project.id,
'invite@example.com',
user.id
).message
end
def member_invited_email
2021-09-04 01:27:46 +05:30
Notify.member_invited_email('project', member.id, '1234').message
2018-05-09 12:01:36 +05:30
end
def pages_domain_enabled_email
cleanup do
pages_domain = PagesDomain.new(domain: 'my.example.com', project: project, verified_at: Time.now, enabled_until: 1.week.from_now)
Notify.pages_domain_enabled_email(pages_domain, user).message
end
end
def pipeline_success_email
Notify.pipeline_success_email(pipeline, pipeline.user.try(:email))
end
def pipeline_failed_email
Notify.pipeline_failed_email(pipeline, pipeline.user.try(:email))
end
2020-04-08 14:13:33 +05:30
def pipeline_fixed_email
Notify.pipeline_fixed_email(pipeline, pipeline.user.try(:email))
end
2018-11-20 20:47:30 +05:30
def autodevops_disabled_email
Notify.autodevops_disabled_email(pipeline, user.email).message
end
2019-02-15 15:39:39 +05:30
def remote_mirror_update_failed_email
Notify.remote_mirror_update_failed_email(remote_mirror.id, user.id).message
end
2020-05-24 23:13:21 +05:30
def unknown_sign_in_email
2020-06-23 00:09:42 +05:30
Notify.unknown_sign_in_email(user, '127.0.0.1', Time.current).message
2020-05-24 23:13:21 +05:30
end
2022-11-25 23:54:43 +05:30
def two_factor_otp_attempt_failed_email
Notify.two_factor_otp_attempt_failed_email(user, '127.0.0.1').message
end
2022-06-21 17:19:12 +05:30
def new_email_address_added_email
Notify.new_email_address_added_email(user, 'someone@gitlab.com').message
end
2020-07-28 23:09:34 +05:30
def service_desk_new_note_email
cleanup do
note = create_note(noteable_type: 'Issue', noteable_id: issue.id, note: 'Issue note content')
2021-04-17 20:07:23 +05:30
Notify.service_desk_new_note_email(issue.id, note.id, 'someone@gitlab.com').message
2020-07-28 23:09:34 +05:30
end
end
def service_desk_thank_you_email
Notify.service_desk_thank_you_email(issue.id).message
end
2023-06-20 00:43:36 +05:30
def service_desk_custom_email_verification_email
cleanup do
setup_service_desk_custom_email_objects
Notify.service_desk_custom_email_verification_email(service_desk_setting).message
end
end
def service_desk_verification_triggered_email
cleanup do
setup_service_desk_custom_email_objects
Notify.service_desk_verification_triggered_email(service_desk_setting, 'owner@example.com').message
end
end
def service_desk_verification_result_email_for_verified_state
cleanup do
setup_service_desk_custom_email_objects
custom_email_verification.update!(state: 1)
Notify.service_desk_verification_result_email(service_desk_setting, 'owner@example.com').message
end
end
def service_desk_verification_result_email_for_incorrect_token_error
service_desk_verification_result_email_for_error_state(error: :incorrect_token)
end
def service_desk_verification_result_email_for_incorrect_from_error
service_desk_verification_result_email_for_error_state(error: :incorrect_from)
end
def service_desk_verification_result_email_for_mail_not_received_within_timeframe_error
service_desk_verification_result_email_for_error_state(error: :mail_not_received_within_timeframe)
end
def service_desk_verification_result_email_for_invalid_credentials_error
service_desk_verification_result_email_for_error_state(error: :invalid_credentials)
end
def service_desk_verification_result_email_for_smtp_host_issue_error
service_desk_verification_result_email_for_error_state(error: :smtp_host_issue)
end
2020-07-28 23:09:34 +05:30
def merge_when_pipeline_succeeds_email
Notify.merge_when_pipeline_succeeds_email(user.id, merge_request.id, user.id).message
end
2022-07-16 23:28:13 +05:30
def inactive_project_deletion_warning
Notify.inactive_project_deletion_warning_email(project, user, '2022-04-22').message
end
2022-08-13 15:12:31 +05:30
def verification_instructions_email
2023-01-13 00:05:48 +05:30
Notify.verification_instructions_email(user.email, token: '123456').message
2022-08-13 15:12:31 +05:30
end
2022-11-25 23:54:43 +05:30
def project_was_exported_email
Notify.project_was_exported_email(user, project).message
end
def request_review_merge_request_email
Notify.request_review_merge_request_email(user.id, merge_request.id, user.id).message
end
def project_was_moved_email
Notify.project_was_moved_email(project.id, user.id, "gitlab/gitlab").message
end
2023-03-17 16:20:25 +05:30
def github_gists_import_errors_email
Notify.github_gists_import_errors_email(user.id, { '12345' => 'Snippet maximum file count exceeded', '67890' => 'error message 2' }).message
end
2017-08-17 22:00:37 +05:30
private
def project
2022-10-11 01:57:18 +05:30
@project ||= Project.first
2017-08-17 22:00:37 +05:30
end
2023-06-20 00:43:36 +05:30
def service_desk_verification_result_email_for_error_state(error:)
cleanup do
setup_service_desk_custom_email_objects
custom_email_verification.update!(state: 2, error: error)
Notify.service_desk_verification_result_email(service_desk_setting, 'owner@example.com').message
end
end
def setup_service_desk_custom_email_objects
# Call accessors to ensure objects have been created
custom_email_credential
custom_email_verification
# Update associations in projects, because we access
# custom_email_credential and custom_email_verification via project
project.reset
end
def custom_email_verification
@custom_email_verification ||= project.service_desk_custom_email_verification || ServiceDesk::CustomEmailVerification.create!(
project: project,
token: 'XXXXXXXXXXXX',
triggerer: user,
triggered_at: Time.current,
state: 0
)
end
def custom_email_credential
@custom_email_credential ||= project.service_desk_custom_email_credential || ServiceDesk::CustomEmailCredential.create!(
project: project,
smtp_address: 'smtp.gmail.com', # Use gmail, because Gitlab::UrlBlocker resolves DNS
smtp_port: 587,
smtp_username: 'user@gmail.com',
smtp_password: 'supersecret'
)
end
def service_desk_setting
@service_desk_setting ||= project.service_desk_setting || ServiceDeskSetting.create!(
project: project,
custom_email: 'user@gmail.com'
)
end
2018-05-09 12:01:36 +05:30
def issue
2021-06-08 01:23:25 +05:30
@issue ||= project.issues.first
2018-05-09 12:01:36 +05:30
end
2017-08-17 22:00:37 +05:30
def merge_request
2018-05-09 12:01:36 +05:30
@merge_request ||= project.merge_requests.first
end
2018-12-13 13:39:08 +05:30
def milestone
@milestone ||= issue.milestone
end
2018-05-09 12:01:36 +05:30
def pipeline
@pipeline = Ci::Pipeline.last
2017-08-17 22:00:37 +05:30
end
2019-02-15 15:39:39 +05:30
def remote_mirror
@remote_mirror ||= RemoteMirror.last
end
2017-08-17 22:00:37 +05:30
def user
@user ||= User.last
end
2022-08-13 15:12:31 +05:30
def group
@group ||= Group.last
end
2019-10-12 21:52:04 +05:30
def member
@member ||= Member.last
end
2017-08-17 22:00:37 +05:30
def create_note(params)
Notes::CreateService.new(project, user, params).execute
end
def note_email(method)
cleanup do
note = yield
2018-11-08 19:23:39 +05:30
Notify.public_send(method, user.id, note) # rubocop:disable GitlabSecurity/PublicSend
2017-08-17 22:00:37 +05:30
end
end
def cleanup
email = nil
2022-03-02 08:16:31 +05:30
ApplicationRecord.transaction do
2017-08-17 22:00:37 +05:30
email = yield
raise ActiveRecord::Rollback
end
email
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
NotifyPreview.prepend_mod_with('Preview::NotifyPreview')