-
Notifications
You must be signed in to change notification settings - Fork 3
/
configure.js
74 lines (69 loc) · 1.75 KB
/
configure.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var mongoose = require('mongoose');
var config = require("./config");
var install = require("./install");
exports.config = config;
exports.install = install;
var Q = require('Q');
exports.checkInitConfig = function() {
var Role = require(__dirname + '/models/role');
var User = require(__dirname + '/models/user');
var Channel = require(__dirname + '/models/channel');
var Repository = require(__dirname + '/models/repository');
var rolePromises = [];
var roles = [];
var userPromises = [];
var adminUser = null;
var channelPromises = [];
Repository.find().exec()
.then(function(data) {
if (data.length==0) {
install.repository.forEach(function(repo) {
var newRepo = new Repository(repo);
newRepo.save();
});
}
});
Role.find().exec()
.then(function(data) {
if (data.length==0) {
var defaultRoles = install.role;
for (var i=0; i<defaultRoles.length;++i) {
var newRole = new Role(defaultRoles[i]);
rolePromises.push(newRole.save());
}
}
return Q.all(rolePromises);
})
.then(function(){
return User.find({"roles":{"$in":["ADMIN"]}}).exec();
})
.then(function(data) {
if (data.length==0) {
install.user.forEach(function(user) {
var newUser = new User(user);
userPromises.push(newUser.save());
});
}
else {
adminUser = data[0];
}
return Q.all(userPromises);
})
.then(function() {
return User.find({"roles":{"$in":["ADMIN"]}}).exec()
})
.then(function(data) {
adminUser = data[0];
return Channel.find().exec();
})
.then(function(data) {
if (data.length==0) {
install.channel.forEach(function(chn) {
chn.owner = [];
chn.owner.push(adminUser._id);
var newChannel = new Channel(chn);
newChannel.save();
});
}
});
}