Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
generalhenry committed Jan 14, 2014
1 parent 5f71153 commit 637157c
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 231 deletions.
33 changes: 13 additions & 20 deletions lib/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,39 +82,32 @@ function cleanupContainersNotIn (domain, whitelist, cb) {
}
module.exports = function (req, res) {
function sendError (err) {
var status;
status = err.status;
var status = err.status;
delete err.status;
return res.json(status || 403, err);
res.json(status || 403, err);
}
async.series([
function (cb) {
if (req.query.firstRun) {
return onFirstRun(cb);
onFirstRun(cb);
} else {
return cb();
cb();
}
},
function (cb) {
var domain = req.domain;
users.findUser(domain, { _id: req.user_id }, domain.intercept(function (user) {
if (!user) {
return cb({ message: 'permission denied: no user' });
cb({ message: 'permission denied: no user' });
} else if (!user.isModerator) {
cb({ message: 'permission denied' });
} else {
if (!user.isModerator) {
return cb({ message: 'permission denied' });
} else {
containers.listSavedContainers(domain, function (containers) {
getOwners(domain, containers, function (err) {
if (err) {
return cb(err);
} else {
var validContainers = containers.filter(hasRegisteredOwner);
cleanupContainersNotIn(domain, validContainers, cb);
}
});
});
}
containers.listSavedContainers(domain, function (containers) {
getOwners(domain, containers, domain.intercept(function () {
var validContainers = containers.filter(hasRegisteredOwner);
cleanupContainersNotIn(domain, validContainers, cb);
}));
});
}
}));
}
Expand Down
14 changes: 7 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function App(configs, domain) {
App.prototype.start = function (cb) {
var self = this;
if (this.started) {
return cb();
cb();
} else {
this.listener = function (err) {
if (self.domain && configs.throwErrors) {
Expand All @@ -49,27 +49,27 @@ App.prototype.start = function (cb) {
process.on('uncaughtException', this.listener);
return this.server.listen(this.configs.port, this.configs.ipaddress || '0.0.0.0', function (err) {
if (err) {
return cb(err);
cb(err);
} else {
self.started = true;
return cb();
cb();
}
});
}
};
App.prototype.stop = function (cb) {
var self = this;
if (!this.started) {
return cb();
cb();
} else {
process.removeListener('uncaughtException', this.listener);
return this.server.close(function (err) {
this.server.close(function (err) {
if (err) {
return cb(err);
cb(err);
} else {
self.started = false;
delete self.listener;
return cb();
cb();
}
});
}
Expand Down
5 changes: 2 additions & 3 deletions lib/models/caching.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ var listFields = {
};
var redis_client = redis.createClient(configs.redis.port, configs.redis.ipaddress);
var markCacheAsDirty = function () {
var cb;
cb = function (err) {
var cb = function (err) {
if (err) {
console.error(err.message && console.log(err.stack));
console.error(err.message);
}
};
redis_client.get('sort_cache.block_set_dirty', function (err, value) {
Expand Down
32 changes: 12 additions & 20 deletions lib/models/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ categorySchema.statics.listCategories = function (domain, cb) {
};
categorySchema.statics.createCategory = function (domain, userId, name, desc, cb) {
var self = this;
users.findUser(domain, { _id: userId }, function (err, user) {
if (err) {
cb(err);
} else if (!user) {
users.findUser(domain, { _id: userId }, domain.intercept(function (user) {
if (!user) {
cb(error(403, 'user not found'));
} else if (!user.isModerator) {
cb(error(403, 'permission denied'));
Expand All @@ -88,7 +86,7 @@ categorySchema.statics.createCategory = function (domain, userId, name, desc, cb
}
}));
}
});
}));
};
categorySchema.statics.createImplicitCategory = function (domain, name, cb) {
var category = new this();
Expand All @@ -103,10 +101,8 @@ categorySchema.statics.createImplicitCategory = function (domain, name, cb) {
};
categorySchema.statics.updateCategory = function (domain, userId, categoryId, newName, newDesc, cb) {
var self = this;
users.findUser(domain, { _id: userId }, function (err, user) {
if (err) {
cb(err);
} else if (!user) {
users.findUser(domain, { _id: userId }, domain.intercept(function (user) {
if (!user) {
cb(error(403, 'user not found'));
} else if (!user.isModerator) {
cb(error(403, 'permission denied'));
Expand All @@ -129,14 +125,12 @@ categorySchema.statics.updateCategory = function (domain, userId, categoryId, ne
}));
}));
}
});
}));
};
categorySchema.statics.updateAliases = function (domain, userId, categoryId, newAliases, cb) {
var self = this;
users.findUser(domain, { _id: userId }, function (err, user) {
if (err) {
cb(err);
} else if (!user.isModerator) {
users.findUser(domain, { _id: userId }, domain.intercept(function (user) {
if (!user.isModerator) {
cb(error(403, 'permission denied'));
} else {
if (newAliases == null) {
Expand All @@ -150,20 +144,18 @@ categorySchema.statics.updateAliases = function (domain, userId, categoryId, new
}));
}
}
});
}));
};
categorySchema.statics.deleteCategory = function (domain, userId, categoryId, cb) {
var self = this;
users.findUser(domain, { _id: userId }, function (err, user) {
if (err) {
cb(err);
} else if (!user.isModerator) {
users.findUser(domain, { _id: userId }, domain.intercept(function (user) {
if (!user.isModerator) {
cb(error(403, 'permission denied'));
} else {
self.remove({ _id: categoryId }, domain.intercept(function () {
cb();
}));
}
});
}));
};
module.exports = mongoose.model('Categories', categorySchema);
Loading

0 comments on commit 637157c

Please sign in to comment.