2016-06-02 10:14:02 -04:00
|
|
|
module Emails
|
|
|
|
module Members
|
|
|
|
extend ActiveSupport::Concern
|
2016-06-02 12:05:06 -04:00
|
|
|
include MembersHelper
|
2016-06-02 10:14:02 -04:00
|
|
|
|
|
|
|
included do
|
2016-06-02 12:05:06 -04:00
|
|
|
helper_method :member_source, :member
|
2016-06-02 10:14:02 -04:00
|
|
|
end
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
def member_access_requested_email(member_source_type, member_id)
|
|
|
|
@member_source_type = member_source_type
|
2016-06-02 10:14:02 -04:00
|
|
|
@member_id = member_id
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
admins = member_source.members.owners_and_masters.includes(:user).pluck(:notification_email)
|
2016-06-20 06:10:37 -04:00
|
|
|
# A project in a group can have no explicit owners/masters, in that case
|
|
|
|
# we fallbacks to the group's owners/masters.
|
|
|
|
if admins.empty? && member_source.respond_to?(:group) && member_source.group
|
|
|
|
admins = member_source.group.members.owners_and_masters.includes(:user).pluck(:notification_email)
|
|
|
|
end
|
2016-06-02 10:14:02 -04:00
|
|
|
|
|
|
|
mail(to: admins,
|
2016-06-02 12:05:06 -04:00
|
|
|
subject: subject("Request to join the #{member_source.human_name} #{member_source.model_name.singular}"))
|
2016-06-02 10:14:02 -04:00
|
|
|
end
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
def member_access_granted_email(member_source_type, member_id)
|
|
|
|
@member_source_type = member_source_type
|
2016-06-02 10:14:02 -04:00
|
|
|
@member_id = member_id
|
|
|
|
|
|
|
|
mail(to: member.user.notification_email,
|
2016-06-02 12:05:06 -04:00
|
|
|
subject: subject("Access to the #{member_source.human_name} #{member_source.model_name.singular} was granted"))
|
2016-06-02 10:14:02 -04:00
|
|
|
end
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
def member_access_denied_email(member_source_type, source_id, user_id)
|
|
|
|
@member_source_type = member_source_type
|
|
|
|
@member_source = member_source_class.find(source_id)
|
|
|
|
requester = User.find(user_id)
|
2016-06-02 10:14:02 -04:00
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
mail(to: requester.notification_email,
|
|
|
|
subject: subject("Access to the #{member_source.human_name} #{member_source.model_name.singular} was denied"))
|
2016-06-02 10:14:02 -04:00
|
|
|
end
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
def member_invited_email(member_source_type, member_id, token)
|
|
|
|
@member_source_type = member_source_type
|
2016-06-02 10:14:02 -04:00
|
|
|
@member_id = member_id
|
|
|
|
@token = token
|
|
|
|
|
|
|
|
mail(to: member.invite_email,
|
2016-09-29 04:09:47 -04:00
|
|
|
subject: subject("Invitation to join the #{member_source.human_name} #{member_source.model_name.singular}"))
|
2016-06-02 10:14:02 -04:00
|
|
|
end
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
def member_invite_accepted_email(member_source_type, member_id)
|
|
|
|
@member_source_type = member_source_type
|
2016-06-02 10:14:02 -04:00
|
|
|
@member_id = member_id
|
2016-06-02 12:05:06 -04:00
|
|
|
return unless member.created_by
|
2016-06-02 10:14:02 -04:00
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
mail(to: member.created_by.notification_email,
|
2016-06-02 10:14:02 -04:00
|
|
|
subject: subject('Invitation accepted'))
|
|
|
|
end
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
def member_invite_declined_email(member_source_type, source_id, invite_email, created_by_id)
|
|
|
|
return unless created_by_id
|
2016-06-02 10:14:02 -04:00
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
@member_source_type = member_source_type
|
|
|
|
@member_source = member_source_class.find(source_id)
|
2016-06-02 10:14:02 -04:00
|
|
|
@invite_email = invite_email
|
2016-06-02 12:05:06 -04:00
|
|
|
inviter = User.find(created_by_id)
|
2016-06-02 10:14:02 -04:00
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
mail(to: inviter.notification_email,
|
2016-06-02 10:14:02 -04:00
|
|
|
subject: subject('Invitation declined'))
|
|
|
|
end
|
|
|
|
|
|
|
|
def member
|
2016-06-02 12:05:06 -04:00
|
|
|
@member ||= Member.find(@member_id)
|
2016-06-02 10:14:02 -04:00
|
|
|
end
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
def member_source
|
|
|
|
@member_source ||= member.source
|
2016-06-02 10:14:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
def member_source_class
|
|
|
|
@member_source_type.classify.constantize
|
2016-06-02 10:14:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|