Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of little cleanup things #175

Merged
merged 55 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
acb3cf3
patch omniauth
cycomachead Sep 1, 2022
1ed3b98
Add a db:import rake task
cycomachead Sep 1, 2022
6138db5
Do not store access/refresh tokens on login
cycomachead Sep 1, 2022
f0ef9fa
run rubocop
cycomachead Sep 1, 2022
335bada
Remove all oauth tokens, and attr_encrypted from teacher logins
cycomachead Sep 2, 2022
f76aaaf
School Selectize: Fix school_id and form fields
cycomachead Sep 2, 2022
656008e
Show the current school first in the selectize dropdown
cycomachead Sep 5, 2022
da7cd7b
use a wider base layout with a fixed nav
cycomachead Sep 5, 2022
c238283
add margin for fixed nav
cycomachead Sep 5, 2022
234121c
Editing/Deleting/Viewing Schools now mostly works.
cycomachead Sep 5, 2022
4a9eb7d
Cleanup+fix teacher creation
cycomachead Sep 5, 2022
0b0a526
Protect against deleting schools with teachers
cycomachead Sep 5, 2022
7a632f7
Show admin users in a second table on teachers#index
cycomachead Sep 5, 2022
019b4e3
delete unneeded JS code!
cycomachead Sep 5, 2022
d7f2bc3
Improve teacher visible forms to include the sidebar
cycomachead Sep 5, 2022
3a06275
Fix preventing schools deletion
cycomachead Sep 5, 2022
faf3c06
Rename slug to URL, permissions to viewer_permissions
cycomachead Sep 5, 2022
7c17daf
tidy
cycomachead Sep 5, 2022
330374f
Improved datatables filtering and pagination
cycomachead Sep 6, 2022
9d87907
cleanup JS
cycomachead Sep 6, 2022
d4d8766
fix teachers allowed params
cycomachead Sep 6, 2022
83baa3a
rerun migrations
cycomachead Sep 6, 2022
83d8abc
Reorder code in teachers controller
cycomachead Sep 6, 2022
05bd3df
Minor cleanup of layoutes
cycomachead Sep 6, 2022
e0fc2cc
Cleanup
cycomachead Sep 6, 2022
0955279
fix typo in main_spec
cycomachead Sep 6, 2022
c43132c
fix page validations function
cycomachead Sep 6, 2022
928183d
replace to text referring to renamed columns
cycomachead Sep 6, 2022
04036b4
Cleanup specs for changing display/text
cycomachead Sep 6, 2022
ef17faa
reflect changed behavior of sessions destroy
cycomachead Sep 6, 2022
c90b068
Fix the schools spec
cycomachead Sep 6, 2022
ad84728
Load fixtures in cucumber for consistency
cycomachead Sep 6, 2022
d5c4088
fix some copy in test cases
cycomachead Sep 6, 2022
a81d49a
Admin + teacher cuke fixes
cycomachead Sep 6, 2022
b3b7d28
run rubocop
cycomachead Sep 6, 2022
aa64d9f
Fix weird school counter issues
cycomachead Sep 6, 2022
3a87875
Fix weird spec with emails
cycomachead Sep 6, 2022
5b9315b
Fixup admin features / within steps
cycomachead Sep 6, 2022
ddf071b
Fix some weird failures with more unique data
cycomachead Sep 6, 2022
1b5b47c
Fix bad find and replace in workflow
cycomachead Sep 6, 2022
efea955
restore new page button on the pages index
cycomachead Sep 6, 2022
8f8764d
Fix name of field on pages edit
cycomachead Sep 6, 2022
03b93b7
Add some now required fields to the school factory
cycomachead Sep 6, 2022
3fec04c
Attempt to cleanup csv
cycomachead Sep 6, 2022
c2b3f88
remove logging
cycomachead Sep 6, 2022
d484003
Cleanup the form HTML
cycomachead Sep 6, 2022
622a325
fix some strings in tests, and the schools factory
cycomachead Sep 6, 2022
f63773a
Comment out the CSV feature tests for now
cycomachead Sep 6, 2022
2bf3919
Cleanup logic in school creation
cycomachead Sep 6, 2022
d97e7a3
tidy code
cycomachead Sep 6, 2022
081b943
try something else
cycomachead Sep 6, 2022
61ad815
use .present? once more
cycomachead Sep 6, 2022
a6f3fcd
fix more specs, load db seeds in rspec
cycomachead Sep 6, 2022
8abe819
Fix more school creation to use IDs
cycomachead Sep 6, 2022
8ddab67
rubocop
cycomachead Sep 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
TZ: America/Los_Angeles
RAILS_ENV: test
RUBY_ENV: test
attr_encrypted_key: '12345678912345678912345678912345'
DISPLAY: ':99' # For chromedriver
CCTR: ./cc-test-reporter
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
Expand Down
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ gem "tzinfo-data"
# for managing API keys
gem "figaro"

# Generate attr_accessors that transparently encrypt and decrypt attributes.
gem "attr_encrypted", "~> 3.1.0"

# Error Tracking
gem "sentry-ruby"
gem "sentry-rails"
Expand Down
8 changes: 2 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ GEM
ansi (1.5.0)
arrayfields (4.9.2)
ast (2.4.2)
attr_encrypted (3.1.0)
encryptor (~> 3.0.0)
aws-eventstream (1.2.0)
aws-partitions (1.573.0)
aws-sdk-core (3.130.0)
Expand Down Expand Up @@ -184,7 +182,6 @@ GEM
diff-lcs (1.5.0)
docile (1.4.0)
dumb_delegator (1.0.0)
encryptor (3.0.0)
erubi (1.10.0)
erubis (2.7.0)
factory_bot (6.2.0)
Expand Down Expand Up @@ -354,7 +351,7 @@ GEM
octokit (4.21.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
omniauth (1.9.1)
omniauth (1.9.2)
hashie (>= 3.4.6)
rack (>= 1.6.2, < 3)
omniauth-clever (1.2.2)
Expand Down Expand Up @@ -405,7 +402,7 @@ GEM
puma (5.6.4)
nio4r (~> 2.0)
racc (1.6.0)
rack (2.2.3.1)
rack (2.2.4)
rack-mini-profiler (2.3.3)
rack (>= 1.2.0)
rack-proxy (0.7.2)
Expand Down Expand Up @@ -609,7 +606,6 @@ PLATFORMS
DEPENDENCIES
activerecord-import
annotate
attr_encrypted (~> 3.1.0)
aws-sdk-s3
axe-core-cucumber
axe-core-rspec
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ def check_teacher_admin
end

def set_sentry_user
Sentry.set_user(id: session[:user_id]) # or anything else in session
Sentry.set_user(id: session[:user_id])
end
end
3 changes: 3 additions & 0 deletions app/controllers/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

class MainController < ApplicationController
before_action :require_admin, only: [:dashboard]

def index
if is_admin?
redirect_to dashboard_path
elsif is_teacher? && current_user.validated?
redirect_to pages_path, notice: "Welcome back, #{@current_user.first_name}!"
elsif is_teacher?
redirect_to edit_teacher_path(current_user.id), notice: "You can edit your information"
else
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create

if @page.save
flash[:success] = "Created #{@page.title} page successfully."
redirect_to action: "show", slug: @page.slug
redirect_to action: "show", url_slug: @page.url_slug
else
flash.now[:alert] = "An error occurred! #{@page.errors.full_messages}"
render "edit"
Expand Down Expand Up @@ -57,16 +57,16 @@ def destroy

private
def load_page
@pages ||= Page.where(permissions: Page.viewable_pages(current_user))
@pages ||= Page.where(viewer_permissions: Page.viewable_pages(current_user))
if params[:id]
@page ||= Page.find_by(id: params[:id])
elsif params[:slug]
@page ||= Page.find_by(slug: params[:slug])
elsif params[:url_slug]
@page ||= Page.find_by(url_slug: params[:url_slug])
end
end

def page_params
params.require(:page).permit(:slug, :html, :title, :permissions)
params.require(:page).permit(:url_slug, :html, :title, :viewer_permissions)
end

# def liquid_assigns
Expand Down
58 changes: 49 additions & 9 deletions app/controllers/schools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,75 @@
class SchoolsController < ApplicationController
before_action :sanitize_params, only: [:new, :create, :edit, :update]
before_action :require_admin

def index
@schools = School.all.order(:name)
end

def show
@school = School.find(params[:id])
end

def search
School.all.collect { |school| ["#{school.name}, #{school.city}, #{school.state}", school.name] }
end

def create
@school = School.find_by(name: school_params[:name], city: school_params[:city], state: school_params[:state])
if !@school # School doesn't exist
if @school
@school.assign_attributes(school_params)
else
@school = School.new(school_params)
if @school.save
flash[:success] = "Created #{@school.name} successfully."
redirect_to schools_path
else
redirect_to root_path, alert: "Failed to submit information :("
end
end
load_ordered_schools
if @school.save
flash[:success] = "Created #{@school.name} successfully."
redirect_to schools_path
else
flash[:alert] = "Failed to submit information :("
render "new"
end
end

def new
@school = School.new
load_ordered_schools
end

def index
@schools = School.all
def edit
@school = School.find(params[:id])
end

def update
@school = School.find(params[:id])
@school.assign_attributes(school_params)
if @school.save
flash[:success] = "Update #{@school.name} successfully."
redirect_back_or_to schools_path
else
render "new", alert: "Failed to submit information :("
end
end

def destroy
@school = School.find(params[:id])
if @school.teachers_count > 0
redirect_to schools_path(@school), alert: "Cannot delete a school which still has teachers"
return
end
@school.destroy
redirect_to schools_path, notice: "Deleted \"#{@school.name}\" successfully."
end

private
def school_params
params.require(:school).permit(:name, :city, :state, :website, :grade_level, :school_type, { tags: [] }, :nces_id)
end

def load_ordered_schools
@ordered_schools ||= School.all.order(:name)
end

def sanitize_params
if params[:school]
if params[:school][:grade_level]
Expand Down
32 changes: 3 additions & 29 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,9 @@ def destroy
end

def omniauth_callback
# Get access tokens from the server
access_token = request.env["omniauth.auth"]
if Teacher.validate_access_token(access_token)
# Tell them to register.
user = Teacher.user_from_omniauth(access_token)
# Access_token is used to authenticate request made from the Rails application to the server
token = access_token.credentials.token
# Refresh_token to request new access_token
# Note: Refresh_token is only sent once during the first request
refresh_token = access_token.credentials.refresh_token
setTokens(token, refresh_token, user)
auth_info = request.env["omniauth.auth"]
if Teacher.validate_access_token(auth_info)
user = Teacher.user_from_omniauth(auth_info)
user.last_session_at = Time.zone.now
user.save!
log_in(user)
Expand All @@ -34,22 +26,4 @@ def omniauth_callback
def omniauth_failure
redirect_to root_url, alert: "Login failed"
end

private
def setTokens(token, refresh_token, user)
case params[:provider]
when "google_oauth2"
user.google_token = token
user.google_refresh_token = refresh_token || user.google_refresh_token
when "microsoft_graph"
user.microsoft_token = token
user.microsoft_refresh_token = refresh_token || user.microsoft_refresh_token
when "discourse"
user.snap_token = token
user.snap_refresh_token = refresh_token || user.snap_refresh_token
when "clever"
user.clever_token = token
user.clever_refresh_token = refresh_token || user.clever_refresh_token
end
end
end
Loading