summaryrefslogtreecommitdiffstats
path: root/models/users.js
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander.sulfrian@fu-berlin.de>2016-03-29 18:36:16 +0200
committerAlexander Sulfrian <alexander.sulfrian@fu-berlin.de>2016-06-03 03:56:40 +0200
commitae2c1fb77f498e0c92cbcb0a48fe6e7ecc9c14c4 (patch)
tree549d8a345cfcd53622019991ec3436f617186db6 /models/users.js
parentb9883a8e244d21f7caf00a794371dbe6b2e4e2ad (diff)
downloadwekan-ae2c1fb77f498e0c92cbcb0a48fe6e7ecc9c14c4.tar.gz
wekan-ae2c1fb77f498e0c92cbcb0a48fe6e7ecc9c14c4.tar.bz2
wekan-ae2c1fb77f498e0c92cbcb0a48fe6e7ecc9c14c4.zip
Fix initial board creation
We cannot rely on the automatic userId setting of the collection hooks. If a user is created during invitation, the userId field will contain the id of the inviting user. This fix this, by mocking the CollectionHooks.getUserId function and returning the userId of the new user for all new documents after creating the user.
Diffstat (limited to 'models/users.js')
-rw-r--r--models/users.js32
1 files changed, 19 insertions, 13 deletions
diff --git a/models/users.js b/models/users.js
index b56fd2ab..629caa4a 100644
--- a/models/users.js
+++ b/models/users.js
@@ -388,25 +388,31 @@ if (Meteor.isServer) {
incrementBoards(_.difference(newIds, oldIds), +1);
});
+ const fakeUserId = new Meteor.EnvironmentVariable();
+ const getUserId = CollectionHooks.getUserId;
+ CollectionHooks.getUserId = () => {
+ return fakeUserId.get() || getUserId();
+ };
+
// XXX i18n
Users.after.insert((userId, doc) => {
- const ExampleBoard = {
- title: 'Welcome Board',
- userId: doc._id,
- permission: 'private',
+ const fakeUser = {
+ extendAutoValueContext: {
+ userId: doc._id,
+ },
};
- // Insert the Welcome Board
- Boards.insert(ExampleBoard, (err, boardId) => {
+ fakeUserId.withValue(doc._id, () => {
+ // Insert the Welcome Board
+ Boards.insert({
+ title: 'Welcome Board',
+ permission: 'private',
+ }, fakeUser, (err, boardId) => {
- ['Basics', 'Advanced'].forEach((title) => {
- const list = {
- title,
- boardId,
- userId: ExampleBoard.userId,
- };
+ ['Basics', 'Advanced'].forEach((title) => {
+ Lists.insert({ title, boardId }, fakeUser);
+ });
- Lists.insert(list);
});
});
});