-
-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathinvitations_controller.rb
More file actions
82 lines (63 loc) · 2.1 KB
/
invitations_controller.rb
File metadata and controls
82 lines (63 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class Admin::InvitationsController < Admin::ApplicationController
include Admin::WorkshopConcerns
def update
set_and_decorate_workshop
authorize @workshop
set_invitation
message = update_attendance(attending: params[:attending], attended: params[:attended])
if request.xhr?
set_admin_workshop_data
render partial: 'admin/workshops/invitation_management'
else
redirect_back fallback_location: root_path, notice: message
end
end
private
def update_attendance(attending:, attended:)
return update_to_attended if attended
result = attending.eql?('true') ? update_to_attending : update_to_not_attending
message, error = result.values_at(:message, :error)
unless error
waiting_listed = WaitingList.find_by(invitation: @invitation)
waiting_listed&.destroy
end
message
end
def update_to_attended
@invitation.update(attended: true)
"You have verified #{@invitation.member.full_name}’s attendace."
end
def update_to_attending
update_successful = @invitation.update(
attending: true,
rsvp_time: Time.zone.now,
automated_rsvp: true,
last_overridden_by_id: current_user.id
)
{
message: update_successful ? attending_successful : attending_failed,
error: !update_successful
}
end
def attending_successful
@workshop.send_attending_email(@invitation) if @workshop.future?
"You have added #{@invitation.member.full_name} to the workshop as a #{@invitation.role}."
end
def attending_failed
"Error adding #{@invitation.member.full_name} as a #{@invitation.role}. "\
"#{@invitation.errors.full_messages.to_sentence}."
end
def update_to_not_attending
@invitation.update!(attending: false, last_overridden_by_id: current_user.id)
{
message: "You have removed #{@invitation.member.full_name} from the workshop.",
error: false
}
end
def set_invitation
@invitation = @workshop.invitations.find_by!(token: invitation_id)
end
def invitation_id
params.key?(:workshop) ? params[:workshop][:invitations] : params[:id]
end
end