rework notifications

notifications are now system level instead of user level.

To clarify the use events/notifications/email:
* eventlog - everything that is happenning on server
* notifications - specific important events (alerts)
* email - these are really urgent things that require immediate attention. this is for
  the case where an admin does not visit the dashboard often. can also be alerts like
  bad backup config or reboot required which are not events per-se.

Notes on notifications
* oom - notification only
* appUpdated - notification only
* cert renewal failure - only raise when < 10 days to go. also send email thereafter (todo).
* Backup failure - only if last 5 backups failed (todo).
* Box update - notification only. we anyway send newsletter.
* box update available - we raise a notification. no email.
* app update available - we already have update indicator on dashboard. so, no notification or email.

Alerts:
* backup config
* disk space
* mail status
* reboot
* box updated
* ubuntu update required
This commit is contained in:
Girish Ramakrishnan
2021-05-28 14:34:18 -07:00
parent 3ba62f2ba1
commit 73917e95c9
18 changed files with 219 additions and 959 deletions

View File

@@ -20,7 +20,6 @@ const appdb = require('../appdb.js'),
hat = require('../hat.js'),
mailboxdb = require('../mailboxdb.js'),
maildb = require('../maildb.js'),
notificationdb = require('../notificationdb.js'),
reverseProxy = require('../reverseproxy.js'),
settingsdb = require('../settingsdb.js'),
taskdb = require('../taskdb.js'),
@@ -120,190 +119,6 @@ describe('database', function () {
], done);
});
describe('notifications', function () {
var EVENT_0 = {
id: 'event_0',
action: 'action',
source: {},
data: {}
};
var EVENT_1 = {
id: 'event_1',
action: 'action',
source: {},
data: {}
};
var EVENT_2 = {
id: 'event_2',
action: 'action',
source: {},
data: {}
};
var NOTIFICATION_0 = {
userId: USER_0.id,
eventId: EVENT_0.id,
title: 'title z', // titles are this way for ordering
message: 'some message there',
};
var NOTIFICATION_1 = {
userId: USER_0.id,
eventId: EVENT_1.id,
title: 'title y',
message: 'some message there',
};
var NOTIFICATION_2 = {
userId: USER_1.id,
eventId: EVENT_2.id,
title: 'title x',
message: 'some message there',
};
var NOTIFICATION_3 = {
userId: USER_0.id,
eventId: null,
title: 'title w',
message: 'some message there',
};
before(function (done) {
async.series([
userdb.add.bind(null, USER_0.id, USER_0),
userdb.add.bind(null, USER_1.id, USER_1),
eventlogdb.add.bind(null, EVENT_0.id, EVENT_0.action, EVENT_0.source, EVENT_0.data),
eventlogdb.add.bind(null, EVENT_1.id, EVENT_1.action, EVENT_1.source, EVENT_1.data),
eventlogdb.add.bind(null, EVENT_2.id, EVENT_2.action, EVENT_2.source, EVENT_2.data),
], done);
});
after(function (done) {
database._clear(done);
});
it('can add notification', function (done) {
notificationdb.add(NOTIFICATION_0, function (error, result) {
expect(error).to.equal(null);
expect(result).to.be.a('string');
NOTIFICATION_0.id = result;
done();
});
});
it('can add second notification', function (done) {
notificationdb.add(NOTIFICATION_1, function (error, result) {
expect(error).to.equal(null);
expect(result).to.be.a('string');
NOTIFICATION_1.id = result;
done();
});
});
it('can add third notification for another user', function (done) {
notificationdb.add(NOTIFICATION_2, function (error, result) {
expect(error).to.equal(null);
expect(result).to.be.a('string');
NOTIFICATION_2.id = result;
done();
});
});
it('can get by id', function (done) {
notificationdb.get(NOTIFICATION_0.id, function (error, result) {
expect(error).to.equal(null);
expect(result.id).to.equal(NOTIFICATION_0.id);
expect(result.title).to.equal(NOTIFICATION_0.title);
expect(result.message).to.equal(NOTIFICATION_0.message);
expect(result.acknowledged).to.equal(false);
done();
});
});
it('cannot get by non-existing id', function (done) {
notificationdb.get('nopenothere', function (error, result) {
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
});
it('can list by user', function (done) {
notificationdb.list({ userId: USER_0.id }, 1, 100, function (error, result) {
expect(error).to.equal(null);
expect(result).to.be.an('array');
expect(result.length).to.equal(2);
expect(result[0].id).to.equal(NOTIFICATION_0.id);
expect(result[0].title).to.equal(NOTIFICATION_0.title);
expect(result[0].message).to.equal(NOTIFICATION_0.message);
expect(result[0].acknowledged).to.equal(false);
done();
});
});
it('cannot update non-existing notification', function (done) {
notificationdb.update('isnotthere', { acknowledged: true }, function (error) {
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
done();
});
});
it('update succeeds', function (done) {
notificationdb.update(NOTIFICATION_1.id, { acknowledged: true }, function (error) {
expect(error).to.equal(null);
notificationdb.get(NOTIFICATION_1.id, function (error, result) {
expect(error).to.equal(null);
expect(result.id).to.equal(NOTIFICATION_1.id);
expect(result.title).to.equal(NOTIFICATION_1.title);
expect(result.message).to.equal(NOTIFICATION_1.message);
expect(result.acknowledged).to.equal(true);
done();
});
});
});
it('deletion succeeds', function (done) {
notificationdb.del(NOTIFICATION_0.id, function (error) {
expect(error).to.equal(null);
notificationdb.get(NOTIFICATION_0.id, function (error, result) {
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
expect(result).to.not.be.ok();
done();
});
});
});
it('deletion for non-existing notification fails', function (done) {
notificationdb.del('doesnotexts', function (error) {
expect(error).to.be.a(BoxError);
expect(error.reason).to.equal(BoxError.NOT_FOUND);
done();
});
});
it('can add notification without eventId', function (done) {
notificationdb.add(NOTIFICATION_3, function (error, result) {
expect(error).to.equal(null);
expect(result).to.be.a('string');
// stash for further use
NOTIFICATION_3.id = result;
done();
});
});
});
describe('domains', function () {
before(function (done) {
userdb.add(USER_0.id, USER_0, done);