forked from wekan/wekan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sandstorm.js
44 lines (40 loc) · 1.64 KB
/
sandstorm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Sandstorm context is detected using the METEOR_SETTINGS environment variable
// in the package definition.
// XXX We could probably rely on the user object to detect sandstorm usage.
var isSandstorm = Meteor.settings &&
Meteor.settings.public && Meteor.settings.public.sandstorm;
// In sandstorm we only have one board per sandstorm instance. Since we want to
// keep most of our code unchanged, we simply hard-code a board `_id` and
// redirect the user to this particular board.
var sandstormBoard = {
_id: "sandstorm",
title: "LibreBoard"
};
// On the first launch of the instance a user is automatically created thanks to
// the `accounts-sandstorm` package. After its creation we insert the unique
// board document.
if (isSandstorm && Meteor.isServer) {
Users.after.insert(function(userId, doc) {
Boards.insert({
_id: sandstormBoard._id,
// XXX should be shared with the instance name
title: sandstormBoard.title,
userId: doc._id
});
});
}
// On the client, redirect the user to the hard-coded board. On the first launch
// the user will be redirected to the board before its creation. But that's not
// a problem thanks to the reactive board publication.
if (isSandstorm && Meteor.isClient) {
Router.go('Board', {
boardId: sandstormBoard._id,
slug: getSlug(sandstormBoard.title)
});
}
// We use this blaze helper in the UI to hide some template that does not make
// sense in the context of sandstorm, like board staring, board archiving, user
// name edition, etc.
Blaze.registerHelper("isSandstorm", function() {
return isSandstorm;
});