Skip to content

Commit

Permalink
Hyperion: add way to send email notification from rules
Browse files Browse the repository at this point in the history
Hyperion: fix common.fromRule() to always use stackTrace instead of module
  • Loading branch information
feugy committed Jul 1, 2014
1 parent 03f8e0a commit 4d6bf17
Show file tree
Hide file tree
Showing 36 changed files with 168 additions and 121 deletions.
2 changes: 1 addition & 1 deletion conf/dev-conf.yml
Expand Up @@ -54,7 +54,7 @@ cache:

# Mailgun information for sending emails
mailgun:
key: key-172q07yay65msqw6rde9v75chjt3t1i1
key: key-23thw7sif-v21lwsgw83--7wyxvp0sj0
domain: sandboxed84f67e52d0457c8f80876019f9fbe3.mailgun.org
sender: noreply@mythic-forge.com

Expand Down
4 changes: 2 additions & 2 deletions conf/heroku-conf.yml
Expand Up @@ -47,8 +47,8 @@ cache:

# Mailgun information for sending emails
mailgun:
key: key-172q07yay65msqw6rde9v75chjt3t1i1
domain: sandboxed84f67e52d0457c8f80876019f9fbe3.mailgun.org
key: !!!!!!
domain: mythic-forge.com
sender: deephulk.noreply@mythic-forge.com

# location of games files
Expand Down
4 changes: 2 additions & 2 deletions conf/simons-conf.yml
Expand Up @@ -53,8 +53,8 @@ cache:

# Mailgun information for sending emails
mailgun:
key: key-172q07yay65msqw6rde9v75chjt3t1i1
domain: sandboxed84f67e52d0457c8f80876019f9fbe3.mailgun.org
key: !!!!!!
domain: mythic-forge.com
sender: deephulk.noreply@mythic-forge.com

# location of games files
Expand Down
2 changes: 1 addition & 1 deletion conf/test-conf.yml
Expand Up @@ -50,7 +50,7 @@ cache:

# Mailgun information for sending emails
mailgun:
key: key-172q07yay65msqw6rde9v75chjt3t1i1
key: key-23thw7sif-v21lwsgw83--7wyxvp0sj0
domain: sandboxed84f67e52d0457c8f80876019f9fbe3.mailgun.org
sender: noreply@mythic-forge.com

Expand Down
2 changes: 1 addition & 1 deletion hyperion/src/model/ClientConf.coffee
Expand Up @@ -36,7 +36,7 @@ parseSource = (model, source) ->

# Define the schema for configuration values.
# locale will be the id, other values will be stored arbitrary
ClientConf = typeFactory 'ClientConf', module,
ClientConf = typeFactory 'ClientConf',

# configuration's source: plain yaml.
source:
Expand Down
2 changes: 1 addition & 1 deletion hyperion/src/model/Event.coffee
Expand Up @@ -24,7 +24,7 @@ conn = require './connection'
modelUtils = require '../util/model'

# Define the schema for map event with properties
Event = typeFactory 'Event', module,
Event = typeFactory 'Event',

# creation date. May not be modified
created:
Expand Down
2 changes: 1 addition & 1 deletion hyperion/src/model/EventType.coffee
Expand Up @@ -24,7 +24,7 @@ logger = require('../util/logger').getLogger 'model'
modelUtils = require '../util/model'

# Define the schema for event types
EventType = typeFactory 'EventType', module,
EventType = typeFactory 'EventType',
# descriptive image for this type.
descImage:
type: String
Expand Down
6 changes: 3 additions & 3 deletions hyperion/src/model/Executable.coffee
Expand Up @@ -242,7 +242,7 @@ class Executable
# @param callback [Function] invoked when the reset is done.
# @option callback err [String] an error callback. Null if no error occured.
@resetAll: (clean, callback) ->
return if fromRule module, callback
return if fromRule callback
# to avoid circular dependency
Item = require '../model/Item'
# clean local files, and compiled scripts
Expand Down Expand Up @@ -377,7 +377,7 @@ class Executable
# @param err [String] error string. Null if save succeeded
# @param item [Item] the saved item
save: (callback) =>
return if fromRule module, callback
return if fromRule callback
wasNew[@id] = !(@id of executables)
# check id unicity and validity
return callback new Error "id #{@id} for model Executable is invalid" unless modelUtils.isValidId @id
Expand All @@ -401,7 +401,7 @@ class Executable
# @param err [String] error string. Null if save succeeded
# @param item [Item] the removed item
remove: (callback) =>
return if fromRule module, callback
return if fromRule callback
fs.exists @path, (exists) =>
return callback "Error while removing executable #{@id}: this executable does not exists" if not exists
cleanNodeCache()
Expand Down
6 changes: 3 additions & 3 deletions hyperion/src/model/FSItem.coffee
Expand Up @@ -129,7 +129,7 @@ class FSItem
# @option callback item [FSItem] the saved item
# @option callback isNew [Boolean] true if the item did not exists before
save: (callback) =>
return if fromRule module, callback
return if fromRule callback
# First, read current file statistics
fs.stat @path, (err, stat) =>
isNew = false
Expand Down Expand Up @@ -194,7 +194,7 @@ class FSItem
# @param err [String] error string. Null if save succeeded
# @param item [FSItem] the removed item
remove: (callback) =>
return if fromRule module, callback
return if fromRule callback
# First, read current file statistics
fs.stat @path, (err, stat) =>
return callback "Unexisting item #{@path} cannot be removed" if err?.code is 'ENOENT'
Expand Down Expand Up @@ -224,7 +224,7 @@ class FSItem
# @option callback err [String] an error message if an error occured. null otherwise
# @option callback item [FSItem] the concerned fsitem
move: (newPath, callback) =>
return if fromRule module, callback
return if fromRule callback
newPath = normalize newPath
# First, read current file statistics
fs.stat @path, (err, stat) =>
Expand Down
2 changes: 1 addition & 1 deletion hyperion/src/model/FieldType.coffee
Expand Up @@ -24,7 +24,7 @@ logger = require('../util/logger').getLogger 'model'
modelUtils = require '../util/model'

# Define the schema for map field types
FieldType = typeFactory 'FieldType', module,
FieldType = typeFactory 'FieldType',

# descriptive image for this type.
descImage:
Expand Down
2 changes: 1 addition & 1 deletion hyperion/src/model/Item.coffee
Expand Up @@ -23,7 +23,7 @@ conn = require './connection'
Map = require './Map'

# Define the schema for map item with its properties
Item = typeFactory 'Item', module,
Item = typeFactory 'Item',
# link to map
map: {}

Expand Down
2 changes: 1 addition & 1 deletion hyperion/src/model/ItemType.coffee
Expand Up @@ -26,7 +26,7 @@ Item = require './Item'
modelUtils = require '../util/model'

# Define the schema for map item types
ItemType = typeFactory 'ItemType', module,
ItemType = typeFactory 'ItemType',

# descriptive image for this type.
descImage:
Expand Down
3 changes: 2 additions & 1 deletion hyperion/src/model/Map.coffee
Expand Up @@ -25,7 +25,8 @@ modelWatcher = require('./ModelWatcher').get()
modelUtils = require '../util/model'

# Define the schema for map item types
Map = typeFactory 'Map', module,
Map = typeFactory 'Map',

# kind of map: square, diamond, hexagon
kind:
type: String
Expand Down
2 changes: 1 addition & 1 deletion hyperion/src/model/ModelWatcher.coffee
Expand Up @@ -45,7 +45,7 @@ class _ModelWatcher extends EventEmitter
# @param instance [Object] the Mongoose document that was modified
# @param modified [Array<String>] array of modified path of the instance
change: (operation, className, instance, modified) =>
return if fromRule module, ->
return if fromRule()
changes = {}
if '_doc' of instance
changes[key] = value for own key,value of instance._doc
Expand Down
2 changes: 1 addition & 1 deletion hyperion/src/model/Player.coffee
Expand Up @@ -27,7 +27,7 @@ utils = require '../util/common'
logger = require('../util/logger').getLogger 'model'

# Define the schema for players
Player = typeFactory 'Player', module,
Player = typeFactory 'Player',

# email as login
email:
Expand Down
6 changes: 6 additions & 0 deletions hyperion/src/model/Rule.coffee
Expand Up @@ -41,10 +41,16 @@ class Rule
# All objects removed by the rule must be added to this array to be removed from database
removed: []

# Notifications sent to players: for each campaign, put an object with properties:
# - msg [String] notification message, with placeholders (use #{} delimiters) to use player's attributes
# - players [Player|Array<Player>] an array of players to be notified
campaigns: []

# Construct a rule, with a category.
constructor: (@category = '') ->
@removed= []
@saved= []
@campaigns= []

# This method indicates wheter or not the rule apply to a given situation.
# Beware: `canExecute` is intended to be invoked on server and client side, thus, database access are not allowed.
Expand Down
6 changes: 6 additions & 0 deletions hyperion/src/model/TurnRule.coffee
Expand Up @@ -38,10 +38,16 @@ class TurnRule
# Turn rule rank inside existing rules
rank: 0

# Notifications sent to players: for each campaign, put an object with properties:
# - msg [String] notification message, with placeholders (use #{} delimiters) to use player's attributes
# - players [Player|Array<Player>] an array of players to be notified
campaigns: []

# Construct a rule, with a fthe rule rank
constructor: (@rank = 0) ->
@removed= []
@saved= []
@campaigns= []

# This method select a set of element on which execute will be applied.
# Objects can be read directly from database, but modification is not allowed.
Expand Down
7 changes: 3 additions & 4 deletions hyperion/src/model/typeFactory.coffee
Expand Up @@ -123,7 +123,7 @@ originals = {}
originals[method] = mongoose.Collection::[method]
mongoose.Collection::[method] = (args...) ->
# forbid if necessary
return if fromRule args[args.length-1] or ->
return if fromRule args[args.length-1]
# or process original
originals[method].apply @, arguments
mongoose.Collection::[method].secured = true
Expand All @@ -138,7 +138,6 @@ originals = {}
# - properties management, for type or instances
#
# @param typeName [String] name of the build type, used for changes propagations
# @param mod [Object] current nodeJs module used to forbidd usage of save/remove method in executables
# @param spec [Object] attributes of the created type.
# @param options [Object] Mongoose schema options, and factory custom options:
# @option options typeProperties [Boolean] whether this type will defined properties for its instances
Expand All @@ -148,7 +147,7 @@ originals = {}
# @option options hasImages [Boolean] if this type has images to be removed when type is removed
# @option options middlewares [Object] type middleware, added before other middlewares
# @return the created type
module.exports = (typeName, mod, spec, options = {}) ->
module.exports = (typeName, spec, options = {}) ->

caches[typeName] = {}

Expand Down Expand Up @@ -295,7 +294,7 @@ module.exports = (typeName, mod, spec, options = {}) ->
#
# @param all [Boolean] true (default) to clean all models, false to clean models of this class
AbstractType.statics.cleanModelCache = (all = true) ->
return if fromRule module
return if fromRule()
for className of caches
caches[className] = {} if className is typeName or all

Expand Down
6 changes: 3 additions & 3 deletions hyperion/src/service/AdminService.coffee
Expand Up @@ -71,7 +71,7 @@ class _AdminService
# @option callback models [Array] list (may be empty) of retrieved models
#
list: (modelName, callback) =>
return if fromRule module, callback
return if fromRule callback
return callback "The #{modelName} model can't be listed", modelName unless modelName in listSupported
switch modelName
when 'ItemType' then ItemType.find (err, result) -> callback err, modelName, result
Expand All @@ -93,7 +93,7 @@ class _AdminService
# @option callback modelName [String] reminds the saved model class name
# @option callback model [Object] saved model
save: (modelName, values, email, callback) =>
return if fromRule module, callback
return if fromRule callback
return callback "The #{modelName} model can't be saved", modelName unless modelName in supported

_save = (model) ->
Expand Down Expand Up @@ -259,7 +259,7 @@ class _AdminService
# @option callback modelName [String] reminds the saved model class name
# @option callback model [Object] saved model
remove: (modelName, values, email, callback) =>
return if fromRule module, callback
return if fromRule callback
return callback "The #{modelName} model can't be removed", modelName unless modelName in supported
unless 'Field' is modelName or 'FSItem' is modelName or 'id' of values
return callback "Cannot remove #{modelName} because no 'id' specified", modelName
Expand Down
18 changes: 9 additions & 9 deletions hyperion/src/service/AuthoringService.coffee
Expand Up @@ -54,7 +54,7 @@ class _AuthoringService
# @param callback [Function] initialization end callback.
# @option callback err [Sting] error message. Null if no error occured.
init: (callback) =>
return if fromRule module, callback
return if fromRule callback
versionService.init (err) =>
return callback err if err?
root = resolve normalize confKey 'game.client.dev'
Expand All @@ -66,7 +66,7 @@ class _AuthoringService
# @option callback err [String] error string. Null if no error occured
# @option callback root [FSItem] the root fSItem folder, populated
readRoot: (callback) =>
return if fromRule module, callback
return if fromRule callback
new FSItem(root, true).read (err, rootFolder) =>
return callback "Failed to get root content: #{purgeFolder err, root}" if err?
# make root relative
Expand All @@ -83,7 +83,7 @@ class _AuthoringService
# @option callback err [String] error string. Null if no error occured
# @option callback saved [FSItem] the saved fSItem
save: (item, email, callback) =>
return if fromRule module, callback
return if fromRule callback
deployed = deployementService.deployedVersion()
return callback "Deployment of version #{deployed} in progress" if deployed?
try
Expand All @@ -108,7 +108,7 @@ class _AuthoringService
# @option callback err [String] error string. Null if no error occured
# @option callback removed [FSItem] the removed fSItem
remove: (item, email, callback) =>
return if fromRule module, callback
return if fromRule callback
deployed = deployementService.deployedVersion()
return callback "Deployment of version #{deployed} in progress" if deployed?
try
Expand All @@ -135,7 +135,7 @@ class _AuthoringService
# @option callback err [String] error string. Null if no error occured
# @option callback moved [FSItem] the moved fSItem
move: (item, newPath, email, callback) =>
return if fromRule module, callback
return if fromRule callback
deployed = deployementService.deployedVersion()
return callback "Deployment of version #{deployed} in progress" if deployed?
try
Expand All @@ -160,7 +160,7 @@ class _AuthoringService
# @option callback err [String] error string. Null if no error occured
# @option callback read [FSItem] the read fSItem populated with its content
read: (item, callback) =>
return if fromRule module, callback
return if fromRule callback
try
item = new FSItem item
catch exc
Expand All @@ -185,7 +185,7 @@ class _AuthoringService
# @option callback obj [FSItem|Executable] concerned file or executable
# @option callback history [Array] array of commits, each an object containing `message`, `author`, `date` and `id`
history: (item, callback) =>
return if fromRule module, callback
return if fromRule callback
path = null
obj = null
if _.isObject(item) and item?.id
Expand Down Expand Up @@ -217,7 +217,7 @@ class _AuthoringService
# @option callback restorables [Array] array of restorable FSItems|Executables. (may be empty).
# For each item contains an object with `id` (commit id), `item` (object model) and `className` (model class name) attributes
restorables: (filters, callback) =>
return if fromRule module, callback
return if fromRule callback
versionService.restorables (err, restorables) =>
return callback "Failed to get restorable list: #{err}" if err?
results = []
Expand Down Expand Up @@ -263,7 +263,7 @@ class _AuthoringService
# @option callback obj [FSItem|Executable] concerned file or executable
# @option callback content [String] the base64 encoded content
readVersion: (item, version, callback) =>
return if fromRule module, callback
return if fromRule callback
path = null
obj = null
if _.isObject(item) and item?.id
Expand Down
2 changes: 1 addition & 1 deletion hyperion/src/service/ContactService.coffee
Expand Up @@ -108,7 +108,7 @@ class _ContactService
# @option callback err [Error] an error object. Null if no error occured
# @option callback report [Array<Object>] a report containing sending result for each player
sendTo: (players, message, callback) =>
return if utils.fromRule module, callback
return if utils.fromRule callback
# make player an array if not alreay the case
players = [players] unless Array.isArray players

Expand Down

0 comments on commit 4d6bf17

Please sign in to comment.