mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-12 12:50:53 +00:00
Made System send a message to opposing team on proposal creation, created a clean migration for match_proposals table
This commit is contained in:
parent
4435f7f5e6
commit
fa68d2ef06
7 changed files with 35 additions and 18 deletions
|
@ -24,8 +24,17 @@ class MatchProposalsController < ApplicationController
|
||||||
raise AccessError unless @proposal.can_create? cuser
|
raise AccessError unless @proposal.can_create? cuser
|
||||||
@proposal.team = cuser.team
|
@proposal.team = cuser.team
|
||||||
@proposal.status = MatchProposal::STATUS_PENDING
|
@proposal.status = MatchProposal::STATUS_PENDING
|
||||||
|
|
||||||
if @proposal.save
|
if @proposal.save
|
||||||
|
# TODO: send message to teamleaders of opposite team
|
||||||
|
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 = "There is a new scheduling proposal for your match against #{recipient.name}.\n" \
|
||||||
|
"Find it [url=#{match_proposals_path(@match)}]here[/url]"
|
||||||
|
msg.save
|
||||||
flash[:notice] = 'Created new proposal'
|
flash[:notice] = 'Created new proposal'
|
||||||
redirect_to(match_proposals_path(@match))
|
redirect_to(match_proposals_path(@match))
|
||||||
else
|
else
|
||||||
|
@ -51,8 +60,10 @@ class MatchProposalsController < ApplicationController
|
||||||
}
|
}
|
||||||
render(json: rjson, status: :forbidden) && return
|
render(json: rjson, status: :forbidden) && return
|
||||||
end
|
end
|
||||||
|
send_msg = proposal.status != params[:match_proposal][:status]
|
||||||
proposal.status = params[:match_proposal][:status]
|
proposal.status = params[:match_proposal][:status]
|
||||||
if proposal.save
|
if proposal.save
|
||||||
|
# TODO: send message to opposite team leaders if send_msg
|
||||||
rjson[:status] = MatchProposal.status_strings[proposal.status]
|
rjson[:status] = MatchProposal.status_strings[proposal.status]
|
||||||
rjson[:message] = "Successfully updated status to #{MatchProposal.status_strings[proposal.status]}"
|
rjson[:message] = "Successfully updated status to #{MatchProposal.status_strings[proposal.status]}"
|
||||||
render(json: rjson, status: :accepted)
|
render(json: rjson, status: :accepted)
|
||||||
|
|
|
@ -189,6 +189,11 @@ class Match < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_opposing_team(team)
|
||||||
|
team == contester1.team ? contester2.team : contester1.team
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def set_hltv
|
def set_hltv
|
||||||
get_hltv if match_time.future?
|
get_hltv if match_time.future?
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,11 +44,15 @@ class Message < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def thread
|
def thread
|
||||||
Message.find_by_sql ["
|
if sender_type == 'System'
|
||||||
|
Message.where(recipient_id: recipient.id, sender_type: 'System')
|
||||||
|
else
|
||||||
|
Message.find_by_sql ["
|
||||||
(SELECT `messages`.* FROM `messages` WHERE `messages`.`sender_id` = ? AND `messages`.`sender_type` = 'User' AND `messages`.`recipient_id` = ?)
|
(SELECT `messages`.* FROM `messages` WHERE `messages`.`sender_id` = ? AND `messages`.`sender_type` = 'User' AND `messages`.`recipient_id` = ?)
|
||||||
UNION
|
UNION
|
||||||
(SELECT `messages`.* FROM `messages` WHERE `messages`.`sender_id` = ? AND `messages`.`sender_type` = 'User' AND `messages`.`recipient_id` = ?)
|
(SELECT `messages`.* FROM `messages` WHERE `messages`.`sender_id` = ? AND `messages`.`sender_type` = 'User' AND `messages`.`recipient_id` = ?)
|
||||||
ORDER BY id", sender.id, recipient.id, recipient.id, sender.id]
|
ORDER BY id", sender.id, recipient.id, recipient.id, sender.id]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_text
|
def parse_text
|
||||||
|
|
|
@ -5,5 +5,5 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
To: <%= namelink message.recipient %> From: <%= namelink message.sender %> on <em><%= longdate message.created_at %></em></em>
|
To: <%= namelink message.recipient %> From: <% if message.sender_type == 'System' %>System<% else %><%= namelink message.sender %><% end %> on <em><%= longdate message.created_at %></em></em>
|
||||||
</p>
|
</p>
|
|
@ -10,7 +10,7 @@
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<%= raw message.text_parsed %>
|
<%= raw message.text_parsed %>
|
||||||
</div>
|
</div>
|
||||||
<p>Sent by: <%= namelink message.sender %> on <%= shortdate message.created_at %></p>
|
<p>Sent by: <% if message.sender_type == 'System' %>System<% else %><%= namelink message.sender %><% end %> on <%= shortdate message.created_at %></p>
|
||||||
<p>
|
<p>
|
||||||
<%= link_to "Reply",
|
<%= link_to "Reply",
|
||||||
{ controller: "messages", action: "new", id: message.sender_type, id2: message.sender_id, title: message.title },
|
{ controller: "messages", action: "new", id: message.sender_type, id2: message.sender_id, title: message.title },
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
class CreateMatchProposals < ActiveRecord::Migration
|
class CreateMatchProposals < ActiveRecord::Migration
|
||||||
def change
|
def up
|
||||||
create_table :match_proposals do |t|
|
create_table :match_proposals do |t|
|
||||||
t.references :match
|
t.references :match, index: true, forign_key: true
|
||||||
t.references :team
|
t.references :team, forign_key: true
|
||||||
t.integer :status
|
|
||||||
t.datetime :proposed_time
|
t.datetime :proposed_time
|
||||||
|
t.integer :status
|
||||||
t.timestamps
|
|
||||||
end
|
end
|
||||||
add_index :match_proposals, :match_id
|
|
||||||
add_index :match_proposals, :team_id
|
add_index :match_proposals, :status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down; end
|
||||||
end
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20170702150454) do
|
ActiveRecord::Schema.define(:version => 20171013154050) do
|
||||||
|
|
||||||
create_table "admin_requests", :force => true do |t|
|
create_table "admin_requests", :force => true do |t|
|
||||||
t.string "addr"
|
t.string "addr"
|
||||||
|
@ -435,14 +435,11 @@ ActiveRecord::Schema.define(:version => 20170702150454) do
|
||||||
create_table "match_proposals", :force => true do |t|
|
create_table "match_proposals", :force => true do |t|
|
||||||
t.integer "match_id"
|
t.integer "match_id"
|
||||||
t.integer "team_id"
|
t.integer "team_id"
|
||||||
t.integer "status"
|
|
||||||
t.datetime "proposed_time"
|
t.datetime "proposed_time"
|
||||||
t.datetime "created_at", :null => false
|
t.integer "status"
|
||||||
t.datetime "updated_at", :null => false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "match_proposals", ["match_id"], :name => "index_match_proposals_on_match_id"
|
add_index "match_proposals", ["status"], :name => "index_match_proposals_on_status"
|
||||||
add_index "match_proposals", ["team_id"], :name => "index_match_proposals_on_team_id"
|
|
||||||
|
|
||||||
create_table "matchers", :force => true do |t|
|
create_table "matchers", :force => true do |t|
|
||||||
t.integer "match_id", :null => false
|
t.integer "match_id", :null => false
|
||||||
|
|
Loading…
Reference in a new issue