From 0d6f7a3bfbf4c87510a1bcf967b618f98e149d49 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 29 Apr 2014 11:25:23 -0400 Subject: clean up permission system --- app/models/alert.rb | 4 ++++ app/models/bracket.rb | 4 ++++ app/models/session.rb | 4 ++++ app/models/team.rb | 4 ++++ app/models/tournament.rb | 4 ++++ app/models/user.rb | 3 +++ 6 files changed, 23 insertions(+) (limited to 'app/models') diff --git a/app/models/alert.rb b/app/models/alert.rb index 9876711..e8a4cf2 100644 --- a/app/models/alert.rb +++ b/app/models/alert.rb @@ -1,3 +1,7 @@ class Alert < ActiveRecord::Base belongs_to :author, class_name: "User" + + def owned_by?(user) + self.author == user + end end diff --git a/app/models/bracket.rb b/app/models/bracket.rb index 48414c3..5aac704 100644 --- a/app/models/bracket.rb +++ b/app/models/bracket.rb @@ -3,6 +3,10 @@ class Bracket < ActiveRecord::Base belongs_to :tournament has_many :bracket_matches + def owned_by?(tuser) + self.user == tuser + end + def create_matches tournament.stages.order(:id).first.matches.order(:id).each do |m| bracket_matches.create(match: m) diff --git a/app/models/session.rb b/app/models/session.rb index f5e642b..27687eb 100644 --- a/app/models/session.rb +++ b/app/models/session.rb @@ -1,6 +1,10 @@ class Session < ActiveRecord::Base belongs_to :user + def owned_by?(tuser) + self.user == tuser + end + ## # Create a random remember token for the user. This will be # changed every time the user creates a new session. diff --git a/app/models/team.rb b/app/models/team.rb index 828d168..90981da 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -3,4 +3,8 @@ class Team < ActiveRecord::Base has_and_belongs_to_many :users alias_attribute :players, :users + + def owned_by?(user) + self.users.include?(user) + end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 8a96dcc..854b8c9 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -55,6 +55,10 @@ class Tournament < ActiveRecord::Base (not self.scoring_method.try(:empty?)) and (scoring_methods.include? scoring_method) end + def owned_by?(user) + self.hosts.include?(user) + end + # Settings ################################################################# def settings diff --git a/app/models/user.rb b/app/models/user.rb index a39037c..ad95683 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,7 @@ class User < ActiveRecord::Base + def owned_by?(tuser) + self == tuser + end ################################################################## # Relationships # ################################################################## -- cgit v1.2.3-54-g00ecf