Created
July 27, 2016 00:50
-
-
Save anonymous/b590f628918fa474d64ef749fe3e11ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def notify_invitee | |
if to_internal_user? | |
UserMailer.delay.new_connexion(self) | |
else | |
UserMailer.delay.new_external_user_connexion(self) | |
end | |
end | |
// this is the model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_connexion_request | |
@error = true | |
@patient = false | |
@patient = (Patient.find_by_email(params[:connexion_request][:email].downcase) || false) if params[:connexion_request].has_key?(:email) | |
# request to existent patient user | |
if @patient | |
@connexion_request = @user.connexion_requests.new(params[:connexion_request]) | |
# check if connexion exists? | |
if (connexion_exists = @user.connexions.where(patient_id: @patient).exists?) | |
flash[:alert] = "Já existe uma ligação com #{@patient.name}." | |
# check if request exists? | |
elsif (request_exists = ConnexionRequest.accepted_or_pending_request_exists?(@user, @patient)) | |
flash[:alert] = "Já existe um pedido de ligação pendente ou aceite com #{@patient.name}." | |
# this request does not exists, is not accepted or pending, or connexion doesn't exist yet | |
else | |
@connexion_request.invitee = @patient | |
@connexion_request.status = 0 | |
if @connexion_request.save | |
flash[:notice] = t(:connexion_successfully_created, name: @connexion_request.invitee.name) | |
else | |
return | |
end | |
end | |
# request by email | |
elsif params[:connexion_request].has_key?(:email) | |
email = params[:connexion_request][:email].downcase | |
unlocked_params = ActiveSupport::HashWithIndifferentAccess.new(params[:connexion_request]) | |
@connexion_request = @user.connexion_requests.new(unlocked_params) | |
# check if request exists? | |
if (request_exists = ConnexionRequest.accepted_or_pending_request_exists?(@user, email, true)) | |
flash[:alert] = "Já existe um pedido de ligação pendente para o email #{email}." | |
# this request does not exists, is not accepted or pending, or connexion doesn't exist yet | |
else | |
@connexion_request.status = 0 | |
if @connexion_request.save | |
flash[:notice] = t(:connexion_successfully_created, name: "#{@connexion_request.name} #{@connexion_request.email}") | |
else | |
return | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jaeku:~/workspace/bc (new_release) $ rake jobs:work | |
[Worker(host:jaeku-jaeku-site-2612732 pid:1217)] Starting job worker | |
[Worker(host:jaeku-jaeku-site-2612732 pid:1217)] Job Delayed::PerformableMailer (id=6) RUNNING | |
[Worker(host:jaeku-jaeku-site-2612732 pid:1217)] Job Delayed::PerformableMailer (id=7) RUNNING | |
[Worker(host:jaeku-jaeku-site-2612732 pid:1217)] Job UserMailer.new_external_user_connexion (id=8) RUNNING | |
[Worker(host:jaeku-jaeku-site-2612732 pid:1217)] Job UserMailer.new_external_user_connexion (id=8) COMPLETED after 1.0627 | |
[Worker(host:jaeku-jaeku-site-2612732 pid:1217)] 1 jobs processed at 0.8808 j/s, 0 failed | |
// this is when i run the delayed_job server to process jobs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def new_external_user_connexion(connexion_request) | |
#email_category "New external user connexion request" | |
@connexion_request = connexion_request | |
@from = @connexion_request.origined | |
@to_name = @connexion_request.name.present? ? @connexion_request.name : false | |
@to_email = @connexion_request.email | |
@email_title = t('mailer.connexion.subject.new_external', name: @from.name, product: PRODUCT_NAME) | |
mail(:from => "#{@from.name} <no-reply@#{DOMAIN}>", :to => "#{@to_email}", :subject => @email_title) | |
end | |
// the user mailer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment