mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-09 07:28:41 -07:00
TODO- in the future, consider putting this in a credential. We're not able to change the production credentials file currently, but we should change it in the future when we're able
42 lines
1.1 KiB
Ruby
42 lines
1.1 KiB
Ruby
class SqmApplicationController < ActionController::Base
|
|
protect_from_forgery with: :exception, prepend: true
|
|
layout "sqm/application"
|
|
before_action :set_schools_and_districts
|
|
before_action :authenticate_district
|
|
before_action :set_google_analytics_id
|
|
|
|
private
|
|
|
|
def authenticate_district
|
|
authenticate(@district.name.downcase, "#{@district.name.downcase}!")
|
|
end
|
|
|
|
def set_schools_and_districts
|
|
@district = District.find_by_slug district_slug
|
|
@districts = District.all.sort_by(&:name)
|
|
@school = School.find_by_slug school_slug
|
|
@schools = School.where(district: @district).sort_by(&:name)
|
|
@academic_year = AcademicYear.find_by_range params[:year]
|
|
@has_empty_dataset = Measure.none_meet_threshold? school: @school, academic_year: @academic_year
|
|
end
|
|
|
|
def district_slug
|
|
params[:district_id]
|
|
end
|
|
|
|
def school_slug
|
|
params[:school_id]
|
|
end
|
|
|
|
def authenticate(username, password)
|
|
return true if username == "boston"
|
|
authenticate_or_request_with_http_basic do |u, p|
|
|
u == username && p == password
|
|
end
|
|
end
|
|
|
|
def set_google_analytics_id
|
|
@google_analytics_id = ENV['GOOGLE_ANALYTICS_ID']
|
|
end
|
|
|
|
end
|