Extract legacy parts of the codebase into its own module

This commit is contained in:
Liam Morley 2021-11-15 16:07:15 -05:00 committed by rebuilt
parent cf6e80ce6b
commit 413096dfe2
269 changed files with 5549 additions and 5279 deletions

View file

@ -1,6 +0,0 @@
class AdminController < ApplicationController
def index
end
end

View file

@ -1,94 +0,0 @@
class AttemptsController < ApplicationController
# before_action :set_attempt, only: [:edit, :update]
protect_from_forgery :except => [:twilio]
def twilio
recipient = Recipient.where(phone: twilio_params['From']).first
attempt = recipient.attempts.last_sent.first
all_twilio_details = (attempt.twilio_details || '').split('~!~')
all_twilio_details << twilio_params.to_h.to_yaml
attempt.save_response(
answer_index: twilio_params[:Body].to_i > 0 ? twilio_params[:Body].to_i : nil,
twilio_details: all_twilio_details.join('~!~')
)
unless (['start', 'resume', 'restart', 'yes', 'go'].index(twilio_params[:Body].downcase).nil?)
recipient.update(opted_out: false)
render plain: 'Thank you, you will now begin receiving messages again.'
return
end
unless (['stop', 'cancel', 'quit', 'no'].index(twilio_params[:Body].downcase).nil?)
recipient.update(opted_out: true)
render plain: 'Thank you, you have been opted out of these messages and will no longer receive them.'
return
end
unless (['skip', 'i dont know', "i don't know", 'next'].index(twilio_params[:Body].downcase).nil?)
render plain: 'Thank you, this question has been skipped.'
return
end
response_message = ["We've registered your response of \"#{attempt.response}\"."]
answer_count = Attempt.for_question(attempt.question).for_school(recipient.school).with_answer.count
if answer_count > 1
response_message << "#{answer_count} people have responded to this question so far. To see all responses visit:"
else
response_message << 'You are the first person to respond to this question. Once more people have responded you will be able to see all responses at:'
end
response_message << school_category_url(attempt.recipient.school, attempt.question.category)
render plain: response_message.join(' ')
end
# # GET /attempts/1/edit
# def edit
# end
#
# # PATCH/PUT /attempts/1
# # PATCH/PUT /attempts/1.json
# def update
# attempt_params = {}
# if twilio_params.present?
# attempt_params.merge!(
# answer_index: twilio_params[:Body].to_i,
# twilio_details: twilio_params.to_h.to_yaml
# )
# end
#
# respond_to do |format|
# if @attempt.update(attempt_params)
# format.html { render plain: 'Thank you!' }
# format.json { render :show, status: :ok, location: @attempt }
# else
# format.html { render :edit }
# format.json { render json: @attempt.errors, status: :unprocessable_entity }
# end
# end
# end
# # DELETE /attempts/1
# # DELETE /attempts/1.json
# def destroy
# @attempt.destroy
# respond_to do |format|
# format.html { redirect_to attempts_url, notice: 'attempt was successfully destroyed.' }
# format.json { head :no_content }
# end
# end
private
# Use callbacks to share common setup or constraints between actions.
def set_attempt
@attempt = Attempt.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def twilio_params
{"Body"=>"5", ""=>"US", "To"=>"+16172023890", "ToZip"=>"02135", "NumSegments"=>"1", "MessageSid"=>"SMe37977e625b7f0b429339e752dddefef", "AccountSid"=>"AC57dc8a5a6d75addb9528e730e92f66b2", "From"=>"+16502693205", "ApiVersion"=>"2010-04-01"}
params.permit(:FromCountry, :FromState, :FromZip, :FromCity, :ToCountry, :ToState, :SmsStatus, :SmsSid, :SmsMessageSid, :MessageSid, :AccountSid, :MessagingServiceSid, :From, :To, :Body, :NumMedia)
end
end

View file

@ -1,104 +1,9 @@
class CategoriesController < ApplicationController
before_action :set_school, only: [:show]
before_action :set_category, only: [:show, :edit, :update, :destroy]
class CategoriesController < SqmApplicationController
# GET /categories
# GET /categories.json
def index
@categories = Category.all
end
# GET /categories/1
# GET /categories/1.json
def show
district = @school.district
authenticate(district.name.downcase, "#{district.name.downcase}!")
@categories = Category.sorted.map { |category| CategoryPresenter.new(category: category) }
school_categories = SchoolCategory.for(@school, @category)
@years = school_categories.map(&:year).map(&:to_i).sort
@year = (params[:year] || @years.last || "2019").to_i
if school_categories.empty?
school_categories = [SchoolCategory.new(school: @school, category: @category, year: @year)]
end
@school_category = school_categories.select { |sc| sc.year.to_s == @year.to_s }.first
@child_school_categories = SchoolCategory.for_parent_category(@school, @category).in(@year).valid.to_a
missing_categories = Category.for_parent(@category) - @child_school_categories.map(&:category)
missing_categories.each do |category|
next if category.benchmark.present?
@child_school_categories << category.school_categories.new(school: @school)
end
if district.name == "Boston"
@child_school_categories = @child_school_categories.reject { |csc| csc.admin? }
end
@questions = @category.questions.created_in(@year)
@category = CategoryPresenter.new(category: Category.find_by_slug(params[:id]))
end
# GET /categories/new
def new
@category = Category.new
end
# GET /categories/1/edit
def edit
end
# POST /categories
# POST /categories.json
def create
@category = Category.new(category_params)
respond_to do |format|
if @category.save
format.html { redirect_to @category, notice: 'Category was successfully created.' }
format.json { render :show, status: :created, location: @category }
else
format.html { render :new }
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /categories/1
# PATCH/PUT /categories/1.json
def update
respond_to do |format|
if @category.update(category_params)
format.html { redirect_to @category, notice: 'Category was successfully updated.' }
format.json { render :show, status: :ok, location: @category }
else
format.html { render :edit }
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
# DELETE /categories/1
# DELETE /categories/1.json
def destroy
@category.destroy
respond_to do |format|
format.html { redirect_to categories_url, notice: 'Category was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_school
redirect_to root_path and return false unless params.include?(:school_id)
@school = School.friendly.find(params[:school_id])
redirect_to root_path and return false if @school.nil?
end
def set_category
@category = Category.friendly.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def category_params
params.require(:category).permit(:name, :blurb, :description, :external_id, :parent_category_id)
end
end

View file

@ -2,7 +2,7 @@ class DashboardController < SqmApplicationController
def index
@variance_chart_row_presenters = Measure.all.map(&method(:presenter_for_measure))
@category_presenters = SqmCategory.sorted.map { |sqm_category| CategoryPresenter.new(category: sqm_category) }
@category_presenters = Category.sorted.map { |category| CategoryPresenter.new(category: category) }
end
private

View file

@ -1,76 +0,0 @@
class DistrictsController < ApplicationController
before_action :set_district, only: [:show, :edit, :update, :destroy]
# GET /districts
# GET /districts.json
def index
@districts = District.all.alphabetic
end
# GET /districts/1
# GET /districts/1.json
def show
authenticate(@district.name.downcase, "#{@district.name.downcase}!")
@schools = @district.schools.alphabetic
end
# GET /districts/new
def new
@district = District.new
end
# GET /districts/1/edit
def edit
end
# POST /districts
# POST /districts.json
def create
@district = District.new(district_params)
respond_to do |format|
if @district.save
format.html { redirect_to @district, notice: 'District was successfully created.' }
format.json { render :show, status: :created, location: @district }
else
format.html { render :new }
format.json { render json: @district.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /districts/1
# PATCH/PUT /districts/1.json
def update
respond_to do |format|
if @district.update(district_params)
format.html { redirect_to @district, notice: 'District was successfully updated.' }
format.json { render :show, status: :ok, location: @district }
else
format.html { render :edit }
format.json { render json: @district.errors, status: :unprocessable_entity }
end
end
end
# DELETE /districts/1
# DELETE /districts/1.json
def destroy
@district.destroy
respond_to do |format|
format.html { redirect_to districts_url, notice: 'District was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_district
@district = District.find_by_slug(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def district_params
params.require(:district).permit(:name, :state_id)
end
end

View file

@ -3,6 +3,6 @@ class HomeController < ActionController::Base
@districts = District.all.order(:name)
@schools = School.all
@categories = SqmCategory.sorted.map { |category| CategoryPresenter.new(category: category) }
@categories = Category.sorted.map { |category| CategoryPresenter.new(category: category) }
end
end

View file

@ -0,0 +1,8 @@
module Legacy
class AdminController < ApplicationController
def index
end
end
end

View file

@ -0,0 +1,97 @@
module Legacy
class AttemptsController < ApplicationController
# before_action :set_attempt, only: [:edit, :update]
protect_from_forgery :except => [:twilio]
def twilio
recipient = Recipient.where(phone: twilio_params['From']).first
attempt = recipient.attempts.last_sent.first
all_twilio_details = (attempt.twilio_details || '').split('~!~')
all_twilio_details << twilio_params.to_h.to_yaml
attempt.save_response(
answer_index: twilio_params[:Body].to_i > 0 ? twilio_params[:Body].to_i : nil,
twilio_details: all_twilio_details.join('~!~')
)
unless (['start', 'resume', 'restart', 'yes', 'go'].index(twilio_params[:Body].downcase).nil?)
recipient.update(opted_out: false)
render plain: 'Thank you, you will now begin receiving messages again.'
return
end
unless (['stop', 'cancel', 'quit', 'no'].index(twilio_params[:Body].downcase).nil?)
recipient.update(opted_out: true)
render plain: 'Thank you, you have been opted out of these messages and will no longer receive them.'
return
end
unless (['skip', 'i dont know', "i don't know", 'next'].index(twilio_params[:Body].downcase).nil?)
render plain: 'Thank you, this question has been skipped.'
return
end
response_message = ["We've registered your response of \"#{attempt.response}\"."]
answer_count = Attempt.for_question(attempt.question).for_school(recipient.school).with_answer.count
if answer_count > 1
response_message << "#{answer_count} people have responded to this question so far. To see all responses visit:"
else
response_message << 'You are the first person to respond to this question. Once more people have responded you will be able to see all responses at:'
end
response_message << legacy_school_legacy_category_url(attempt.recipient.school, attempt.question.category)
render plain: response_message.join(' ')
end
# # GET /attempts/1/edit
# def edit
# end
#
# # PATCH/PUT /attempts/1
# # PATCH/PUT /attempts/1.json
# def update
# attempt_params = {}
# if twilio_params.present?
# attempt_params.merge!(
# answer_index: twilio_params[:Body].to_i,
# twilio_details: twilio_params.to_h.to_yaml
# )
# end
#
# respond_to do |format|
# if @attempt.update(attempt_params)
# format.html { render plain: 'Thank you!' }
# format.json { render :show, status: :ok, location: @attempt }
# else
# format.html { render :edit }
# format.json { render json: @attempt.errors, status: :unprocessable_entity }
# end
# end
# end
# # DELETE /attempts/1
# # DELETE /attempts/1.json
# def destroy
# @attempt.destroy
# respond_to do |format|
# format.html { redirect_to attempts_url, notice: 'attempt was successfully destroyed.' }
# format.json { head :no_content }
# end
# end
private
# Use callbacks to share common setup or constraints between actions.
def set_attempt
@attempt = Attempt.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def twilio_params
{ "Body" => "5", "" => "US", "To" => "+16172023890", "ToZip" => "02135", "NumSegments" => "1", "MessageSid" => "SMe37977e625b7f0b429339e752dddefef", "AccountSid" => "AC57dc8a5a6d75addb9528e730e92f66b2", "From" => "+16502693205", "ApiVersion" => "2010-04-01" }
params.permit(:FromCountry, :FromState, :FromZip, :FromCity, :ToCountry, :ToState, :SmsStatus, :SmsSid, :SmsMessageSid, :MessageSid, :AccountSid, :MessagingServiceSid, :From, :To, :Body, :NumMedia)
end
end
end

View file

@ -0,0 +1,107 @@
module Legacy
class CategoriesController < ApplicationController
before_action :set_school, only: [:show]
before_action :set_category, only: [:show, :edit, :update, :destroy]
# GET /categories
# GET /categories.json
def index
@categories = Category.all
end
# GET /categories/1
# GET /categories/1.json
def show
district = @school.district
authenticate(district.name.downcase, "#{district.name.downcase}!")
school_categories = SchoolCategory.for(@school, @category)
@years = school_categories.map(&:year).map(&:to_i).sort
@year = (params[:year] || @years.last || "2019").to_i
if school_categories.empty?
school_categories = [SchoolCategory.new(school: @school, category: @category, year: @year)]
end
@school_category = school_categories.select { |sc| sc.year.to_s == @year.to_s }.first
@child_school_categories = SchoolCategory.for_parent_category(@school, @category).in(@year).valid.to_a
missing_categories = Category.for_parent(@category) - @child_school_categories.map(&:category)
missing_categories.each do |category|
next if category.benchmark.present?
@child_school_categories << category.school_categories.new(school: @school)
end
if district.name == "Boston"
@child_school_categories = @child_school_categories.reject { |csc| csc.admin? }
end
@questions = @category.questions.created_in(@year)
end
# GET /categories/new
def new
@category = Category.new
end
# GET /categories/1/edit
def edit
end
# POST /categories
# POST /categories.json
def create
@category = Category.new(category_params)
respond_to do |format|
if @category.save
format.html { redirect_to @category, notice: 'Category was successfully created.' }
format.json { render :show, status: :created, location: @category }
else
format.html { render :new }
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /categories/1
# PATCH/PUT /categories/1.json
def update
respond_to do |format|
if @category.update(category_params)
format.html { redirect_to @category, notice: 'Category was successfully updated.' }
format.json { render :show, status: :ok, location: @category }
else
format.html { render :edit }
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
# DELETE /categories/1
# DELETE /categories/1.json
def destroy
@category.destroy
respond_to do |format|
format.html { redirect_to legacy_categories_url, notice: 'Category was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_school
redirect_to root_path and return false unless params.include?(:school_id)
@school = School.friendly.find(params[:school_id])
redirect_to root_path and return false if @school.nil?
end
def set_category
@category = Category.friendly.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def category_params
params.require(:category).permit(:name, :blurb, :description, :external_id, :parent_category_id)
end
end
end

View file

@ -0,0 +1,79 @@
module Legacy
class DistrictsController < ApplicationController
before_action :set_district, only: [:show, :edit, :update, :destroy]
# GET /districts
# GET /districts.json
def index
@districts = District.all.alphabetic
end
# GET /districts/1
# GET /districts/1.json
def show
authenticate(@district.name.downcase, "#{@district.name.downcase}!")
@schools = @district.schools.alphabetic
end
# GET /districts/new
def new
@district = District.new
end
# GET /districts/1/edit
def edit
end
# POST /districts
# POST /districts.json
def create
@district = District.new(district_params)
respond_to do |format|
if @district.save
format.html { redirect_to @district, notice: 'District was successfully created.' }
format.json { render :show, status: :created, location: @district }
else
format.html { render :new }
format.json { render json: @district.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /districts/1
# PATCH/PUT /districts/1.json
def update
respond_to do |format|
if @district.update(district_params)
format.html { redirect_to @district, notice: 'District was successfully updated.' }
format.json { render :show, status: :ok, location: @district }
else
format.html { render :edit }
format.json { render json: @district.errors, status: :unprocessable_entity }
end
end
end
# DELETE /districts/1
# DELETE /districts/1.json
def destroy
@district.destroy
respond_to do |format|
format.html { redirect_to districts_url, notice: 'District was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_district
@district = District.find_by_slug(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def district_params
params.require(:district).permit(:name, :state_id)
end
end
end

View file

@ -0,0 +1,77 @@
module Legacy
class QuestionListsController < ApplicationController
before_action :set_question_list, only: [:show, :edit, :update, :destroy]
# GET /question_lists
# GET /question_lists.json
def index
@question_lists = QuestionList.all
end
# GET /question_lists/1
# GET /question_lists/1.json
def show
end
# GET /question_lists/new
def new
@question_list = QuestionList.new
end
# GET /question_lists/1/edit
def edit
end
# POST /question_lists
# POST /question_lists.json
def create
@question_list = QuestionList.new(question_list_params)
respond_to do |format|
if @question_list.save
format.html { redirect_to @question_list, notice: 'Question list was successfully created.' }
format.json { render :show, status: :created, location: @question_list }
else
format.html { render :new }
format.json { render json: @question_list.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /question_lists/1
# PATCH/PUT /question_lists/1.json
def update
respond_to do |format|
if @question_list.update(question_list_params)
format.html { redirect_to @question_list, notice: 'Question list was successfully updated.' }
format.json { render :show, status: :ok, location: @question_list }
else
format.html { render :edit }
format.json { render json: @question_list.errors, status: :unprocessable_entity }
end
end
end
# DELETE /question_lists/1
# DELETE /question_lists/1.json
def destroy
@question_list.destroy
respond_to do |format|
format.html { redirect_to legacy_question_lists_url, notice: 'Question list was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_question_list
@question_list = QuestionList.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def question_list_params
params.require(:question_list).permit(:name, :description, question_id_array: [])
end
end
end

View file

@ -0,0 +1,90 @@
module Legacy
class QuestionsController < ApplicationController
before_action :authenticate_user!, except: [:show]
before_action :verify_super_admin, except: [:show]
before_action :set_school, only: [:show]
before_action :set_question, only: [:show, :edit, :update, :destroy]
# GET /questions
# GET /questions.json
def index
@questions = Question.all
end
# GET /questions/1
# GET /questions/1.json
def show
end
# GET /questions/new
def new
@question = Question.new
end
# GET /questions/1/edit
def edit
end
# POST /questions
# POST /questions.json
def create
@question = Question.new(question_params)
respond_to do |format|
if @question.save
format.html { redirect_to @question, notice: 'Question was successfully created.' }
format.json { render :show, status: :created, location: @question }
else
format.html { render :new }
format.json { render json: @question.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /questions/1
# PATCH/PUT /questions/1.json
def update
respond_to do |format|
if @question.update(question_params)
format.html { redirect_to @question, notice: 'Question was successfully updated.' }
format.json { render :show, status: :ok, location: @question }
else
format.html { render :edit }
format.json { render json: @question.errors, status: :unprocessable_entity }
end
end
end
# DELETE /questions/1
# DELETE /questions/1.json
def destroy
@question.destroy
respond_to do |format|
format.html { redirect_to legacy_questions_url, notice: 'Question was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_school
redirect_to root_path and return false unless params.include?(:school_id)
@school = School.friendly.find(params[:school_id])
redirect_to root_path and return false if @school.nil?
end
# Use callbacks to share common setup or constraints between actions.
def set_question
@question = Question.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def question_params
params.require(:question).permit(:text, :option1, :option2, :option3, :option4, :option5, :category_id)
end
def verify_super_admin
user_signed_in? && current_user.super_admin?
end
end
end

View file

@ -0,0 +1,69 @@
module Legacy
class RecipientListsController < ApplicationController
before_action :authenticate_user!
before_action :set_school
before_action :verify_admin
before_action :set_recipient_list, only: [:show, :edit, :update, :destroy]
# GET schools/1/recipient_lists
def index
@recipient_lists = @school.recipient_lists
end
# GET schools/1/recipient_lists/1
def show
end
# GET schools/1/recipient_lists/new
def new
@recipient_list = @school.recipient_lists.build
end
# GET schools/1/recipient_lists/1/edit
def edit
end
# POST schools/1/recipient_lists
def create
@recipient_list = @school.recipient_lists.build(recipient_list_params)
if @recipient_list.save
redirect_to([@recipient_list.school, @recipient_list], notice: 'Recipient list was successfully created.')
else
render action: 'new'
end
end
# PUT schools/1/recipient_lists/1
def update
if @recipient_list.update(recipient_list_params)
redirect_to([@recipient_list.school, @recipient_list], notice: 'Recipient list was successfully updated.')
else
render action: 'edit'
end
end
# DELETE schools/1/recipient_lists/1
def destroy
@recipient_list.destroy
redirect_to @school
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.friendly.find(params[:school_id])
end
def set_recipient_list
@recipient_list = @school.recipient_lists.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def recipient_list_params
params.require(:recipient_list).permit(:name, :description, recipient_id_array: [])
end
end
end

View file

@ -0,0 +1,92 @@
module Legacy
class RecipientsController < ApplicationController
before_action :authenticate_user!
before_action :set_school
before_action :verify_admin
before_action :set_recipient, only: [:show, :edit, :update, :destroy]
# GET /recipients
# GET /recipients.json
def index
@recipients = @school.recipients.all
end
# GET /recipients/1
# GET /recipients/1.json
def show
end
# GET /recipients/new
def new
@recipient = @school.recipients.new
end
# GET /recipients/1/edit
def edit
end
# POST /recipients
# POST /recipients.json
def create
@recipient = @school.recipients.new(recipient_params)
respond_to do |format|
if @recipient.save
format.html { redirect_to legacy_school_legacy_recipient_path(@school, @recipient), notice: 'Recipient was successfully created.' }
format.json { render :show, status: :created, location: @recipient }
else
format.html { render :new }
format.json { render json: @recipient.errors, status: :unprocessable_entity }
end
end
end
def import
render and return if request.get?
Recipient.import(@school, params[:file])
redirect_to @school, notice: "Recipients imported."
end
# PATCH/PUT /recipients/1
# PATCH/PUT /recipients/1.json
def update
respond_to do |format|
if @recipient.update(recipient_params)
format.html { redirect_to legacy_school_legacy_recipient_path(@school, @recipient), notice: 'Recipient was successfully updated.' }
format.json { render :show, status: :ok, location: @recipient }
else
format.html { render :edit }
format.json { render json: @recipient.errors, status: :unprocessable_entity }
end
end
end
# DELETE /recipients/1
# DELETE /recipients/1.json
def destroy
@recipient.destroy
respond_to do |format|
format.html { redirect_to @school, notice: 'Recipient was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.friendly.find(params[:school_id])
end
# Use callbacks to share common setup or constraints between actions.
def set_recipient
@recipient = @school.recipients.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def recipient_params
params.require(:recipient).permit(:name, :phone, :birth_date, :gender, :race, :ethnicity, :home_language_id, :income, :opted_out, :school_id)
end
end
end

View file

@ -0,0 +1,71 @@
module Legacy
class SchedulesController < ApplicationController
before_action :authenticate_user!, except: [:show]
before_action :set_school
before_action :verify_admin
before_action :set_schedule, only: [:show, :edit, :update, :destroy]
before_action :set_time, only: [:create, :update]
# GET schools/1/schedules/1
def show
end
# GET schools/1/schedules/new
def new
@schedule = @school.schedules.build
end
# GET schools/1/schedules/1/edit
def edit
end
# POST schools/1/schedules
def create
@schedule = @school.schedules.build(schedule_params)
if @schedule.save
redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully created.')
else
render action: 'new'
end
end
# PUT schools/1/schedules/1
def update
if @schedule.update(schedule_params)
redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully updated.')
else
render action: 'edit'
end
end
# DELETE schools/1/schedules/1
def destroy
@schedule.destroy
redirect_to @school
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.friendly.find(params[:school_id])
end
def set_schedule
@schedule = @school.schedules.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def schedule_params
params.require(:schedule).permit(:name, :description, :school_id, :frequency_hours, :start_date, :end_date, :time, :active, :random, :recipient_list_id, :question_list_id)
end
def set_time
return unless schedule_params.include?(:time)
params[:schedule][:time] = schedule_params[:time].to_i + (4 * 60) # Go from EST to UTC (NEEDS TO BETTER)
end
end
end

View file

@ -0,0 +1,97 @@
module Legacy
class SchoolsController < ApplicationController
before_action :authenticate_user!, except: [:show]
before_action :set_school, only: [:admin, :show, :edit, :update, :destroy]
before_action :verify_admin, except: [:show, :create, :new]
# GET /schools/1
# GET /schools/1.json
def show
@district = @school.district
authenticate(@district.name.downcase, "#{@district.name.downcase}!")
@years = [2017, 2018, 2019]
@year = (params[:year] || @years.last).to_i
if @district.name == "Boston"
@categories = Category.joins(:questions)
@school_categories = SchoolCategory.where(school: @school).where(category: @categories).in(@year).to_a
else
@categories = Category.root
@school_categories = @school.school_categories.for_parent_category(@school, nil).valid.in(@year).sort
end
missing_categories = @categories - @school_categories.map(&:category)
missing_categories.each do |category|
@school_categories << category.school_categories.new(school: @school, year: @year)
end
@school_categories = @school_categories.select { |sc| sc.year.to_i == @year }
end
def admin
end
# GET /schools/new
def new
@school = School.new
end
# GET /schools/1/edit
def edit
end
# POST /schools
# POST /schools.json
def create
@school = School.new(school_params)
respond_to do |format|
if @school.save
format.html { redirect_to @school, notice: 'School was successfully created.' }
format.json { render :show, status: :created, location: @school }
else
format.html { render :new }
format.json { render json: @school.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /schools/1
# PATCH/PUT /schools/1.json
def update
respond_to do |format|
if @school.update(school_params)
format.html { redirect_to @school, notice: 'School was successfully updated.' }
format.json { render :show, status: :ok, location: @school }
else
format.html { render :edit }
format.json { render json: @school.errors, status: :unprocessable_entity }
end
end
end
# DELETE /schools/1
# DELETE /schools/1.json
def destroy
@school.destroy
respond_to do |format|
format.html { redirect_to legacy_schools_url, notice: 'School was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.friendly.find(params[:id] || params[:school_id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def school_params
params.require(:school).permit(:name, :district_id)
end
end
end

View file

@ -0,0 +1,16 @@
module Legacy
class UsersController < ApplicationController
def show; end
# private
# # Use callbacks to share common setup or constraints between actions.
# def set_district
# @district = District.find(params[:id])
# end
#
# # Never trust parameters from the scary internet, only allow the white list through.
# def district_params
# params.require(:district).permit(:name, :state_id)
# end
end
end

View file

@ -0,0 +1,10 @@
module Legacy
class WelcomeController < ApplicationController
def index
@districts = District.all.alphabetic
@schools = School.all.alphabetic
end
end
end

View file

@ -1,74 +0,0 @@
class QuestionListsController < ApplicationController
before_action :set_question_list, only: [:show, :edit, :update, :destroy]
# GET /question_lists
# GET /question_lists.json
def index
@question_lists = QuestionList.all
end
# GET /question_lists/1
# GET /question_lists/1.json
def show
end
# GET /question_lists/new
def new
@question_list = QuestionList.new
end
# GET /question_lists/1/edit
def edit
end
# POST /question_lists
# POST /question_lists.json
def create
@question_list = QuestionList.new(question_list_params)
respond_to do |format|
if @question_list.save
format.html { redirect_to @question_list, notice: 'Question list was successfully created.' }
format.json { render :show, status: :created, location: @question_list }
else
format.html { render :new }
format.json { render json: @question_list.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /question_lists/1
# PATCH/PUT /question_lists/1.json
def update
respond_to do |format|
if @question_list.update(question_list_params)
format.html { redirect_to @question_list, notice: 'Question list was successfully updated.' }
format.json { render :show, status: :ok, location: @question_list }
else
format.html { render :edit }
format.json { render json: @question_list.errors, status: :unprocessable_entity }
end
end
end
# DELETE /question_lists/1
# DELETE /question_lists/1.json
def destroy
@question_list.destroy
respond_to do |format|
format.html { redirect_to question_lists_url, notice: 'Question list was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_question_list
@question_list = QuestionList.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def question_list_params
params.require(:question_list).permit(:name, :description, question_id_array: [])
end
end

View file

@ -1,87 +0,0 @@
class QuestionsController < ApplicationController
before_action :authenticate_user!, except: [:show]
before_action :verify_super_admin, except: [:show]
before_action :set_school, only: [:show]
before_action :set_question, only: [:show, :edit, :update, :destroy]
# GET /questions
# GET /questions.json
def index
@questions = Question.all
end
# GET /questions/1
# GET /questions/1.json
def show
end
# GET /questions/new
def new
@question = Question.new
end
# GET /questions/1/edit
def edit
end
# POST /questions
# POST /questions.json
def create
@question = Question.new(question_params)
respond_to do |format|
if @question.save
format.html { redirect_to @question, notice: 'Question was successfully created.' }
format.json { render :show, status: :created, location: @question }
else
format.html { render :new }
format.json { render json: @question.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /questions/1
# PATCH/PUT /questions/1.json
def update
respond_to do |format|
if @question.update(question_params)
format.html { redirect_to @question, notice: 'Question was successfully updated.' }
format.json { render :show, status: :ok, location: @question }
else
format.html { render :edit }
format.json { render json: @question.errors, status: :unprocessable_entity }
end
end
end
# DELETE /questions/1
# DELETE /questions/1.json
def destroy
@question.destroy
respond_to do |format|
format.html { redirect_to questions_url, notice: 'Question was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_school
redirect_to root_path and return false unless params.include?(:school_id)
@school = School.friendly.find(params[:school_id])
redirect_to root_path and return false if @school.nil?
end
# Use callbacks to share common setup or constraints between actions.
def set_question
@question = Question.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def question_params
params.require(:question).permit(:text, :option1, :option2, :option3, :option4, :option5, :category_id)
end
def verify_super_admin
user_signed_in? && current_user.super_admin?
end
end

View file

@ -1,66 +0,0 @@
class RecipientListsController < ApplicationController
before_action :authenticate_user!
before_action :set_school
before_action :verify_admin
before_action :set_recipient_list, only: [:show, :edit, :update, :destroy]
# GET schools/1/recipient_lists
def index
@recipient_lists = @school.recipient_lists
end
# GET schools/1/recipient_lists/1
def show
end
# GET schools/1/recipient_lists/new
def new
@recipient_list = @school.recipient_lists.build
end
# GET schools/1/recipient_lists/1/edit
def edit
end
# POST schools/1/recipient_lists
def create
@recipient_list = @school.recipient_lists.build(recipient_list_params)
if @recipient_list.save
redirect_to([@recipient_list.school, @recipient_list], notice: 'Recipient list was successfully created.')
else
render action: 'new'
end
end
# PUT schools/1/recipient_lists/1
def update
if @recipient_list.update(recipient_list_params)
redirect_to([@recipient_list.school, @recipient_list], notice: 'Recipient list was successfully updated.')
else
render action: 'edit'
end
end
# DELETE schools/1/recipient_lists/1
def destroy
@recipient_list.destroy
redirect_to @school
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.friendly.find(params[:school_id])
end
def set_recipient_list
@recipient_list = @school.recipient_lists.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def recipient_list_params
params.require(:recipient_list).permit(:name, :description, recipient_id_array: [])
end
end

View file

@ -1,89 +0,0 @@
class RecipientsController < ApplicationController
before_action :authenticate_user!
before_action :set_school
before_action :verify_admin
before_action :set_recipient, only: [:show, :edit, :update, :destroy]
# GET /recipients
# GET /recipients.json
def index
@recipients = @school.recipients.all
end
# GET /recipients/1
# GET /recipients/1.json
def show
end
# GET /recipients/new
def new
@recipient = @school.recipients.new
end
# GET /recipients/1/edit
def edit
end
# POST /recipients
# POST /recipients.json
def create
@recipient = @school.recipients.new(recipient_params)
respond_to do |format|
if @recipient.save
format.html { redirect_to school_recipient_path(@school, @recipient), notice: 'Recipient was successfully created.' }
format.json { render :show, status: :created, location: @recipient }
else
format.html { render :new }
format.json { render json: @recipient.errors, status: :unprocessable_entity }
end
end
end
def import
render and return if request.get?
Recipient.import(@school, params[:file])
redirect_to @school, notice: "Recipients imported."
end
# PATCH/PUT /recipients/1
# PATCH/PUT /recipients/1.json
def update
respond_to do |format|
if @recipient.update(recipient_params)
format.html { redirect_to school_recipient_path(@school, @recipient), notice: 'Recipient was successfully updated.' }
format.json { render :show, status: :ok, location: @recipient }
else
format.html { render :edit }
format.json { render json: @recipient.errors, status: :unprocessable_entity }
end
end
end
# DELETE /recipients/1
# DELETE /recipients/1.json
def destroy
@recipient.destroy
respond_to do |format|
format.html { redirect_to @school, notice: 'Recipient was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.friendly.find(params[:school_id])
end
# Use callbacks to share common setup or constraints between actions.
def set_recipient
@recipient = @school.recipients.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def recipient_params
params.require(:recipient).permit(:name, :phone, :birth_date, :gender, :race, :ethnicity, :home_language_id, :income, :opted_out, :school_id)
end
end

View file

@ -1,68 +0,0 @@
class SchedulesController < ApplicationController
before_action :authenticate_user!, except: [:show]
before_action :set_school
before_action :verify_admin
before_action :set_schedule, only: [:show, :edit, :update, :destroy]
before_action :set_time, only: [:create, :update]
# GET schools/1/schedules/1
def show
end
# GET schools/1/schedules/new
def new
@schedule = @school.schedules.build
end
# GET schools/1/schedules/1/edit
def edit
end
# POST schools/1/schedules
def create
@schedule = @school.schedules.build(schedule_params)
if @schedule.save
redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully created.')
else
render action: 'new'
end
end
# PUT schools/1/schedules/1
def update
if @schedule.update(schedule_params)
redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully updated.')
else
render action: 'edit'
end
end
# DELETE schools/1/schedules/1
def destroy
@schedule.destroy
redirect_to @school
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.friendly.find(params[:school_id])
end
def set_schedule
@schedule = @school.schedules.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def schedule_params
params.require(:schedule).permit(:name, :description, :school_id, :frequency_hours, :start_date, :end_date, :time, :active, :random, :recipient_list_id, :question_list_id)
end
def set_time
return unless schedule_params.include?(:time)
params[:schedule][:time] = schedule_params[:time].to_i + (4 * 60) # Go from EST to UTC (NEEDS TO BETTER)
end
end

View file

@ -1,95 +0,0 @@
class SchoolsController < ApplicationController
before_action :authenticate_user!, except: [:show]
before_action :set_school, only: [:admin, :show, :edit, :update, :destroy]
before_action :verify_admin, except: [:show, :create, :new]
# GET /schools/1
# GET /schools/1.json
def show
@district = @school.district
authenticate(@district.name.downcase, "#{@district.name.downcase}!")
@years = [2017, 2018, 2019]
@year = (params[:year] || @years.last).to_i
if @district.name == "Boston"
@categories = Category.joins(:questions)
@school_categories = SchoolCategory.where(school: @school).where(category: @categories).in(@year).to_a
else
@categories = Category.root
@school_categories = @school.school_categories.for_parent_category(@school, nil).valid.in(@year).sort
end
missing_categories = @categories - @school_categories.map(&:category)
missing_categories.each do |category|
@school_categories << category.school_categories.new(school: @school, year: @year)
end
@school_categories = @school_categories.select { |sc| sc.year.to_i == @year }
end
def admin
end
# GET /schools/new
def new
@school = School.new
end
# GET /schools/1/edit
def edit
end
# POST /schools
# POST /schools.json
def create
@school = School.new(school_params)
respond_to do |format|
if @school.save
format.html { redirect_to @school, notice: 'School was successfully created.' }
format.json { render :show, status: :created, location: @school }
else
format.html { render :new }
format.json { render json: @school.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /schools/1
# PATCH/PUT /schools/1.json
def update
respond_to do |format|
if @school.update(school_params)
format.html { redirect_to @school, notice: 'School was successfully updated.' }
format.json { render :show, status: :ok, location: @school }
else
format.html { render :edit }
format.json { render json: @school.errors, status: :unprocessable_entity }
end
end
end
# DELETE /schools/1
# DELETE /schools/1.json
def destroy
@school.destroy
respond_to do |format|
format.html { redirect_to schools_url, notice: 'School was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.friendly.find(params[:id] || params[:school_id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def school_params
params.require(:school).permit(:name, :district_id)
end
end

View file

@ -1,9 +0,0 @@
class SqmCategoriesController < SqmApplicationController
def show
@categories = SqmCategory.sorted.map { |category| CategoryPresenter.new(category: category) }
@category = CategoryPresenter.new(category: SqmCategory.find_by_slug(params[:id]))
end
end

View file

@ -1,17 +0,0 @@
class UsersController < ApplicationController
def show
end
# private
# # Use callbacks to share common setup or constraints between actions.
# def set_district
# @district = District.find(params[:id])
# end
#
# # Never trust parameters from the scary internet, only allow the white list through.
# def district_params
# params.require(:district).permit(:name, :state_id)
# end
end

View file

@ -1,8 +0,0 @@
class WelcomeController < ApplicationController
def index
@districts = District.all.alphabetic
@schools = School.all.alphabetic
end
end