diff options
Diffstat (limited to 'app/models/project_services/emails_on_push_service.rb')
-rw-r--r-- | app/models/project_services/emails_on_push_service.rb | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/app/models/project_services/emails_on_push_service.rb b/app/models/project_services/emails_on_push_service.rb index 01d8647d439..cdb69684d16 100644 --- a/app/models/project_services/emails_on_push_service.rb +++ b/app/models/project_services/emails_on_push_service.rb @@ -3,10 +3,19 @@ class EmailsOnPushService < Service include NotificationBranchSelection + RECIPIENTS_LIMIT = 750 + boolean_accessor :send_from_committer_email boolean_accessor :disable_diffs prop_accessor :recipients, :branches_to_be_notified - validates :recipients, presence: true, if: :valid_recipients? + validates :recipients, presence: true, if: :validate_recipients? + validate :number_of_recipients_within_limit, if: :validate_recipients? + + def self.valid_recipients(recipients) + recipients.split.select do |recipient| + recipient.include?('@') + end.uniq(&:downcase) + end def title s_('EmailsOnPushService|Emails on push') @@ -63,11 +72,26 @@ class EmailsOnPushService < Service domains = Notify.allowed_email_domains.map { |domain| "user@#{domain}" }.join(", ") [ { type: 'checkbox', name: 'send_from_committer_email', title: s_("EmailsOnPushService|Send from committer"), - help: s_("EmailsOnPushService|Send notifications from the committer's email address if the domain is part of the domain GitLab is running on (e.g. %{domains}).") % { domains: domains } }, + help: s_("EmailsOnPushService|Send notifications from the committer's email address if the domain matches the domain used by your GitLab instance (such as %{domains}).") % { domains: domains } }, { type: 'checkbox', name: 'disable_diffs', title: s_("EmailsOnPushService|Disable code diffs"), help: s_("EmailsOnPushService|Don't include possibly sensitive code diffs in notification body.") }, { type: 'select', name: 'branches_to_be_notified', choices: branch_choices }, - { type: 'textarea', name: 'recipients', placeholder: s_('EmailsOnPushService|Emails separated by whitespace') } + { + type: 'textarea', + name: 'recipients', + placeholder: s_('EmailsOnPushService|tanuki@example.com gitlab@example.com'), + help: s_('EmailsOnPushService|Emails separated by whitespace.') + } ] end + + private + + def number_of_recipients_within_limit + return if recipients.blank? + + if self.class.valid_recipients(recipients).size > RECIPIENTS_LIMIT + errors.add(:recipients, s_("EmailsOnPushService|can't exceed %{recipients_limit}") % { recipients_limit: RECIPIENTS_LIMIT }) + end + end end |