mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Added a transactional email for when changes are made, to notify watchers.
This commit is contained in:
parent
ed0c7e1412
commit
8adca4a1da
5 changed files with 29 additions and 2 deletions
|
@ -60,6 +60,7 @@ class CocoModel extends Backbone.Model
|
|||
return result.errors unless result.valid
|
||||
|
||||
save: (attrs, options) ->
|
||||
@set 'editPath', document.location.pathname
|
||||
options ?= {}
|
||||
success = options.success
|
||||
options.success = (resp) =>
|
||||
|
|
|
@ -4,6 +4,8 @@ Grid = require 'gridfs-stream'
|
|||
errors = require './errors'
|
||||
log = require 'winston'
|
||||
Patch = require '../patches/Patch'
|
||||
User = require '../users/User'
|
||||
sendwithus = require '../sendwithus'
|
||||
|
||||
PROJECT = {original:1, name:1, version:1, description: 1, slug:1, kind: 1}
|
||||
FETCH_LIMIT = 200
|
||||
|
@ -293,6 +295,7 @@ module.exports = class Handler
|
|||
newDocument.save (err) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
@sendSuccess(res, @formatEntity(req, newDocument))
|
||||
@notifyWatchersOfChange(req.user, newDocument, req.body.editPath) if @modelClass.schema.is_patchable
|
||||
|
||||
if major?
|
||||
parentDocument.makeNewMinorVersion(updatedObject, major, done)
|
||||
|
@ -300,6 +303,27 @@ module.exports = class Handler
|
|||
else
|
||||
parentDocument.makeNewMajorVersion(updatedObject, done)
|
||||
|
||||
notifyWatchersOfChange: (editor, changedDocument, editPath) ->
|
||||
watchers = changedDocument.get('watchers') or []
|
||||
watchers = (w for w in watchers when not w.equals(editor.get('_id')))
|
||||
return unless watchers.length
|
||||
User.find({_id:{$in:watchers}}).select({email:1, name:1}).exec (err, watchers) =>
|
||||
for watcher in watchers
|
||||
@notifyWatcherOfChange editor, watcher, changedDocument, editPath
|
||||
|
||||
notifyWatcherOfChange: (editor, watcher, changedDocument, editPath) ->
|
||||
context =
|
||||
email_id: sendwithus.templates.change_made_notify_watcher
|
||||
recipient:
|
||||
address: watcher.get('email')
|
||||
name: watcher.get('name')
|
||||
email_data:
|
||||
doc_name: changedDocument.get('name') or '???'
|
||||
submitter_name: editor.get('name') or '???'
|
||||
doc_link: if editPath then "http://codecombat.com#{editPath}" else null
|
||||
commit_message: changedDocument.get('commitMessage')
|
||||
sendwithus.api.send context, (err, result) ->
|
||||
|
||||
makeNewInstance: (req) ->
|
||||
model = new @modelClass({})
|
||||
model.set 'watchers', [req.user.get('_id')] if @modelClass.schema.is_patchable
|
||||
|
|
|
@ -57,7 +57,8 @@ PatchHandler = class PatchHandler extends Handler
|
|||
onPostSuccess: (req, doc) ->
|
||||
log.error "Error sending patch created: could not find the loaded target on the patch object." unless doc.targetLoaded
|
||||
return unless doc.targetLoaded
|
||||
watchers = doc.targetLoaded.get('watchers')
|
||||
watchers = doc.targetLoaded.get('watchers') or []
|
||||
watchers = (w for w in watchers when not w.equals(editor.get('_id')))
|
||||
return unless watchers?.length
|
||||
User.find({_id:{$in:watchers}}).select({email:1, name:1}).exec (err, watchers) =>
|
||||
for watcher in watchers
|
||||
|
|
|
@ -15,3 +15,4 @@ module.exports.templates =
|
|||
welcome_email: 'utnGaBHuSU4Hmsi7qrAypU'
|
||||
ladder_update_email: 'JzaZxf39A4cKMxpPZUfWy4'
|
||||
patch_created: 'tem_xhxuNosLALsizTNojBjNcL'
|
||||
change_made_notify_watcher: 'tem_7KVkfmv9SZETb25dtHbUtG'
|
||||
|
|
|
@ -52,7 +52,7 @@ describe '/db/patch', ->
|
|||
body = JSON.parse(body)
|
||||
expect(res.statusCode).toBe(200)
|
||||
expect(body.length).toBe(1)
|
||||
done()
|
||||
done()
|
||||
|
||||
it 'allows you to set yourself as watching', (done) ->
|
||||
watchingURL = getURL("/db/article/#{articles[0]._id}/watch")
|
||||
|
|
Loading…
Reference in a new issue