From 9f4300d38b248a147ac0fdf39bb607ffed5bae7e Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Wed, 21 Sep 2016 11:16:07 -0400 Subject: Fix updating of permissions and profile. --- sandstorm.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'sandstorm.js') diff --git a/sandstorm.js b/sandstorm.js index e7a67f76..d1b7b300 100644 --- a/sandstorm.js +++ b/sandstorm.js @@ -58,29 +58,6 @@ if (isSandstorm && Meteor.isServer) { Location: base + boardPath, }); res.end(); - - // `accounts-sandstorm` populate the Users collection when new users - // accesses the document, but in case a already known user comes back, we - // need to update his associated document to match the request HTTP headers - // informations. - // XXX We need to update this document even if the initial route is not `/`. - // Unfortuanlty I wasn't able to make the Webapp.rawConnectHandlers solution - // work. - const user = Users.findOne({ - 'services.sandstorm.id': req.headers['x-sandstorm-user-id'], - }); - if (user) { - // XXX At this point the user.services.sandstorm credentials haven't been - // updated, which mean that the user will have to restart the application - // a second time to see its updated name and avatar. - Users.update(user._id, { - $set: { - 'profile.fullname': user.services.sandstorm.name, - 'profile.avatarUrl': user.services.sandstorm.picture, - }, - }); - updateUserPermissions(user._id, user.services.sandstorm.permissions); - } }); // On the first launch of the instance a user is automatically created thanks @@ -126,6 +103,29 @@ if (isSandstorm && Meteor.isServer) { updateUserPermissions(doc._id, doc.services.sandstorm.permissions); }); + Meteor.startup(() => { + Users.find().observeChanges({ + changed(userId, fields) { + const sandstormData = (fields.services || {}).sandstorm || {}; + if (sandstormData.name) { + Users.update(userId, { + $set: { 'profile.fullname': sandstormData.name }, + }); + } + + if (sandstormData.picture) { + Users.update(userId, { + $set: { 'profile.avatarUrl': sandstormData.picture }, + }); + } + + if (sandstormData.permissions) { + updateUserPermissions(userId, sandstormData.permissions); + } + }, + }); + }); + // Wekan v0.8 didn’t implement the Sandstorm sharing model and instead kept // the visibility setting (“public” or “private”) in the UI as does the main // Meteor application. We need to enforce “public” visibility as the sharing -- cgit v1.2.3-1-g7c22