summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <shumakl@purdue.edu>2014-04-30 15:38:26 -0400
committerLuke Shumaker <shumakl@purdue.edu>2014-04-30 15:38:26 -0400
commit47bb545740937d50b72e0d1c420fcba4e64d6760 (patch)
tree886e361d01b1cdab7d3e8afed40eb76c6791ddfb
parentf1b2a1f25b839237ff1791ffc4586bc466409874 (diff)
Add #owned_by? to the models that didn't have it (when appropriate)
-rw-r--r--app/models/bracket_match.rb4
-rw-r--r--app/models/match.rb4
-rw-r--r--app/models/pm.rb4
-rw-r--r--app/models/remote_username.rb4
-rw-r--r--app/models/tournament_setting.rb4
-rw-r--r--app/models/tournament_stage.rb4
-rw-r--r--app/views/matches/index.html.erb3
7 files changed, 24 insertions, 3 deletions
diff --git a/app/models/bracket_match.rb b/app/models/bracket_match.rb
index f9a11f0..14a8002 100644
--- a/app/models/bracket_match.rb
+++ b/app/models/bracket_match.rb
@@ -3,5 +3,7 @@ class BracketMatch < ActiveRecord::Base
belongs_to :match
belongs_to :predicted_winner, class_name: "Team"
-
+ def owned_by?(user)
+ self.bracket.owned_by?(user)
+ end
end
diff --git a/app/models/match.rb b/app/models/match.rb
index ed21f78..f1c32fe 100644
--- a/app/models/match.rb
+++ b/app/models/match.rb
@@ -14,6 +14,10 @@ class Match < ActiveRecord::Base
# winner:references
# not validated
+ def owned_by?(user)
+ self.tournament_stage.owned_by?(user)
+ end
+
##
# Returns whether or not all the statistics have been collected
# such that the match may be considered finished.
diff --git a/app/models/pm.rb b/app/models/pm.rb
index 8b06181..3d14149 100644
--- a/app/models/pm.rb
+++ b/app/models/pm.rb
@@ -7,6 +7,10 @@ class Pm < ActiveRecord::Base
return current_user.name
end
+ def owned_by?(user)
+ self.author == user
+ end
+
=begin
def mailboxer_email(email)
return current_user.email
diff --git a/app/models/remote_username.rb b/app/models/remote_username.rb
index c863ede..23dc0a8 100644
--- a/app/models/remote_username.rb
+++ b/app/models/remote_username.rb
@@ -2,6 +2,10 @@ class RemoteUsername < ActiveRecord::Base
belongs_to :game
belongs_to :user
+ def owned_by?(tuser)
+ self.user == tuser
+ end
+
def value
begin
return JSON::restore(self.json_value)
diff --git a/app/models/tournament_setting.rb b/app/models/tournament_setting.rb
index 20d9842..48c607e 100644
--- a/app/models/tournament_setting.rb
+++ b/app/models/tournament_setting.rb
@@ -4,6 +4,10 @@ class TournamentSetting < ActiveRecord::Base
validates(:vartype, presence: true, numericality: {only_integer: true})
validates(:type_opt, presence: true, if: :needs_type_opt?)
+ def owned_by?(user)
+ self.tournament.owned_by?(user)
+ end
+
def needs_type_opt?
[
GameSetting.types[:pick_one_radio],
diff --git a/app/models/tournament_stage.rb b/app/models/tournament_stage.rb
index 72aa14c..efb4d5c 100644
--- a/app/models/tournament_stage.rb
+++ b/app/models/tournament_stage.rb
@@ -12,6 +12,10 @@ class TournamentStage < ActiveRecord::Base
presence: true,
inclusion: {in: Tournament.new.seeding_methods})
+ def owned_by?(user)
+ self.tournament.owned_by?(user)
+ end
+
# A 1-indexed hash of matches
def matches_ordered
h = {}
diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb
index e0e69b5..df2c426 100644
--- a/app/views/matches/index.html.erb
+++ b/app/views/matches/index.html.erb
@@ -20,8 +20,7 @@
<td><%= (match.winner.nil? ? "-" : "Team #{match.winner.id}") %></td>
<td><%= link_to "See Match", tournament_match_path(@tournament, match) %>
<td>
- <%# NOTE: - fix this permission, if split up by match, this does not work %>
- <% if @tournament.check_permission(current_user, :edit) %>
+ <% if match.check_permission(current_user, :edit) %>
<%= form_tag(tournament_match_path(@tournament, match), method: "put") do %>
<input type="hidden" name="update_action" value="start">
<% @startable = (match.status == 1) and (match.teams.count >= @tournament.min_teams_per_match) %>