Skip to content

Commit

Permalink
Merge pull request #30618 from code-dot-org/staging
Browse files Browse the repository at this point in the history
DTT (Staging > Test) [robo-dtt]
  • Loading branch information
deploy-code-org committed Sep 5, 2019
2 parents d539714 + 9115b15 commit a650244
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 321 deletions.
4 changes: 2 additions & 2 deletions dashboard/app/assets/stylesheets/teacher-panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
border-right: none;
border-radius: 10px 0 0 10px;

/* must appear in front of ProgressBubble */
z-index: 1000;
/* must appear in front of <Overlay/>, whose z-index is 1020 */
z-index: 1021;

.hide-handle,
.show-handle {
Expand Down
97 changes: 23 additions & 74 deletions dashboard/app/controllers/followers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,14 @@
# models).

class FollowersController < ApplicationController
before_action :authenticate_user!, except: [:student_user_new, :student_register]
before_action :load_section, only: [:create, :create_sync, :student_user_new, :student_register]
before_action :load_section

# join a section as a logged in student
def create
@section.add_student current_user

redirect_to redirect_url, notice: I18n.t('follower.added_teacher', name: @section.teacher.name)
end

# Remove enrollment in a section (as a student in the section).
def remove
@section = Section.find_by_code params[:section_code]
if @section
f = Follower.where(section: @section.id, student_user_id: current_user.id).first
end

unless @section && f
# TODO(asher): Change the alert message to section.
redirect_to root_path, alert: t(
'follower.error.section_not_found',
section_code: params[:section_code]
)
return
end

@teacher = @section.user

authorize! :destroy, f
f.delete
# Though in theory required, we are missing an email address for many teachers.
if @teacher && @teacher.email.present?
FollowerMailer.student_disassociated_notify_teacher(@teacher, current_user).deliver_now
end
teacher_name = @teacher ? @teacher.name : I18n.t('user.deleted_user')
redirect_to(
root_path,
notice: t(
'teacher.student_teacher_disassociated',
teacher_name: teacher_name,
section_code: params[:section_code]
)
)
end

# GET /join/XXXXXX
# GET /join/:section_code (section_code is optional)
def student_user_new
# Though downstream validations would raise an exception, we redirect to the admin directory to
# improve user experience.
if current_user && current_user.admin?
redirect_to admin_directory_path
return
end

if @section && @section.provider_managed?
provider = I18n.t(@section.login_type, scope: 'section.type')
redirect_to root_path, alert: I18n.t('follower.error.provider_managed_section', provider: provider)
return
end

@user = current_user || User.new

# if this is a picture or word section, redirect to the section login page so that the student
# does not have to type in the full URL
if @section && [Section::LOGIN_TYPE_PICTURE, Section::LOGIN_TYPE_WORD].include?(@section.login_type)
redirect_to controller: 'sections', action: 'show', id: @section.code
end

# render the default student_user_new view, which includes the section code form or sign up form
end

# POST /join/XXXXXX
# POST /join/:section_code
# join a section
def student_register
if current_user
Expand Down Expand Up @@ -115,19 +51,19 @@ def redirect_url
end

def load_section
p request.path
if params[:section_code].blank?
if request.path != student_user_new_path(section_code: params[:section_code])
# if user submitted the section form without a code /join
redirect_to student_user_new_path(section_code: params[:section_code])
end
return if params[:section_code].blank?

# Though downstream validations would raise an exception, we redirect to the admin directory to
# improve user experience.
if current_user&.admin?
redirect_to admin_directory_path
return
end

@section = Section.find_by_code(params[:section_code])
# Note that we treat the section as not being found if the section user
# (i.e., the teacher) does not exist (possibly soft-deleted) or is not a teacher
unless @section && @section.user && @section.user.teacher?
unless @section && @section.user&.teacher?
redirect_to redirect_url, alert: I18n.t('follower.error.section_not_found', section_code: params[:section_code])
return
end
Expand All @@ -136,5 +72,18 @@ def load_section
redirect_to redirect_url, alert: I18n.t('follower.error.cant_join_own_section')
return
end

# Redirect and provide an error for provider-managed sections.
if @section&.provider_managed?
provider = I18n.t(@section.login_type, scope: 'section.type')
redirect_to root_path, alert: I18n.t('follower.error.provider_managed_section', provider: provider)
return
end

# If this is a picture or word section, redirect to the section login page so that the student
# does not have to type in the full URL.
if [Section::LOGIN_TYPE_PICTURE, Section::LOGIN_TYPE_WORD].include?(@section&.login_type)
redirect_to controller: 'sections', action: 'show', id: @section.code
end
end
end
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module RaceInterstitialHelper
# Determine whether or not to show the race interstitial popup to a user
def self.show_race_interstitial?(user, request_ip = nil)
def self.show?(user)
return false if user.nil?
return false if user.races
return false if user.teacher?
return false if user.under_13?
return false if user.account_age_days < 7

# Restrict to cases where we can successfully geolocate to the US
return false if request_ip.nil?
location = Geocoder.search(request_ip).first
return false if user.current_sign_in_ip.nil?
location = Geocoder.search(user.current_sign_in_ip).first
return false unless location
return false if location.country_code.to_s.downcase != 'us'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module SchoolInfoInterstitialHelper
def self.show_school_info_interstitial?(user)
def self.show?(user)
return false if user.nil?
return false unless user.teacher?

return false if user.account_age_days < 7
Expand All @@ -25,7 +26,8 @@ def self.show_school_info_interstitial?(user)
# Show the school info confirmation dialog when a teacher has either completely
# filled out the school info interstitial for a US public, private, or charter school
# or confirmed current school over a year ago.
def self.show_school_info_confirmation_dialog?(user)
def self.show_confirmation_dialog?(user)
return false if user.nil?
return false unless user.teacher?

return false if user.user_school_infos.empty?
Expand Down
34 changes: 0 additions & 34 deletions dashboard/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
require 'digest/md5'
require 'cdo/aws/metrics'
require 'cdo/user_helpers'
require 'cdo/race_interstitial_helper'
require 'school_info_interstitial_helper'
require 'sign_up_tracking'

Expand Down Expand Up @@ -229,7 +228,6 @@ class User < ActiveRecord::Base

belongs_to :school_info
accepts_nested_attributes_for :school_info, reject_if: :preprocess_school_info
validates_presence_of :school_info, unless: :school_info_optional?

has_many :user_school_infos
after_save :update_and_add_users_school_infos, if: :school_info_id_changed?
Expand Down Expand Up @@ -320,11 +318,6 @@ def complete_school_info
end
end

# Not deployed to everyone, so we don't require this for anybody, yet
def school_info_optional?
true # update if/when A/B test is done and accepted
end

# Most recently created user_school_info referring to a complete school_info entry
def last_complete_user_school_info
user_school_infos.
Expand Down Expand Up @@ -1503,16 +1496,6 @@ def get_active_experiment_names
Experiment.get_all_enabled(user: self).pluck(:name)
end

def advertised_scripts
[
Script.hoc_2014_script, Script.frozen_script, Script.infinity_script,
Script.flappy_script, Script.playlab_script, Script.artist_script,
Script.course1_script, Script.course2_script, Script.course3_script,
Script.course4_script, Script.twenty_hour_script, Script.starwars_script,
Script.starwars_blocks_script, Script.minecraft_script
]
end

def in_progress_and_completed_scripts
user_scripts.compact.reject do |user_script|
user_script.script.nil?
Expand Down Expand Up @@ -1676,10 +1659,6 @@ def last_joined_section
Follower.where(student_user: self).order(created_at: :desc).first.try(:section)
end

def all_advertised_scripts_completed?
advertised_scripts.all? {|script| completed?(script)}
end

def completed?(script)
user_script = user_scripts.where(script_id: script.id).first
return false unless user_script
Expand Down Expand Up @@ -2073,19 +2052,6 @@ def show_census_teacher_banner?
teacher? && users_school && (next_census_display.nil? || Date.today >= next_census_display.to_date)
end

def show_race_interstitial?(ip = nil)
ip_to_check = ip || current_sign_in_ip
RaceInterstitialHelper.show_race_interstitial?(self, ip_to_check)
end

def show_school_info_confirmation_dialog?
SchoolInfoInterstitialHelper.show_school_info_confirmation_dialog?(self)
end

def show_school_info_interstitial?
SchoolInfoInterstitialHelper.show_school_info_interstitial?(self)
end

# Removes PII and other information from the user and marks the user as having been purged.
# WARNING: This (permanently) destroys data and cannot be undone.
# WARNING: This does not purge the user, only marks them as such.
Expand Down
2 changes: 1 addition & 1 deletion dashboard/app/views/courses/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

%link{:href=>'/shared/css/course-explorer.css', :rel=>'stylesheet'}

- if (current_user && current_user.show_race_interstitial?) || @force_race_interstitial
- if RaceInterstitialHelper.show?(current_user) || @force_race_interstitial
= render partial: 'layouts/race_interstitial'

%script{src: minifiable_asset_path('js/courses/index.js'), data: {courses: courses_data.to_json}}
Expand Down
6 changes: 3 additions & 3 deletions dashboard/app/views/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@


-# Student modal
- if (current_user && current_user.show_race_interstitial?) || @force_race_interstitial
- if RaceInterstitialHelper.show?(current_user) || @force_race_interstitial
= render partial: 'layouts/race_interstitial'

-# Teacher modals
- if current_user && current_user.teacher? && !current_user.accepted_latest_terms?
= render partial: 'layouts/terms_interstitial'
- elsif (current_user && current_user.show_school_info_confirmation_dialog?) || @force_school_info_confirmation_dialog
- elsif SchoolInfoInterstitialHelper.show_confirmation_dialog?(current_user) || @force_school_info_confirmation_dialog
= render partial: 'layouts/school_info_confirmation_dialog'
- elsif (current_user && current_user.show_school_info_interstitial?) || @force_school_info_interstitial
- elsif SchoolInfoInterstitialHelper.show?(current_user) || @force_school_info_interstitial
= render partial: 'layouts/school_info_interstitial', locals: {show_header: false, user: current_user, form_name: "user[school_info_attributes]"}

- if current_user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
.row
.col-lg-12
- join_route_options = {controller: 'pd/workshop_enrollment', action: 'join_session', session_code: @session.code}
= link_to 'My name is not on this list.', join_route_options
= link_to join_route_options do
%button{class: "btn btn-primary", style: "font-size: 18px"}
My name is not on this list
2 changes: 1 addition & 1 deletion dashboard/app/views/scripts/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
%script{ src: minifiable_asset_path('js/scripts/show.js'), data: {scriptoverview: scriptOverviewData.to_json }}


- if (current_user && current_user.show_race_interstitial?) || @force_race_interstitial
- if RaceInterstitialHelper.show?(current_user) || @force_race_interstitial
= render partial: 'layouts/race_interstitial'

= render partial: 'shared/check_admin'
Expand Down
3 changes: 0 additions & 3 deletions dashboard/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,6 @@

get '/weblab/host', to: 'weblab_host#index'

resources :followers, only: [:create]
post '/followers/remove', to: 'followers#remove', as: 'remove_follower'

get '/join(/:section_code)', to: 'followers#student_user_new', as: 'student_user_new'
post '/join(/:section_code)', to: 'followers#student_register', as: 'student_register'

Expand Down

0 comments on commit a650244

Please sign in to comment.