diff --git a/migrations/20190228225735-notifications-drop-action.js b/migrations/20190228225735-notifications-drop-action.js new file mode 100644 index 000000000..8e9909822 --- /dev/null +++ b/migrations/20190228225735-notifications-drop-action.js @@ -0,0 +1,14 @@ +'use strict'; + +var async = require('async'); + +exports.up = function(db, callback) { + db.runSql('ALTER TABLE notifications DROP COLUMN action', function (error) { + if (error) console.error(error); + callback(error); + }); +}; + +exports.down = function(db, callback) { + db.runSql('ALTER TABLE notifications ADD COLUMN action VARCHAR(512) NOT NULL', callback); +}; diff --git a/migrations/schema.sql b/migrations/schema.sql index 430e45a1f..da0c2341f 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -219,10 +219,9 @@ CREATE TABLE IF NOT EXISTS tasks( CREATE TABLE IF NOT EXISTS notifications( id int NOT NULL AUTO_INCREMENT, userId VARCHAR(128) NOT NULL, - eventId VARCHAR(128), + eventId VARCHAR(128), // reference to eventlog. can be null title VARCHAR(512) NOT NULL, message TEXT, - action VARCHAR(512) NOT NULL, acknowledged BOOLEAN DEFAULT false, creationTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, diff --git a/src/notificationdb.js b/src/notificationdb.js index 1d10ccde6..d95031266 100644 --- a/src/notificationdb.js +++ b/src/notificationdb.js @@ -13,7 +13,7 @@ let assert = require('assert'), database = require('./database.js'), DatabaseError = require('./databaseerror'); -const NOTIFICATION_FIELDS = [ 'id', 'userId', 'eventId', 'title', 'message', 'action', 'creationTime', 'acknowledged' ]; +const NOTIFICATION_FIELDS = [ 'id', 'userId', 'eventId', 'title', 'message', 'creationTime', 'acknowledged' ]; function postProcess(result) { assert.strictEqual(typeof result, 'object'); @@ -27,8 +27,8 @@ function add(notification, callback) { assert.strictEqual(typeof notification, 'object'); assert.strictEqual(typeof callback, 'function'); - const query = 'INSERT INTO notifications (userId, eventId, title, message, action) VALUES (?, ?, ?, ?, ?)'; - const args = [ notification.userId, notification.eventId, notification.title, notification.message, notification.action ]; + const query = 'INSERT INTO notifications (userId, eventId, title, message) VALUES (?, ?, ?, ?)'; + const args = [ notification.userId, notification.eventId, notification.title, notification.message ]; database.query(query, args, function (error, result) { if (error && error.code === 'ER_NO_REFERENCED_ROW_2') return callback(new DatabaseError(DatabaseError.NOT_FOUND, 'no such eventlog entry')); @@ -52,7 +52,6 @@ function upsert(notification, callback) { acknowledged: notification.acknowledged, eventId: notification.eventId, message: notification.message, - action: notification.action, creationTime: new Date() }; diff --git a/src/notifications.js b/src/notifications.js index 5bcf2217b..0d15110db 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -3,7 +3,6 @@ exports = module.exports = { NotificationsError: NotificationsError, - add: add, get: get, ack: ack, getAllPaged: getAllPaged, @@ -61,22 +60,20 @@ util.inherits(NotificationsError, Error); NotificationsError.INTERNAL_ERROR = 'Internal Error'; NotificationsError.NOT_FOUND = 'Not Found'; -function add(userId, eventId, title, message, action, callback) { +function add(userId, eventId, title, message, callback) { assert.strictEqual(typeof userId, 'string'); assert(typeof eventId === 'string' || eventId === null); assert.strictEqual(typeof title, 'string'); assert.strictEqual(typeof message, 'string'); - assert.strictEqual(typeof action, 'string'); assert.strictEqual(typeof callback, 'function'); - debug('add: ', userId, title, action); + debug('add: ', userId, title); notificationdb.add({ userId: userId, eventId: eventId, title: title, - message: message, - action: action + message: message }, function (error, result) { if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new NotificationsError(NotificationsError.NOT_FOUND, error.message)); if (error) return callback(new NotificationsError(NotificationsError.INTERNAL_ERROR, error)); @@ -149,7 +146,7 @@ function userAdded(performedBy, eventId, user) { actionForAllAdmins([ performedBy, user.id ], function (admin, callback) { mailer.userAdded(admin.email, user); - add(admin.id, eventId, 'User added', `User ${user.fallbackEmail} was added`, '/#/users', callback); + add(admin.id, eventId, 'User added', `User ${user.fallbackEmail} was added`, callback); }, function (error) { if (error) console.error(error); }); @@ -162,7 +159,7 @@ function userRemoved(performedBy, eventId, user) { actionForAllAdmins([ performedBy, user.id ], function (admin, callback) { mailer.userRemoved(admin.email, user); - add(admin.id, eventId, 'User removed', `User ${user.username || user.email || user.fallbackEmail} was removed`, '/#/users', callback); + add(admin.id, eventId, 'User removed', `User ${user.username || user.email || user.fallbackEmail} was removed`, callback); }, function (error) { if (error) console.error(error); }); @@ -174,7 +171,7 @@ function adminChanged(performedBy, eventId, user) { actionForAllAdmins([ performedBy, user.id ], function (admin, callback) { mailer.adminChanged(admin.email, user, user.admin); - add(admin.id, eventId, 'Admin status change', `User ${user.username || user.email || user.fallbackEmail} ${user.admin ? 'is now an admin' : 'is no more an admin'}`, '/#/users', callback); + add(admin.id, eventId, 'Admin status change', `User ${user.username || user.email || user.fallbackEmail} ${user.admin ? 'is now an admin' : 'is no more an admin'}`, callback); }, function (error) { if (error) console.error(error); }); @@ -195,7 +192,7 @@ function oomEvent(eventId, program, context) { if (context.app) message = `The application ${context.app.manifest.title} with id ${context.app.id} ran out of memory.`; else message = `The container with id ${context.details.id} ran out of memory`; - add(admin.id, eventId, 'Process died out-of-memory', message, context.app ? '/#/apps' : '', callback); + add(admin.id, eventId, 'Process died out-of-memory', message, callback); }, function (error) { if (error) console.error(error); }); @@ -210,7 +207,7 @@ function appUp(eventId, app) { actionForAllAdmins([], function (admin, callback) { mailer.appUp(admin.email, app); - add(admin.id, eventId, `App ${app.fqdn} is back online`, `The application ${app.manifest.title} installed at ${app.fqdn} is back online.`, '/#/apps', callback); + add(admin.id, eventId, `App ${app.fqdn} is back online`, `The application ${app.manifest.title} installed at ${app.fqdn} is back online.`, callback); }, function (error) { if (error) console.error(error); }); @@ -225,7 +222,7 @@ function appDied(eventId, app) { actionForAllAdmins([], function (admin, callback) { mailer.appDied(admin.email, app); - add(admin.id, eventId, `App ${app.fqdn} is down`, `The application ${app.manifest.title} installed at ${app.fqdn} is not responding.`, '/#/apps', callback); + add(admin.id, eventId, `App ${app.fqdn} is down`, `The application ${app.manifest.title} installed at ${app.fqdn} is not responding.`, callback); }, function (error) { if (error) console.error(error); }); @@ -244,7 +241,7 @@ function processCrash(eventId, processName, crashLogFile) { actionForAllAdmins([], function (admin, callback) { mailer.unexpectedExit(admin.email, subject, crashLogs); - add(admin.id, eventId, subject, 'Detailed logs have been sent to your email address.', '/#/system', callback); + add(admin.id, eventId, subject, 'Detailed logs have been sent to your email address.', callback); }, function (error) { if (error) console.error(error); }); @@ -263,7 +260,7 @@ function apptaskCrash(eventId, appId, crashLogFile) { actionForAllAdmins([], function (admin, callback) { mailer.unexpectedExit(admin.email, subject, crashLogs); - add(admin.id, eventId, subject, 'Detailed logs have been sent to your email address.', '/#/system', callback); + add(admin.id, eventId, subject, 'Detailed logs have been sent to your email address.', callback); }, function (error) { if (error) console.error(error); });