summaryrefslogtreecommitdiffstats
path: root/sandstorm.js
diff options
context:
space:
mode:
authorDavid Renshaw <david@sandstorm.io>2016-09-21 11:16:07 -0400
committerDavid Renshaw <david@sandstorm.io>2016-11-03 23:42:00 -0400
commit9f4300d38b248a147ac0fdf39bb607ffed5bae7e (patch)
treeac150b170a7bb146245dd261ec1e9d1810b77d47 /sandstorm.js
parent0f62fe0c6e5a151be0aa7baf60405ef2e878a0d8 (diff)
downloadwekan-9f4300d38b248a147ac0fdf39bb607ffed5bae7e.tar.gz
wekan-9f4300d38b248a147ac0fdf39bb607ffed5bae7e.tar.bz2
wekan-9f4300d38b248a147ac0fdf39bb607ffed5bae7e.zip
Fix updating of permissions and profile.
Diffstat (limited to 'sandstorm.js')
-rw-r--r--sandstorm.js46
1 files changed, 23 insertions, 23 deletions
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