mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-25 12:01:03 +00:00
Make System send a message to opposing team whenever state of an proposal changes, sent message is dependend on new state
This commit is contained in:
parent
fa68d2ef06
commit
e85cf3a18d
1 changed files with 35 additions and 3 deletions
|
@ -60,10 +60,23 @@ class MatchProposalsController < ApplicationController
|
|||
}
|
||||
render(json: rjson, status: :forbidden) && return
|
||||
end
|
||||
send_msg = proposal.status != params[:match_proposal][:status]
|
||||
proposal.status = params[:match_proposal][:status]
|
||||
new_status = params[:match_proposal][:status]
|
||||
curr_status = proposal.status
|
||||
status_updated = curr_status != new_status
|
||||
proposal.status = new_status
|
||||
if proposal.save
|
||||
# TODO: send message to opposite team leaders if send_msg
|
||||
|
||||
if status_updated
|
||||
msg = Message.new
|
||||
msg.sender_type = 'System'
|
||||
msg.recipient_type = 'Team'
|
||||
msg.title = 'New Scheduling Proposal'
|
||||
recipient = @match.get_opposing_team(cuser.team)
|
||||
msg.recipient = recipient
|
||||
msg.text = message_text(new_status)
|
||||
msg.save if msg.text
|
||||
end
|
||||
|
||||
rjson[:status] = MatchProposal.status_strings[proposal.status]
|
||||
rjson[:message] = "Successfully updated status to #{MatchProposal.status_strings[proposal.status]}"
|
||||
render(json: rjson, status: :accepted)
|
||||
|
@ -80,4 +93,23 @@ private
|
|||
def get_match
|
||||
@match = Match.find params[:match_id]
|
||||
end
|
||||
|
||||
def message_text(new_status)
|
||||
case new_status
|
||||
when MatchProposal::STATUS_CONFIRMED
|
||||
"A scheduling proposal for your match against #{recipient.name} was confirmed!.\n" \
|
||||
"Find it [url=#{match_proposals_path(@match)}]here[/url]"
|
||||
when MatchProposal::STATUS_REJECTED
|
||||
"A scheduling proposal for your match against #{recipient.name} was rejected!.\n" \
|
||||
"Find it [url=#{match_proposals_path(@match)}]here[/url]"
|
||||
when MatchProposal::STATUS_REVOKED
|
||||
"A scheduling proposal for your match against #{recipient.name} was revoked!.\n" \
|
||||
"Find it [url=#{match_proposals_path(@match)}]here[/url]"
|
||||
when MatchProposal::STATUS_DELAYED
|
||||
"Delaying for your match against #{recipient.name} was permitted!.\n" \
|
||||
"Schedule a new time as soon as possible [url=#{match_proposals_path(@match)}]here[/url]"
|
||||
else
|
||||
false # Should not happen as transition to any other state is not allowed
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue