diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index 0ff0e23..b2cc6a4 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -5,14 +5,14 @@ def show end def accept - # find invitation by token - # invitation.accept - # redirect to invitation.html_url + @invitation = Invitation.find_by_token(params[:token]) + invitation.accept! + redirect_to invitation_path(@invitation.token) end def reject - # find invitation by token - # invitation.reject - # redirect back invitation.html_url + @invitation = Invitation.find_by_token(params[:token]) + invitation.reject! + redirect_to invitation_path(@invitation.token) end end \ No newline at end of file diff --git a/app/models/invitation.rb b/app/models/invitation.rb index 619a09e..c6944d0 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -13,15 +13,45 @@ def generate_token end end - def accept - update!(accepted_at: Time.zone.now) + def decline_deadline + project_allocation.decline_deadline end - def reject - update!(rejected_at: Time.zone.now) + def expired? + Time.zone.now > decline_deadline + end + + def accept! + return if expired? + update!(accepted_at: Time.zone.now, rejected_at: nil) + project_allocation.accept_funding! + end + + def reject! + return if expired? + update!(rejected_at: Time.zone.now, accepted_at: nil) project_allocation.reject_funding! end + def accepted? + accepted_at.present? + end + + def rejected? + rejected_at.present? + end + + def send_email + MaintainerMailer.invitation_email( + project.contact_email, + project.to_s, + funder_names, + "$#{amount_cents / 100.0}", + "https://example.com/invite", + decline_deadline.strftime("%B %d, %Y") + ).deliver_now + end + def html_url "https://staging.opencollective.com/#{ENV['OPENCOLLECTIVE_PARENT_SLUG']}/projects/#{project_allocation.fund.oc_project_slug}/expenses/#{member_invitation_id}" end diff --git a/app/models/project_allocation.rb b/app/models/project_allocation.rb index 3bfb11f..e5052c5 100644 --- a/app/models/project_allocation.rb +++ b/app/models/project_allocation.rb @@ -341,18 +341,16 @@ def decline_deadline created_at + 14.days end - def send_invitation_email - MaintainerMailer.invitation_email( - project.contact_email, - project.to_s, - funder_names, - "$#{amount_cents / 100.0}", - "https://example.com/invite", - decline_deadline.strftime("%B %d, %Y") - ) + def send_invitation + # create invitation record + # send email end def reject_funding! project.update!(funding_rejected: true) end + + def accept_funding! + project.update!(funding_rejected: false) + end end diff --git a/app/views/invitations/show.html.erb b/app/views/invitations/show.html.erb index 10b938a..13059d5 100644 --- a/app/views/invitations/show.html.erb +++ b/app/views/invitations/show.html.erb @@ -1,9 +1,17 @@

Accept or reject the invitation!

-

Accept confirmation button

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

or they can update their funding.yml and we'll check it again

+

This invitation has expired

-

also an option to reject

+<% else %> -

if it's been accepted/rejected already then show a message

\ No newline at end of file +

Accept confirmation button

+ +

or they can update their funding.yml and we'll check it again

+ +

also an option to reject

+ +

if it's been accepted/rejected already then show a message

+ +<% end %> \ No newline at end of file