Upgrade kenton:accounts-sandstorm package to 0.1.6

We now delegates more user attributes sync (avatar and permissions) to
this package instead of doing it ourselves.
This commit is contained in:
Maxime Quandalle 2015-10-21 04:26:16 +02:00
parent 7a5f030cc8
commit 9154b06fc3
4 changed files with 25 additions and 22 deletions

View file

@ -62,7 +62,7 @@ idmontie:migrations@1.0.0
jquery@1.11.4 jquery@1.11.4
kadira:blaze-layout@2.1.0 kadira:blaze-layout@2.1.0
kadira:flow-router@2.7.0 kadira:flow-router@2.7.0
kenton:accounts-sandstorm@0.1.4 kenton:accounts-sandstorm@0.1.6
launch-screen@1.0.4 launch-screen@1.0.4
less@2.5.0_3 less@2.5.0_3
livedata@1.0.15 livedata@1.0.15

View file

@ -1,7 +1,7 @@
template(name="userAvatar") template(name="userAvatar")
a.member.js-member(title="{{userData.profile.fullname}} ({{userData.username}})") a.member.js-member(title="{{userData.profile.fullname}} ({{userData.username}})")
if userData.profile.avatarUrl if userData.getAvatarUrl
img.avatar.avatar-image(src=userData.profile.avatarUrl) img.avatar.avatar-image(src=userData.getAvatarUrl)
else else
+userAvatarInitials(userId=userData._id) +userAvatarInitials(userId=userData._id)

View file

@ -35,6 +35,19 @@ Users.helpers({
_.where(board.members, {userId: this._id})[0].isAdmin; _.where(board.members, {userId: this._id})[0].isAdmin;
}, },
getAvatarUrl() {
// Although we put the avatar picture URL in the `profile` object, we need
// to support Sandstorm which put in the `picture` attribute by default.
// XXX Should we move both cases to `picture`?
if (this.picture) {
return this.picture;
} else if (this.profile && this.profile.avatarUrl) {
return this.profile.avatarUrl;
} else {
return null;
}
},
getInitials() { getInitials() {
const profile = this.profile || {}; const profile = this.profile || {};
if (profile.initials) if (profile.initials)

View file

@ -21,16 +21,9 @@ if (isSandstorm && Meteor.isServer) {
permission: 'public', permission: 'public',
}; };
// This function should probably be handled by `accounts-sandstorm` but
// apparently meteor-core misses an API to handle that cleanly, cf.
// https://github.com/meteor/meteor/blob/ff783e9a12ffa04af6fd163843a563c9f4bbe8c1/packages/accounts-base/accounts_server.js#L1143
function updateUserAvatar(userId, avatarUrl) {
Users.findOne(userId).setAvatarUrl(avatarUrl);
}
function updateUserPermissions(userId, permissions) { function updateUserPermissions(userId, permissions) {
const isActive = permissions.indexOf('participate') > -1; const isActive = permissions.includes('participate');
const isAdmin = permissions.indexOf('configure') > -1; const isAdmin = permissions.includes('configure');
const permissionDoc = { userId, isActive, isAdmin }; const permissionDoc = { userId, isActive, isAdmin };
const boardMembers = Boards.findOne(sandstormBoard._id).members; const boardMembers = Boards.findOne(sandstormBoard._id).members;
@ -55,7 +48,8 @@ if (isSandstorm && Meteor.isServer) {
// and the home page was accessible by pressing the back button of the // and the home page was accessible by pressing the back button of the
// browser, a server-side redirection solves both of these issues. // browser, a server-side redirection solves both of these issues.
// //
// XXX Maybe sandstorm manifest could provide some kind of "home URL"? // XXX Maybe the sandstorm http-bridge could provide some kind of "home URL"
// in the manifest?
const base = req.headers['x-sandstorm-base-path']; const base = req.headers['x-sandstorm-base-path'];
// XXX If this routing scheme changes, this will break. We should generate // XXX If this routing scheme changes, this will break. We should generate
// the location URL using the router, but at the time of writing, the // the location URL using the router, but at the time of writing, the
@ -68,20 +62,14 @@ if (isSandstorm && Meteor.isServer) {
res.end(); res.end();
// `accounts-sandstorm` populate the Users collection when new users // `accounts-sandstorm` populate the Users collection when new users
// accesses the document, but in case a already known user come back, we // 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 // need to update his associated document to match the request HTTP headers
// informations. // informations.
const user = Users.findOne({ const user = Users.findOne({
'services.sandstorm.id': req.headers['x-sandstorm-user-id'], 'services.sandstorm.id': req.headers['x-sandstorm-user-id'],
}); });
if (user) { if (user) {
const userId = user._id; updateUserPermissions(user._id, user.permissions);
const avatarUrl = req.headers['x-sandstorm-user-picture'];
const permissions = req.headers['x-sandstorm-permissions'].split(',') || [];
// XXX The user may also change his name, we should handle it.
updateUserAvatar(userId, avatarUrl);
updateUserPermissions(userId, permissions);
} }
}); });
@ -90,6 +78,8 @@ if (isSandstorm && Meteor.isServer) {
// unique board document. Note that when the `Users.after.insert` hook is // unique board document. Note that when the `Users.after.insert` hook is
// called, the user is inserted into the database but not connected. So // called, the user is inserted into the database but not connected. So
// despite the appearances `userId` is null in this block. // despite the appearances `userId` is null in this block.
//
// XXX We should support the `preferredHandle` exposed by Sandstorm
Users.after.insert((userId, doc) => { Users.after.insert((userId, doc) => {
if (!Boards.findOne(sandstormBoard._id)) { if (!Boards.findOne(sandstormBoard._id)) {
Boards.insert(sandstormBoard, {validate: false}); Boards.insert(sandstormBoard, {validate: false});
@ -104,7 +94,7 @@ if (isSandstorm && Meteor.isServer) {
// LibreBoard v0.8 didnt implement the Sandstorm sharing model and instead // LibreBoard v0.8 didnt implement the Sandstorm sharing model and instead
// kept the visibility setting (“public” or “private”) in the UI as does the // kept the visibility setting (“public” or “private”) in the UI as does the
// main Meteor application. We need to enforce “public” visibility has the // main Meteor application. We need to enforce “public” visibility as the
// sharing is now handled by Sandstorm. // sharing is now handled by Sandstorm.
// See https://github.com/wekan/wekan/issues/346 // See https://github.com/wekan/wekan/issues/346
Migrations.add('enforce-public-visibility-for-sandstorm', () => { Migrations.add('enforce-public-visibility-for-sandstorm', () => {