Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notifications when a proposal is finalized. #212

Merged
merged 1 commit into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ def index
}
end

def finalized_notification
@proposal = proposal # because drapper won't set the instance variable

email_template = case @proposal.state
when Proposal::State::ACCEPTED
'accept_email'
when Proposal::State::REJECTED
'reject_email'
when Proposal::State::WAITLISTED
'waitlist_email'
end

markdown_string = render_to_string "staff/proposal_mailer/#{email_template}", layout: false, formats: :md

@body = Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(markdown_string)
end

def new
if @event.closed?
redirect_to event_path (@event)
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/staff/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def finalize

if @proposal.finalize
Staff::ProposalMailer.send_email(@proposal).deliver_now
@proposal.speakers.map(&:user).each do |user|
Notification.create_for(user, proposal: @proposal,
message: "Your proposal for #{@proposal.event.name} has been #{@proposal.state}",
target_path: finalized_notification_event_proposal_url(@proposal.event, @proposal))
end
else
flash[:danger] = "There was a problem finalizing the proposal: #{@proposal.errors.full_messages.join(', ')}"
end
Expand Down
4 changes: 3 additions & 1 deletion app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class Notification < ApplicationRecord

def self.create_for(user, args = {})
proposal = args.delete(:proposal)
args[:target_path] = user.decorate.proposal_notification_url(proposal) if proposal
if proposal && args[:target_path].blank?
args[:target_path] = user.decorate.proposal_notification_url(proposal)
end
user.notifications.create(args)
end

Expand Down
1 change: 1 addition & 0 deletions app/views/proposals/finalized_notification.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= @body.html_safe %>
10 changes: 5 additions & 5 deletions app/views/staff/proposal_mailer/accept_email.md.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<% if @event.accept.present? %>
<%= Staff::ProposalMailerTemplate.new(@event.accept, @event, @proposal).render %>
<% else %>
Congratulations! We'd love to include your talk, <%= @proposal.title %>, at <%= @event.name %>.
Congratulations! We'd love to include your talk, <%= @proposal.title %>, at <%= @event.name %>.

TO CONFIRM that you're still willing and able to present this talk, please visit the <%= @proposal.confirm_link %> .
TO CONFIRM that you're still willing and able to present this talk, please visit the <%= @proposal.confirm_link %> .

TO DECLINE (if you're no longer able to give this talk), please visit the <%= @proposal.confirm_link %>, and click the 'Decline' button.
TO DECLINE (if you're no longer able to give this talk), please visit the <%= @proposal.confirm_link %>, and click the 'Decline' button.

In the meantime, let us know if you have any questions. We're looking forward to seeing you there!
In the meantime, let us know if you have any questions. We're looking forward to seeing you there!

The <%= @event.name %> Program Committee
The <%= @event.name %> Program Committee

<% end %>
8 changes: 4 additions & 4 deletions app/views/staff/proposal_mailer/reject_email.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<%= Staff::ProposalMailerTemplate.new(@event.reject, @event,
@proposal, [ :proposal_title ]).render %>
<% else %>
Thank you for your proposal to <%= @event.name %>. Our program committee received many great talk submissions this year, and that's allowed us to put together an exciting program.
Thank you for your proposal to <%= @event.name %>. Our program committee received many great talk submissions this year, and that's allowed us to put together an exciting program.

As a result of the number of talks submitted, however, we've had to turn down a lot of excellent proposals. I'm sorry to say that we were not able to accept your submission titled, <%= @proposal.title %>, this year. This is always the toughest part knowing that we simply can't fit all the good talks in. We hope that you'll still be able to attend the conference.
As a result of the number of talks submitted, however, we've had to turn down a lot of excellent proposals. I'm sorry to say that we were not able to accept your submission titled, <%= @proposal.title %>, this year. This is always the toughest part knowing that we simply can't fit all the good talks in. We hope that you'll still be able to attend the conference.

Thanks again for your submission as we really appreciate your willingness to share with the community.
Thanks again for your submission as we really appreciate your willingness to share with the community.

The <%= @event.name %> Program Committee
The <%= @event.name %> Program Committee

<% end %>
10 changes: 5 additions & 5 deletions app/views/staff/proposal_mailer/waitlist_email.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<%= Staff::ProposalMailerTemplate.new(@event.waitlist, @event, @proposal).render %>
<% else %>

We have good news and bad news. We'll start with the bad news. We weren't able to fit your talk, <%= @proposal.title %>, into the program for <%= @event.name %>. The good news is that we have you on our waitlist. We keep a waitlist of talks that are ready to step in if any of the accepted talks back out or get sick.
We have good news and bad news. We'll start with the bad news. We weren't able to fit your talk, <%= @proposal.title %>, into the program for <%= @event.name %>. The good news is that we have you on our waitlist. We keep a waitlist of talks that are ready to step in if any of the accepted talks back out or get sick.

If you are willing to be a waitlisted speaker then you need to CONFIRM by visiting the <%= @proposal.confirm_link %>.
If you are willing to be a waitlisted speaker then you need to CONFIRM by visiting the <%= @proposal.confirm_link %>.

TO DECLINE: if you are not interested in being a waitlisted speaker, please visit the <%= @proposal.confirm_link %>, and click the 'Decline' button.
TO DECLINE: if you are not interested in being a waitlisted speaker, please visit the <%= @proposal.confirm_link %>, and click the 'Decline' button.

In the meantime, let us know if you have any questions. We're looking forward to seeing you!
In the meantime, let us know if you have any questions. We're looking forward to seeing you!

The <%= @event.name %> Program Committee
The <%= @event.name %> Program Committee

<% end %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
member { post :decline }
member { post :update_notes }
member { delete :destroy }
member { get :finalized_notification }
end

get 'parse_edit_field' => 'proposals#parse_edit_field', as: :parse_edit_field_proposal
Expand Down