Skip to content

Instantly share code, notes, and snippets.

@jboursiquot
Created January 7, 2014 21:18
Show Gist options
  • Save jboursiquot/8307084 to your computer and use it in GitHub Desktop.
Save jboursiquot/8307084 to your computer and use it in GitHub Desktop.
app/models/authentication/team_check.rb
module Authentication
class TeamCheck
include GitHub::HasClient
def initialize(token, login)
@token = token
@login = login
end
def passes?
@login && client && in_organization? && on_authorized_team?
end
def admin?
!(self.class.admin_team_names & team_names).empty?
end
def experience_engineer?
!(self.class.experience_engineer_team_names & team_names).empty?
end
def effective_teams
@effective_teams ||= authorized_team_names & team_names
end
class << self
def admin_team_names
[
'admins'
]
end
def experience_engineer_team_names
[
'experience engineers'
]
end
end
protected
def authorized_team_names
self.class.admin_team_names + self.class.experience_engineer_team_names + active_section_team_names
end
def active_section_team_names
CourseSection.active.map{|a| a.github_team_name }
end
def on_authorized_team?
!effective_teams.empty?
end
def in_organization?
client.organization_member?(GitHub.org_name, @login)
end
def team_names
teams.map {|team| team.name }
end
def teams
@teams ||= client.organization_teams(GitHub.org_name)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment