2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Members
|
2021-04-29 21:17:54 +05:30
|
|
|
class InviteService < Members::CreateService
|
|
|
|
extend ::Gitlab::Utils::Override
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
def initialize(*args)
|
|
|
|
super
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
@errors = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
alias_method :formatted_errors, :errors
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
def invites_from_params
|
|
|
|
params[:email]
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
def validate_invitable!
|
2021-04-29 21:17:54 +05:30
|
|
|
super
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
# we need the below due to add_users hitting Members::CreatorService.parse_users_list and ignoring invalid emails
|
2021-04-29 21:17:54 +05:30
|
|
|
# ideally we wouldn't need this, but we can't really change the add_users method
|
|
|
|
valid, invalid = invites.partition { |email| Member.valid_email?(email) }
|
|
|
|
@invites = valid
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
invalid.each { |email| errors[email] = s_('AddMember|Invite email is invalid') }
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
override :blank_invites_message
|
|
|
|
def blank_invites_message
|
|
|
|
s_('AddMember|Emails cannot be blank')
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
override :add_error_for_member
|
|
|
|
def add_error_for_member(member)
|
|
|
|
errors[invite_email(member)] = member.errors.full_messages.to_sentence
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
override :create_tasks_to_be_done
|
|
|
|
def create_tasks_to_be_done
|
|
|
|
# Only create task issues for existing users. Tasks for new users are created when they signup.
|
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
def invite_email(member)
|
|
|
|
member.invite_email || member.user.email
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|