1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-03 13:30:02 +00:00

Added views to delegate tournament permissions

This commit is contained in:
2016-01-07 19:55:15 +00:00
parent 216e60d2b8
commit dd9e19b43f
10 changed files with 157 additions and 10 deletions

View File

@@ -40,7 +40,7 @@ class Ability
end
#Can manage school if tournament owner
can :manage, School do |school|
school.tournament.user.id == user.id
school.tournament.user_id == user.id
end
#Can manage school if tournament delegate
can :manage, School do |school|

View File

@@ -1,2 +1,4 @@
class SchoolDelegate < ActiveRecord::Base
belongs_to :school
belongs_to :user
end

View File

@@ -1,4 +1,4 @@
class TournamentDelegate < ActiveRecord::Base
# belongs_to :tournament
# has_one :user
belongs_to :tournament
belongs_to :user
end

View File

@@ -2,10 +2,29 @@ class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
has_many :tournaments
has_many :delegated_tournaments, class_name: "TournamentDelegate"
has_many :delegated_schools, class_name: "SchoolDelegate"
has_many :delegated_tournament_permissions, class_name: "TournamentDelegate"
has_many :delegated_school_permissions, class_name: "SchoolDelegate"
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
def delegated_tournaments
tournaments_delegated = []
delegated_tournament_permissions.each do |t|
tournaments_delegated << t.tournament
end
tournaments_delegated
end
def delegated_schools
schools_delegated = []
delegated_school_permissions.each do |t|
schools_delegated << t.school
end
schools_delegated
end
def self.search(search)
where("email LIKE ?", "%#{search}%")
end
end