mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-12 00:31:21 -05:00
7bab895dee
Previously, when diplomats submit translations, the system would try to figure out whether it should be a 'patch' or a 'change', and then would either create a patch for an admin or artisan to review and accept or reject, or would apply the changes immediately and they would be live. This was done as a compromise between getting translations live quickly, but also preventing already-translated text from getting overwritten without oversight. But having the client handle this added logical complexity. So this makes all diplomats submit patches, no matter what. The server is then in charge of deciding if it should auto-accept the patch or not. Either way, a patch is created. There was also much refactoring. This commit includes: * Update jsondiffpatch so changes within array items are handled correctly * Refactor posting patches to use the new auto-accepting logic, and out of Patch model * Refactor POST /db/patch/:handle/status so that it doesn't rely on handlers * Refactor patch stat handling to ensure auto-accepted patches are counted * Refactor User.incrementStat to use mongodb update commands, to avoid race conditions * Refactor Patch tests
36 lines
1.6 KiB
CoffeeScript
36 lines
1.6 KiB
CoffeeScript
slack = require '../slack'
|
|
sendwithus = require '../sendwithus'
|
|
User = require '../models/User'
|
|
|
|
# TODO: Refactor notification (slack, watcher emails) logic here
|
|
|
|
module.exports =
|
|
notifyChangesMadeToDoc: (req, doc) ->
|
|
# TODO: Stop using headers to pass edit paths. Perhaps should be a method property for Mongoose models
|
|
editPath = req.headers['x-current-path']
|
|
docLink = "http://codecombat.com#{editPath}"
|
|
|
|
# Post a message on Slack
|
|
message = "#{req.user.get('name')} saved a change to #{doc.get('name')}: #{doc.get('commitMessage') or '(no commit message)'} #{docLink}"
|
|
slack.sendSlackMessage message, ['artisans']
|
|
|
|
# Send emails to watchers
|
|
watchers = doc.get('watchers') or []
|
|
# Don't send these emails to the person who submitted the patch, or to Nick, George, or Scott.
|
|
watchers = (w for w in watchers when not w.equals(req.user._id) and not (w.toHexString() in ['512ef4805a67a8c507000001', '5162fab9c92b4c751e000274', '51538fdb812dd9af02000001']))
|
|
if watchers.length
|
|
User.find({_id:{$in:watchers}}).select({email:1, name:1}).exec (err, watchers) ->
|
|
for watcher in watchers
|
|
continue if not watcher.get('email')
|
|
context =
|
|
email_id: sendwithus.templates.change_made_notify_watcher
|
|
recipient:
|
|
address: watcher.get('email')
|
|
name: watcher.get('name')
|
|
email_data:
|
|
doc_name: doc.get('name') or '???'
|
|
submitter_name: req.user.get('name') or '???'
|
|
doc_link: if editPath then docLink else null
|
|
commit_message: doc.get('commitMessage')
|
|
sendwithus.api.send context, _.noop
|
|
|