From 409b1708916c9da5ce21a715c9b58c8b5e20e397 Mon Sep 17 00:00:00 2001 From: Matt Lott Date: Tue, 14 Jun 2016 16:44:51 -0700 Subject: [PATCH 1/4] Update inbound lead assignment splits --- scripts/updateCloseIoLeads.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/scripts/updateCloseIoLeads.js b/scripts/updateCloseIoLeads.js index 8d1edce15..7753fa320 100644 --- a/scripts/updateCloseIoLeads.js +++ b/scripts/updateCloseIoLeads.js @@ -57,7 +57,20 @@ const emailDelayMinutes = 27; const scriptStartTime = new Date(); const closeIoApiKey = process.argv[2]; // Automatic mails sent as API owners, first key assumed to be primary and gets 50% of the leads -const closeIoMailApiKeys = [process.argv[3], process.argv[3], process.argv[4], process.argv[5]]; +const closeIoMailApiKeys = [ + { + apiKey: process.argv[3], + weight: .7 + }, + { + apiKey: process.argv[4], + weight: .25 + }, + { + apiKey: process.argv[5], + weight: .05 + }, +]; const closeIoEuMailApiKey = process.argv[6]; const intercomAppIdApiKey = process.argv[7]; const intercomAppId = intercomAppIdApiKey.split(':')[0]; @@ -238,7 +251,14 @@ function isUSSchoolStatus(status) { function getEmailApiKey(leadStatus) { if (leadStatus === defaultEuLeadStatus) return closeIoEuMailApiKey; if (closeIoMailApiKeys.length < 0) return; - return closeIoMailApiKeys[Math.floor(Math.random() * closeIoMailApiKeys.length)]; + const weightedList = []; + for (let closeIoMailApiKey of closeIoMailApiKeys) { + const multiples = closeIoMailApiKey.weight * 100; + for (let i = 0; i < multiples; i++) { + weightedList.push(closeIoMailApiKey.apiKey); + } + } + return weightedList[Math.floor(Math.random() * weightedList.length)]; } function getRandomEmailTemplate(templates) { From 109de551857cc6f266f6204170ab241676aa38a6 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Tue, 14 Jun 2016 18:02:08 -0700 Subject: [PATCH 2/4] Stop unprocessing flag events when serializing the flag history so that flag history is properly deterministic again --- app/lib/world/world.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/lib/world/world.coffee b/app/lib/world/world.coffee index d62fe4bc2..070e9b143 100644 --- a/app/lib/world/world.coffee +++ b/app/lib/world/world.coffee @@ -364,8 +364,8 @@ module.exports = class World endFrame = @frames.length #console.log "... world serializing frames from", startFrame, "to", endFrame, "of", @totalFrames [transferableObjects, nontransferableObjects] = [0, 0] - delete flag.processed for flag in @flagHistory - o = {totalFrames: @totalFrames, maxTotalFrames: @maxTotalFrames, frameRate: @frameRate, dt: @dt, victory: @victory, userCodeMap: {}, trackedProperties: {}, flagHistory: @flagHistory, difficulty: @difficulty, scores: @getScores(), randomSeed: @randomSeed, picoCTFFlag: @picoCTFFlag} + serializedFlagHistory = (_.omit(_.clone(flag), 'processed') for flag in @flagHistory) + o = {totalFrames: @totalFrames, maxTotalFrames: @maxTotalFrames, frameRate: @frameRate, dt: @dt, victory: @victory, userCodeMap: {}, trackedProperties: {}, flagHistory: serializedFlagHistory, difficulty: @difficulty, scores: @getScores(), randomSeed: @randomSeed, picoCTFFlag: @picoCTFFlag} o.trackedProperties[prop] = @[prop] for prop in @trackedProperties or [] for thangID, methods of @userCodeMap From 9239d2a81bb4d75dca30c46b6bd14c9aa99a1a61 Mon Sep 17 00:00:00 2001 From: phoenixeliot Date: Wed, 15 Jun 2016 13:09:43 -0700 Subject: [PATCH 3/4] Fix text overflowing on teacher dashboard --- app/templates/courses/enrollments-view.jade | 26 ++++++++++--------- .../courses/restricted-to-students-view.jade | 7 ++--- .../courses/teacher-classes-view.jade | 7 ++--- .../teachers/restricted-to-teachers-view.jade | 7 ++--- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/templates/courses/enrollments-view.jade b/app/templates/courses/enrollments-view.jade index 15e77b330..babd88a79 100644 --- a/app/templates/courses/enrollments-view.jade +++ b/app/templates/courses/enrollments-view.jade @@ -5,19 +5,21 @@ block page_nav block content if me.isAnonymous() || (!me.isTeacher() && !view.classrooms.size()) - .access-restricted.container.text-center.m-y-3 - h5(data-i18n='teacher.access_restricted') - p(data-i18n='teacher.teacher_account_required') - if me.isAnonymous() - .login-button.btn.btn-lg.btn-primary(data-i18n='login.log_in') - a.btn.btn-lg.btn-primary-alt(href="/teachers/signup" data-i18n='teacher.create_teacher_account') - else - a.btn.btn-lg.btn-primary(href="/teachers/update-account" data-i18n="teachers_quote.convert_account_title") - button#logout-button.btn.btn-lg.btn-primary-alt(data-i18n="login.log_out") + .container + .access-restricted.container.text-center.m-y-3 + h5(data-i18n='teacher.access_restricted') + p(data-i18n='teacher.teacher_account_required') + if me.isAnonymous() + .login-button.btn.btn-lg.btn-primary(data-i18n='login.log_in') + a.btn.btn-lg.btn-primary-alt(href="/teachers/signup" data-i18n='teacher.create_teacher_account') + else + a.btn.btn-lg.btn-primary(href="/teachers/update-account" data-i18n="teachers_quote.convert_account_title") + button#logout-button.btn.btn-lg.btn-primary-alt(data-i18n="login.log_out") - .teacher-account-blurb.text-center.col-xs-6.col-xs-offset-3.m-y-3 - h5(data-i18n='teacher.what_is_a_teacher_account') - p(data-i18n='teacher.teacher_account_explanation') + .container + .teacher-account-blurb.text-center.col-xs-6.col-xs-offset-3.m-y-3 + h5(data-i18n='teacher.what_is_a_teacher_account') + p(data-i18n='teacher.teacher_account_explanation') else if !me.isTeacher() diff --git a/app/templates/courses/restricted-to-students-view.jade b/app/templates/courses/restricted-to-students-view.jade index 9ffcb3909..6b4a48c59 100644 --- a/app/templates/courses/restricted-to-students-view.jade +++ b/app/templates/courses/restricted-to-students-view.jade @@ -17,6 +17,7 @@ block content button#logout-button.btn.btn-lg.btn-primary-alt(data-i18n="login.log_out") if me.isTeacher() - .teacher-account-blurb.text-center.col-xs-6.col-xs-offset-3.m-y-3 - h5(data-i18n='teacher.what_is_a_teacher_account') - p(data-i18n='teacher.teacher_account_explanation') + .container + .teacher-account-blurb.text-center.col-xs-6.col-xs-offset-3.m-y-3 + h5(data-i18n='teacher.what_is_a_teacher_account') + p(data-i18n='teacher.teacher_account_explanation') diff --git a/app/templates/courses/teacher-classes-view.jade b/app/templates/courses/teacher-classes-view.jade index 9946d300c..82e11e3b9 100644 --- a/app/templates/courses/teacher-classes-view.jade +++ b/app/templates/courses/teacher-classes-view.jade @@ -15,9 +15,10 @@ block content button.btn.btn-lg.btn-primary.update-teacher-btn(data-event-action="Teachers Classes Convert Teacher Account", data-i18n="teachers_quote.convert_account_title") button#logout-button.btn.btn-lg.btn-primary-alt(data-i18n="login.log_out") - .teacher-account-blurb.text-center.col-xs-6.col-xs-offset-3.m-y-3 - h5(data-i18n='teacher.what_is_a_teacher_account') - p(data-i18n='teacher.teacher_account_explanation') + .container + .teacher-account-blurb.text-center.col-xs-6.col-xs-offset-3.m-y-3 + h5(data-i18n='teacher.what_is_a_teacher_account') + p(data-i18n='teacher.teacher_account_explanation') else if !me.isTeacher() diff --git a/app/templates/teachers/restricted-to-teachers-view.jade b/app/templates/teachers/restricted-to-teachers-view.jade index 3bb07c1e5..a5c890f00 100644 --- a/app/templates/teachers/restricted-to-teachers-view.jade +++ b/app/templates/teachers/restricted-to-teachers-view.jade @@ -14,6 +14,7 @@ block content a.btn.btn-lg.btn-primary(href="/teachers/update-account" data-i18n="teachers_quote.convert_account_title") button#logout-button.btn.btn-lg.btn-primary-alt(data-i18n="login.log_out") - .teacher-account-blurb.text-center.col-xs-6.col-xs-offset-3.m-y-3 - h5(data-i18n='teacher.what_is_a_teacher_account') - p(data-i18n='teacher.teacher_account_explanation') \ No newline at end of file + .container + .teacher-account-blurb.text-center.col-xs-6.col-xs-offset-3.m-y-3 + h5(data-i18n='teacher.what_is_a_teacher_account') + p(data-i18n='teacher.teacher_account_explanation') From e841334c86ee47ca51c66d538576aedbdfce66e9 Mon Sep 17 00:00:00 2001 From: phoenixeliot Date: Tue, 14 Jun 2016 17:15:48 -0700 Subject: [PATCH 4/4] Fix join class modal (temporary hack) --- app/core/Router.coffee | 4 ++-- app/views/courses/CoursesView.coffee | 16 +++++++++++++++- app/views/courses/JoinClassModal.coffee | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/core/Router.coffee b/app/core/Router.coffee index 3ddbbf206..7030d7df6 100644 --- a/app/core/Router.coffee +++ b/app/core/Router.coffee @@ -69,8 +69,8 @@ module.exports = class CocoRouter extends Backbone.Router 'contribute/diplomat': go('contribute/DiplomatView') 'contribute/scribe': go('contribute/ScribeView') - 'courses': go('courses/CoursesView', { studentsOnly: true }) - 'Courses': go('courses/CoursesView', { studentsOnly: true }) + 'courses': go('courses/CoursesView') + 'Courses': go('courses/CoursesView') 'courses/students': redirect('/courses') 'courses/teachers': redirect('/teachers/classes') 'courses/purchase': redirect('/teachers/licenses') diff --git a/app/views/courses/CoursesView.coffee b/app/views/courses/CoursesView.coffee index e4caa6662..6079838c8 100644 --- a/app/views/courses/CoursesView.coffee +++ b/app/views/courses/CoursesView.coffee @@ -40,7 +40,7 @@ module.exports = class CoursesView extends RootView @courseInstances = new CocoCollection([], { url: "/db/user/#{me.id}/course_instances", model: CourseInstance}) @courseInstances.comparator = (ci) -> return ci.get('classroomID') + ci.get('courseID') @listenToOnce @courseInstances, 'sync', @onCourseInstancesLoaded - @supermodel.loadCollection(@courseInstances) + @supermodel.loadCollection(@courseInstances, { cache: false }) @classrooms = new CocoCollection([], { url: "/db/classroom", model: Classroom }) @supermodel.loadCollection(@classrooms, { data: {memberID: me.id}, cache: false }) @ownedClassrooms = new Classrooms() @@ -59,6 +59,11 @@ module.exports = class CoursesView extends RootView @listenTo @hero, 'all', -> @render() window.tracker?.trackEvent 'Students Loaded', category: 'Students', ['Mixpanel'] + + afterInsert: -> + super() + unless me.isStudent() or (@classCodeQueryVar and not me.isTeacher()) + @onClassLoadError() onCourseInstancesLoaded: -> map = {} @@ -135,12 +140,21 @@ module.exports = class CoursesView extends RootView else modal = new JoinClassModal({ @classCode }) @openModalView modal + @listenTo modal, 'error', @onClassLoadError @listenTo modal, 'join:success', @onJoinClassroomSuccess @listenTo modal, 'join:error', @onJoinClassroomError + @listenToOnce modal, 'hidden', -> + unless me.isStudent() + @onClassLoadError() @listenTo modal, 'hidden', -> @state = null @renderSelectors '#join-class-form' + # Super hacky way to patch users being able to join class while hiding /courses from others + onClassLoadError: -> + _.defer -> + application.router.routeDirectly('courses/RestrictedToStudentsView') + onJoinClassroomError: (classroom, jqxhr, options) -> @state = null if jqxhr.status is 422 diff --git a/app/views/courses/JoinClassModal.coffee b/app/views/courses/JoinClassModal.coffee index 78b3ad161..35cb4d58c 100644 --- a/app/views/courses/JoinClassModal.coffee +++ b/app/views/courses/JoinClassModal.coffee @@ -16,6 +16,8 @@ module.exports = class JoinClassModal extends ModalView jqxhr = @supermodel.trackRequest @classroom.fetchByCode(@classCode) unless me.get('emailVerified') @supermodel.trackRequest $.post("/db/user/#{me.id}/request-verify-email") + @listenTo @classroom, 'error', -> + @trigger('error') @listenTo @classroom, 'sync', -> @render @listenTo @classroom, 'join:success', ->