-
Notifications
You must be signed in to change notification settings - Fork 16
/
app.js
59 lines (53 loc) · 2.01 KB
/
app.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* This is an example Wiki web application written on Pintura
*/
var pageFacets = require("./facet/page"),
pageChangeFacets = require("./facet/page-change"),
admins = require("perstore/util/settings").security.admins,
copy = require("perstore/util/copy").copy,
Restrictive = require("perstore/facet").Restrictive,
FileSystem = require("perstore/store/filesystem").FileSystem,
File = require("pintura/media").getFileModel(),
Model = require("perstore/model").Model,
Notifying = require("perstore/store/notifying").Notifying,
pinturaConfig = require("pintura/pintura").config,
User = pinturaConfig.security.getAuthenticationFacet();
// registers the HTML representation handler that generates HTML from wiki content
require("./media/wiki-html");
// Defines the data model for the given user by request
pinturaConfig.getDataModel = function(request){
var user = request.remoteUser;
if(user){
if(admins.indexOf(user)>-1){
return fullModel; // admin users can directly access the data model without facets
}
return userModel;
}
return publicModel;
}
// we can use the class model for RESTful creation of models
var ClassModel = Model(Notifying(require("perstore/stores").DefaultStore()),{});
var fullModel = {
Page: require("./model/page").Page,
PageSuper: require("./model/page").PageSuper,
PageChange: require("./model/page-change").PageChange,
User: User,
File: File,
Class: ClassModel,
Module: FileSystem({dataFolder:"../lib"})
};
// initialize the data model
require("perstore/model").initializeRoot(fullModel);
// We can generate models from schemas stored in a store/model if we want
exports.DataModel = fullModel = require("perstore/model").createModelsFromModel(ClassModel, fullModel);
// the data model for non-authenticated users
var publicModel = {
Page: pageFacets.PublicFacet,
PageChange: pageChangeFacets.PublicFacet,
User: User,
File: File,
Class: Restrictive(ClassModel)
};
// the data model for authenticated users
var userModel = copy(publicModel, {});
userModel.Page = pageFacets.UserFacet;