mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 17:02:18 -05:00
Merge pull request #514 from codecombat/master
Merge database/ladder fixes into production
This commit is contained in:
commit
09e2ed3089
8 changed files with 29 additions and 21 deletions
|
@ -66,7 +66,7 @@ module.exports = class SettingsView extends View
|
|||
c.photos = me.gravatarPhotoURLs()
|
||||
c.chosenPhoto = me.getPhotoURL()
|
||||
c.subs = {}
|
||||
c.subs[sub] = 1 for sub in c.me.get('emailSubscriptions') or ['announcement', 'tester', 'level_creator', 'developer']
|
||||
c.subs[sub] = 1 for sub in c.me.get('emailSubscriptions') or ['announcement', 'notification', 'tester', 'level_creator', 'developer']
|
||||
c
|
||||
|
||||
getSubscriptions: ->
|
||||
|
@ -88,7 +88,7 @@ module.exports = class SettingsView extends View
|
|||
if res?
|
||||
forms.applyErrorsToForm(@$el, res)
|
||||
return
|
||||
|
||||
|
||||
return unless me.hasLocalChanges()
|
||||
|
||||
res = me.save()
|
||||
|
|
|
@ -49,8 +49,9 @@ module.exports = class SignupModalView extends View
|
|||
userObject.emailSubscriptions ?= []
|
||||
if subscribe
|
||||
userObject.emailSubscriptions.push 'announcement' unless 'announcement' in userObject.emailSubscriptions
|
||||
userObject.emailSubscriptions.push 'notification' unless 'notification' in userObject.emailSubscriptions
|
||||
else
|
||||
userObject.emailSubscriptions = _.without (userObject.emailSubscriptions ? []), 'announcement'
|
||||
userObject.emailSubscriptions = _.without (userObject.emailSubscriptions ? []), 'announcement', 'notification'
|
||||
res = tv4.validateMultiple userObject, User.schema.attributes
|
||||
return forms.applyErrorsToForm(@$el, res.errors) unless res.valid
|
||||
window.tracker?.trackEvent 'Finished Signup'
|
||||
|
|
|
@ -140,7 +140,6 @@ LevelHandler = class LevelHandler extends Handler
|
|||
query = Session
|
||||
.find(sessionsQueryParameters)
|
||||
.limit(req.query.limit)
|
||||
.sort(sortParameters)
|
||||
.select(selectProperties.join ' ')
|
||||
|
||||
query.exec (err, resultSessions) =>
|
||||
|
|
|
@ -7,7 +7,7 @@ class LevelSessionHandler extends Handler
|
|||
modelClass: LevelSession
|
||||
editableProperties: ['multiplayer', 'players', 'code', 'completed', 'state',
|
||||
'levelName', 'creatorName', 'levelID', 'screenshot',
|
||||
'chat', 'teamSpells','submitted']
|
||||
'chat', 'teamSpells', 'submitted', 'unsubscribed']
|
||||
|
||||
getByRelationship: (req, res, args...) ->
|
||||
return @sendNotFoundError(res) unless args.length is 2 and args[1] is 'active'
|
||||
|
|
|
@ -122,7 +122,7 @@ _.extend LevelSessionSchema.properties,
|
|||
|
||||
standardDeviation:
|
||||
type:'number'
|
||||
default:25/3
|
||||
default: 25/3
|
||||
minimum: 0
|
||||
|
||||
totalScore:
|
||||
|
@ -139,25 +139,29 @@ _.extend LevelSessionSchema.properties,
|
|||
|
||||
submittedCode:
|
||||
type: 'object'
|
||||
|
||||
|
||||
unsubscribed:
|
||||
type: 'boolean'
|
||||
description: 'Whether the player has opted out of receiving email updates about ladder rankings for this session.'
|
||||
|
||||
numberOfWinsAndTies:
|
||||
type: 'number'
|
||||
default: 0
|
||||
numberOfLosses:
|
||||
type: 'number'
|
||||
default: 0
|
||||
|
||||
|
||||
scoreHistory:
|
||||
type: 'array'
|
||||
title: 'Score History'
|
||||
description: 'A list of objects representing the score history of a session'
|
||||
items:
|
||||
items:
|
||||
title: 'Score History Point'
|
||||
description: 'An array with the format [unix timestamp, totalScore]'
|
||||
type: 'array'
|
||||
items:
|
||||
type: 'number'
|
||||
|
||||
|
||||
|
||||
matches:
|
||||
type: 'array'
|
||||
|
|
|
@ -42,8 +42,8 @@ handleLadderUpdate = (req, res) ->
|
|||
for daysAgo in emailDays
|
||||
# Get every session that was submitted in a 5-minute window after the time.
|
||||
startTime = getTimeFromDaysAgo daysAgo
|
||||
endTime = startTime + 5 * 60 * 1000
|
||||
#endTime = startTime + 1 * 60 * 60 * 1000
|
||||
#endTime = startTime + 5 * 60 * 1000
|
||||
endTime = startTime + 1 * 60 * 60 * 1000 # Debugging: make sure there's something to send
|
||||
findParameters = {submitted: true, submitDate: {$gt: new Date(startTime), $lte: new Date(endTime)}}
|
||||
# TODO: think about putting screenshots in the email
|
||||
selectString = "creator team levelName levelID totalScore matches submitted submitDate numberOfWinsAndTies numberOfLosses"
|
||||
|
@ -53,16 +53,19 @@ handleLadderUpdate = (req, res) ->
|
|||
do (daysAgo) ->
|
||||
query.exec (err, results) ->
|
||||
if err
|
||||
log.error "Couldn't fetch ladder updates for", findParameters, "\nError: ", err
|
||||
log.error "Couldn't fetch ladder updates for #{findParameters}\nError: #{err}"
|
||||
return errors.serverError res, "Ladder update email query failed: #{JSON.stringify(err)}"
|
||||
log.info "Found #{results.length} ladder sessions to email updates about for #{daysAgo} day(s) ago."
|
||||
sendLadderUpdateEmail result, daysAgo for result in results
|
||||
|
||||
sendLadderUpdateEmail = (session, daysAgo) ->
|
||||
User.findOne({_id: session.creator}).select("name email firstName lastName emailSubscriptions preferredLanguage").lean().exec (err, user) ->
|
||||
if err
|
||||
log.error "Couldn't find user for", session.creator, "from session", session._id
|
||||
log.error "Couldn't find user for #{session.creator} from session #{session._id}"
|
||||
return
|
||||
if not user.email or not ('notification' in user.emailSubscriptions)
|
||||
log.info "Not sending email to #{user.email} #{user.name} because they only want emails about #{user.emailSubscriptions}"
|
||||
return
|
||||
return unless user.email and 'notification' in user.emailSubscriptions
|
||||
name = if user.firstName and user.lastName then "#{user.firstName} #{user.lastName}" else user.name
|
||||
name = "Wizard" if not name or name is "Anoner"
|
||||
|
||||
|
@ -72,7 +75,7 @@ sendLadderUpdateEmail = (session, daysAgo) ->
|
|||
email_id: sendwithus.templates.ladder_update_email
|
||||
recipient:
|
||||
#address: user.email
|
||||
address: 'nick@codecombat.com'
|
||||
address: 'nick@codecombat.com' # Debugging
|
||||
name: name
|
||||
email_data:
|
||||
name: name
|
||||
|
@ -85,8 +88,9 @@ sendLadderUpdateEmail = (session, daysAgo) ->
|
|||
ladder_url: "http://codecombat.com/play/ladder/#{session.levelID}#my-matches"
|
||||
defeat: defeatContext
|
||||
victory: victoryContext
|
||||
log.info "Sending ladder update email to #{context.recipient.address} with #{context.email_data.wins} wins and #{context.email_data.losses} since #{daysAgo} day(s) ago."
|
||||
sendwithus.api.send context, (err, result) ->
|
||||
log.error "Error sending ladder update email:", err, 'result', result if err
|
||||
log.error "Error sending ladder update email: #{err} with result #{result}" if err
|
||||
|
||||
# Fetch the most recent defeat and victory, if there are any.
|
||||
# (We could look at strongest/weakest, but we'd have to fetch everyone, or denormalize more.)
|
||||
|
|
|
@ -11,4 +11,4 @@ options = { DEBUG: not config.isProduction }
|
|||
module.exports.api = new sendwithusAPI swuAPIKey, options
|
||||
module.exports.templates =
|
||||
welcome_email: 'utnGaBHuSU4Hmsi7qrAypU'
|
||||
ladder_update_email: 'Xq3vSbDHXcjXfje7n2e7Eb'
|
||||
ladder_update_email: 'JzaZxf39A4cKMxpPZUfWy4'
|
||||
|
|
|
@ -19,7 +19,7 @@ UserSchema = c.object {},
|
|||
music: {type: 'boolean', default: true}
|
||||
#autocastDelay, or more complex autocast options? I guess I'll see what I need when trying to hook up Scott's suggested autocast behavior
|
||||
|
||||
emailSubscriptions: c.array {uniqueItems: true, 'default': ['announcement']}, {'enum': emailSubscriptions}
|
||||
emailSubscriptions: c.array {uniqueItems: true, 'default': ['announcement', 'notification']}, {'enum': emailSubscriptions}
|
||||
|
||||
# server controlled
|
||||
permissions: c.array {'default': []}, c.shortString()
|
||||
|
@ -29,7 +29,7 @@ UserSchema = c.object {},
|
|||
mailChimp: {type: 'object'}
|
||||
hourOfCode: {type: 'boolean'}
|
||||
hourOfCodeComplete: {type: 'boolean'}
|
||||
|
||||
|
||||
emailLower: c.shortString()
|
||||
nameLower: c.shortString()
|
||||
passwordHash: {type: 'string', maxLength: 256}
|
||||
|
@ -40,7 +40,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()}
|
||||
|
|
Loading…
Reference in a new issue