Skip to content

Commit

Permalink
Enhance invitation handling: add development token generation, improv…
Browse files Browse the repository at this point in the history
…e email sending logic, and update show view layout
  • Loading branch information
andrew committed Nov 28, 2024
1 parent 275b4f6 commit 60349e8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
16 changes: 12 additions & 4 deletions app/controllers/invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
class InvitationsController < ApplicationController

def show
if Rails.env.development? && params[:token].blank?
# make a new invitation for development
@invitation = Invitation.create!(email: '[email protected]', project_allocation: ProjectAllocation.first)
redirect_to invitation_path(token: @invitation.token) and return
end
@invitation = Invitation.find_by_token(params[:token])
raise ActiveRecord::RecordNotFound unless @invitation
end

def accept
@invitation = Invitation.find_by_token(params[:token])
invitation.accept!
redirect_to invitation_path(@invitation.token)
raise ActiveRecord::RecordNotFound unless @invitation
@invitation.accept!
redirect_to invitation_path(token: @invitation.token)
end

def reject
@invitation = Invitation.find_by_token(params[:token])
invitation.reject!
redirect_to invitation_path(@invitation.token)
raise ActiveRecord::RecordNotFound unless @invitation
@invitation.reject!
redirect_to invitation_path(token: @invitation.token)
end
end
8 changes: 4 additions & 4 deletions app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def rejected?

def send_email
MaintainerMailer.invitation_email(
project.contact_email,
project.to_s,
funder_names,
"$#{amount_cents / 100.0}",
email,
project_allocation.project.to_s,
project_allocation.funder_names,
"$#{project_allocation.amount_cents / 100.0}",
"https://example.com/invite",
decline_deadline.strftime("%B %d, %Y")
).deliver_now
Expand Down
30 changes: 21 additions & 9 deletions app/views/invitations/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
<h1>Accept or reject the invitation!</h1>
<div class="container">
<div class="row">
<div class="col-lg-8 page-content">
<h1 class="page-content__title display-2">Accept or reject the invitation!</h1>

<% if @invitation.expired? %>
<% if @invitation.expired? %>

<p>This invitation has expired</p>
<p>This invitation has expired</p>

<% else %>
<% else %>

<p>Accept confirmation button</p>
<% if @invitation.accepted? %>
<p>This invitation has already been accepted</p>
<% end %>

<p>or they can update their funding.yml and we'll check it again</p>
<% if @invitation.rejected? %>
<p>This invitation has already been rejected</p>
<% end %>

<p>also an option to reject</p>
<%= button_to 'Accept Invitation', accept_invitation_path(token: @invitation.token) %>

<p>if it's been accepted/rejected already then show a message</p>
<p>or they can update their funding.yml and we'll check it again</p>

<% end %>
<%= button_to 'Reject Invitation', reject_invitation_path(token: @invitation.token) %>

<% end %>
</div>
</div>
</div>
7 changes: 7 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
resources :projects, only: [:index]
end

resource :invitation do
member do
post :accept
post :reject
end
end

resources :funding_sources, only: [:index, :show]

resources :projects, only: [:show]
Expand Down

0 comments on commit 60349e8

Please sign in to comment.