Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user image update triggering on first login #25

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { encode } = require('../utils'),
encrypt = require('../services/encrypt');
let db = require('../services/storage'),
bus;
bus = require('../services/bus');

/**
* Adds an user into the db and publishes the action to the bus
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const _isEmpty = require('lodash/isEmpty'),
{ AUTH_LEVELS } = require('./constants'),
{ withAuthLevel } = require('./services/auth'),
{ setDb } = require('./services/storage'),
{ setBus } = require('./controllers/users');
{ setBus } = require('./services/bus');

/**
* determine if a route is protected
Expand Down
15 changes: 15 additions & 0 deletions services/bus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

let bus; // Redis bus passed from Amphora. Assigned value at initialization

/**
* Retrieves an item from the database.
* @param {string} eventName
* @param {Object} data
*/
function publish(eventName, data) {
bus.publish(eventName, data);
}

module.exports.publish = publish;
module.exports.setBus = redisBus => bus = redisBus;
7 changes: 6 additions & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const _get = require('lodash/get'),
references = require('./services/references'),
{ isValidPassword } = require('./services/encrypt');

let db = require('./services/storage');
let db = require('./services/storage'),
bus = require('./services/bus');

/**
* encode username and provider to base64
Expand Down Expand Up @@ -97,6 +98,9 @@ function verify(properties) {
return done(null, false, { message: 'Invalid Password' });
}

data._ref = uid;

bus.publish('saveUser', { key: uid, value: data }); // Tell elastic about any update changes to maintain data consistency
return done(null, data);
})
.catch(e => done(e));
Expand Down Expand Up @@ -254,5 +258,6 @@ module.exports.getUri = getUri;

// For testing purposes
module.exports.setDb = mock => db = mock;
module.exports.setBus = mock => bus = mock;
module.exports.removeQueryString = removeQueryString;
module.exports.removeExtension = removeExtension;
6 changes: 5 additions & 1 deletion utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ const _startCase = require('lodash/startCase'),
storage = require('./test/fixtures/mocks/storage');

describe(_startCase(filename), function () {
let fakeDb;
let fakeDb, fakeBus;

beforeEach(function () {
fakeDb = storage();
fakeBus = {
publish: jest.fn()
};

lib.setDb(fakeDb);
lib.setBus(fakeBus);
});

describe('compileTemplate', function () {
Expand Down