Don't allow conversion to student without a ClassCode

Fix i18n and tests
This commit is contained in:
phoenixeliot 2016-08-01 16:40:48 -07:00
parent bd45f75bc0
commit 5f560f3e7d
6 changed files with 16 additions and 5 deletions

View file

@ -1351,6 +1351,7 @@
update_account_students_warning: "Warning: You will not be able to manage any classes that you have previously created or create new classes."
update_account_remain_student: "Remain a Student"
update_account_update_student: "Update to Student"
need_a_class_code: "You'll need a Class Code for the class you're joining:"
update_account_not_sure: "Not sure which one to choose? Email"
update_account_confirm_update_student: "Are you sure you want to update your account to a Student experience?"
update_account_confirm_update_student2: "You will not be able to manage any classes that you have previously created or create new classes. Your previously created classes will be removed from CodeCombat and cannot be restored."

View file

@ -73,6 +73,9 @@ block content
if me.isStudent()
button.remain-student-btn.btn.btn-navy(data-i18n="courses.update_account_remain_student")
else
label
span(data-i18n="courses.need_a_class_code")
input(name='classCode')
button.update-student-btn.btn.btn-forest(data-i18n="courses.update_account_update_student")
br
br

View file

@ -2,6 +2,7 @@ errors = require 'core/errors'
RootView = require 'views/core/RootView'
template = require 'templates/courses/courses-update-account-view'
AuthModal = require 'views/core/AuthModal'
JoinClassModal = require 'views/courses/JoinClassModal'
{logoutUser, me} = require('core/auth')
module.exports = class CoursesUpdateAccountView extends RootView
@ -41,8 +42,11 @@ module.exports = class CoursesUpdateAccountView extends RootView
@becomeStudent(e.target, 'Remain student')
onClickUpdateStudentButton: (e) ->
return unless window.confirm($.i18n.t('courses.update_account_confirm_update_student') + '\n\n' + $.i18n.t('courses.update_account_confirm_update_student2'))
@becomeStudent(e.target, 'Update student')
joinClassModal = new JoinClassModal { classCode: @$('input[name="classCode"]').val() }
@openModalView joinClassModal
@listenTo joinClassModal, 'join:success', => @becomeStudent(e.target, 'Update student')
# return unless window.confirm($.i18n.t('courses.update_account_confirm_update_student') + '\n\n' + $.i18n.t('courses.update_account_confirm_update_student2'))
# @becomeStudent(e.target, 'Update student')
becomeStudent: (targetElem, trackEventMsg) ->
$(targetElem).prop('disabled', true)

View file

@ -10,7 +10,7 @@ module.exports = class JoinClassModal extends ModalView
events:
'click .join-class-btn': 'onClickJoinClassButton'
initialize: ({ @classCode }) ->
initialize: ({ @classCode } = {}) ->
@classroom = new Classroom()
@teacher = new User()
jqxhr = @supermodel.trackRequest @classroom.fetchByCode(@classCode)

View file

@ -22,7 +22,7 @@ co = require 'co'
module.exports =
fetchByCode: wrap (req, res, next) ->
code = req.query.code
return next() unless code
return next() unless req.query.hasOwnProperty('code')
classroom = yield Classroom.findOne({ code: code.toLowerCase().replace(RegExp(' ', 'g') , '') }).select('name ownerID aceConfig')
if not classroom
log.debug("classrooms.fetchByCode: Couldn't find Classroom with code: #{code}")

View file

@ -24,8 +24,9 @@ describe '/courses/update-account', ->
it 'shows update to teacher button', ->
expect(@view.$el.find('.update-teacher-btn').length).toEqual(1)
it 'shows update to student button', ->
it 'shows update to student button and classCode input', ->
expect(@view.$el.find('.update-student-btn').length).toEqual(1)
expect(@view.$el.find('input[name="classCode"]').length).toEqual(1)
describe 'when logged in as student', ->
beforeEach (done) ->
@ -39,6 +40,7 @@ describe '/courses/update-account', ->
it 'shows remain a student button', ->
expect(@view.$el.find('.remain-student-btn').length).toEqual(1)
expect(@view.$el.find('input[name="classCode"]').length).toEqual(0)
it 'shows update to teacher button', ->
expect(@view.$el.find('.update-teacher-btn').length).toEqual(1)
@ -57,3 +59,4 @@ describe '/courses/update-account', ->
it 'shows update to student button', ->
expect(@view.$el.find('.update-student-btn').length).toEqual(1)
expect(@view.$el.find('input[name="classCode"]').length).toEqual(1)