Merge pull request #920 from codecombat/master

Merge master into production
This commit is contained in:
Michael Schmatz 2014-04-25 11:19:43 -07:00
commit daca71786a
7 changed files with 43 additions and 60 deletions

View file

@ -7,22 +7,21 @@ storage = require 'lib/storage'
module.exports = LinkedInHandler = class LinkedInHandler extends CocoClass
constructor: ->
super()
subscriptions:
'linkedin-loaded':'onLinkedInLoaded'
onLinkedInLoaded: (e) =>
'linkedin-loaded': 'onLinkedInLoaded'
onLinkedInLoaded: (e) ->
IN.Event.on IN, "auth", @onLinkedInAuth
onLinkedInAuth: (e) => console.log "Authorized with LinkedIn"
constructEmployerAgreementObject: (cb) =>
IN.API.Profile("me")
.fields(["positions","public-profile-url","id","first-name","last-name","email-address"])
.error(cb)
.result (profiles) =>
cb null, profiles.values[0]
destroy: ->
super()

View file

@ -30,10 +30,11 @@ UserSchema = c.object {},
artisanNews: { $ref: '#/definitions/emailSubscription' }
diplomatNews: { $ref: '#/definitions/emailSubscription' }
scribeNews: { $ref: '#/definitions/emailSubscription' }
# notifications
anyNotes: { $ref: '#/definitions/emailSubscription' } # overrides any other notifications settings
recruitNotes: { $ref: '#/definitions/emailSubscription' }
employerNotes: { $ref: '#/definitions/emailSubscription' }
# server controlled
permissions: c.array {'default': []}, c.shortString()
@ -53,7 +54,7 @@ UserSchema = c.object {},
#Internationalization stuff
preferredLanguage: {type: 'string', default: 'en', 'enum': c.getLanguageCodeArray()}
signedCLA: c.date({title: 'Date Signed the CLA'})
wizard: c.object {},
colorConfig: c.object {additionalProperties: c.colorConfig()}
@ -112,8 +113,8 @@ UserSchema = c.object {},
signedEmployerAgreement: c.object {},
linkedinID: c.shortString {title:"LinkedInID", description: "The user's LinkedIn ID when they signed the contract."}
date: c.date {title: "Date signed employer agreement"}
data: c.object
data: c.object {description: "Cached LinkedIn data slurped from profile."}
c.extendBasicProperties UserSchema, 'user'

View file

@ -63,6 +63,6 @@ block modal-footer
button.btn.btn-primary(id="contract-agreement-button") I agree
else
.modal-footer.linkedin
| Thanks #{firstName}! You've already agreed to the contract.
| Thanks! You've already agreed to the contract.

View file

@ -28,7 +28,7 @@ module.exports = class EmployersView extends View
getRenderData: ->
c = super()
c.candidates = @candidates.models
userPermissions = me.get('permissions') || []
userPermissions = me.get('permissions') ? []
c.isEmployer = _.contains userPermissions, "employer"
c.moment = moment

View file

@ -10,27 +10,27 @@ module.exports = class EmployerSignupView extends View
template: template
closeButton: true
subscriptions:
"server-error": "onServerError"
"created-user-without-reload": "linkedInAuth"
events:
"click #contract-agreement-button": "agreeToContract"
constructor: (options) ->
super(options)
@authorizedWithLinkedIn = IN?.User?.isAuthorized()
window.tracker?.trackEvent 'Started Employer Signup'
@reloadWhenClosed = false
window.contractCallback = =>
window.contractCallback = =>
@authorizedWithLinkedIn = IN?.User?.isAuthorized()
@render()
onServerError: (e) ->
onServerError: (e) ->
@disableModalInProgress(@$el)
afterInsert: ->
super()
linkedInButtonParentElement = document.getElementById("linkedInAuthButton")?.parentNode
@ -38,16 +38,14 @@ module.exports = class EmployerSignupView extends View
IN.parse()
if me.get('anonymous')
$(".IN-widget").get(0).addEventListener('click', @createAccount, true)
console.log "Parsed linkedin button element!"
console.log linkedInButtonParentElement
getRenderData: ->
context = super()
context.userIsAuthorized = @authorizedWithLinkedIn
context.userHasSignedContract = "employer" in me.get("permissions")
context.userIsAnonymous = context.me.get('anonymous')
context
agreeToContract: ->
application.linkedinHandler.constructEmployerAgreementObject (err, profileData) =>
if err? then return handleAgreementFailure err
@ -57,54 +55,37 @@ module.exports = class EmployerSignupView extends View
type: "POST"
success: @handleAgreementSuccess
error: @handleAgreementFailure
handleAgreementSuccess: (result) ->
window.tracker?.trackEvent 'Employer Agreed to Contract'
me.fetch()
window.location.reload()
handleAgreementFailure: (error) ->
alert "There was an error signing the contract. Please contact team@codecombat.com with this error: #{error.responseText}"
createAccount: (e) =>
window.tracker?.trackEvent 'Finished Employer Signup'
console.log "Tried to create account!"
e.stopPropagation()
forms.clearFormAlerts(@$el)
userObject = forms.formToObject @$el
delete userObject.subscribe
for key, val of me.attributes when key in ["preferredLanguage", "testGroupNumber", "dateCreated", "wizardColor1", "name", "music", "volume", "emails"]
userObject[key] ?= val
subscribe = true
#TODO: Enable all email subscriptions
userObject.emails ?= {}
userObject.emails.generalNews ?= {}
userObject.emails.generalNews.enabled = subscribe
userObject.emails.employerNotes = {enabled: true}
res = tv4.validateMultiple userObject, User.schema
return forms.applyErrorsToForm(@$el, res.errors) unless res.valid
window.tracker?.trackEvent 'Finished Signup'
@enableModalInProgress(@$el)
auth.createUserWithoutReload userObject, null
console.log "Authorizing with linkedin"
IN.User.authorize(@recordUserDetails, @)
linkedInAuth: (e) =>
IN.User.authorize @render, @
linkedInAuth: (e) ->
me.fetch()
@reloadWhenClosed = true
recordUserDetails: (e) =>
#TODO: refactor this out
@render()
destroy: ->
reloadWhenClosed = @reloadWhenClosed
super()
if reloadWhenClosed
window.location.reload()

View file

@ -29,7 +29,7 @@ UserSchema.post('init', ->
UserSchema.methods.isAdmin = ->
p = @get('permissions')
return p and 'admin' in p
emailNameMap =
generalNews: 'announcement'
adventurerNews: 'tester'
@ -39,20 +39,20 @@ emailNameMap =
diplomatNews: 'translator'
ambassadorNews: 'support'
anyNotes: 'notification'
UserSchema.methods.setEmailSubscription = (newName, enabled) ->
oldSubs = _.clone @get('emailSubscriptions')
if oldSubs and oldName = emailNameMap[newName]
oldSubs = (s for s in oldSubs when s isnt oldName)
oldSubs.push(oldName) if enabled
@set('emailSubscriptions', oldSubs)
newSubs = _.clone(@get('emails') or _.cloneDeep(jsonschema.properties.emails.default))
newSubs[newName] ?= {}
newSubs[newName].enabled = enabled
@set('emails', newSubs)
@newsSubsChanged = true if newName in mail.NEWS_GROUPS
UserSchema.methods.isEmailSubscriptionEnabled = (newName) ->
emails = @get 'emails'
if not emails
@ -74,10 +74,10 @@ UserSchema.statics.updateMailChimp = (doc, callback) ->
newGroups = []
for [mailchimpEmailGroup, emailGroup] in _.zip(mail.MAILCHIMP_GROUPS, mail.NEWS_GROUPS)
newGroups.push(mailchimpEmailGroup) if doc.isEmailSubscriptionEnabled(emailGroup)
if (not existingProps) and newGroups.length is 0
return callback?() # don't add totally unsubscribed people to the list
params = {}
params.id = mail.MAILCHIMP_LIST_ID
params.email = if existingProps then {leid:existingProps.leid} else {email:doc.get('email')}
@ -113,7 +113,7 @@ UserSchema.pre('save', (next) ->
recipient:
address: @get 'email'
sendwithus.api.send data, (err, result) ->
log.error 'error', err, 'result', result if err
log.error "sendwithus post-save error: #{err}, result: #{result}" if err
next()
)

View file

@ -232,6 +232,7 @@ UserHandler = class UserHandler extends Handler
return @sendDatabaseError(res, err) if err
documents = (LevelSessionHandler.formatEntity(req, doc) for doc in documents)
@sendSuccess(res, documents)
agreeToEmployerAgreement: (req, res) ->
userIsAnonymous = req.user?.get('anonymous')
if userIsAnonymous then return errors.unauthorized(res, "You need to be logged in to agree to the employer agreeement.")
@ -244,19 +245,20 @@ UserHandler = class UserHandler extends Handler
return errors.conflict(res, "You already have signed the agreement!")
#TODO: Search for the current position
employerAt = _.filter(profileData.positions.values,"isCurrent")[0]?.company.name ? "Not available"
signedEmployerAgreement =
signedEmployerAgreement =
linkedinID: profileData.id
date: new Date()
data: profileData
updateObject =
updateObject =
"employerAt": employerAt
"signedEmployerAgreement": signedEmployerAgreement
$push: "permissions":'employer'
User.update {"_id": req.user.id}, updateObject, (err, result) =>
if err? then return errors.serverError(res, "There was an issue updating the user object to reflect employer status: #{err}")
res.send({"message": "The agreement was successful."})
res.end()
getCandidates: (req, res) ->
authorized = req.user.isAdmin() or ('employer' in req.user.get('permissions'))
since = (new Date((new Date()) - 2 * 30.4 * 86400 * 1000)).toISOString()