mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
@@ -34,7 +34,7 @@ Categories.getCategoryById = function (data, callback) {
|
|||||||
},
|
},
|
||||||
function (categories, next) {
|
function (categories, next) {
|
||||||
if (!categories[0]) {
|
if (!categories[0]) {
|
||||||
return next(new Error('[[error:invalid-cid]]'));
|
return callback(null, null);
|
||||||
}
|
}
|
||||||
category = categories[0];
|
category = categories[0];
|
||||||
data.category = category;
|
data.category = category;
|
||||||
|
|||||||
@@ -103,6 +103,9 @@ categoryController.get = function (req, res, callback) {
|
|||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (categoryData, next) {
|
function (categoryData, next) {
|
||||||
|
if (!categoryData) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
categories.modifyTopicsByPrivilege(categoryData.topics, userPrivileges);
|
categories.modifyTopicsByPrivilege(categoryData.topics, userPrivileges);
|
||||||
|
|
||||||
if (categoryData.link) {
|
if (categoryData.link) {
|
||||||
|
|||||||
@@ -148,14 +148,14 @@ function generateForTopic(req, res, callback) {
|
|||||||
], callback);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateForCategory(req, res, next) {
|
function generateForCategory(req, res, callback) {
|
||||||
if (meta.config['feeds:disableRSS']) {
|
if (meta.config['feeds:disableRSS']) {
|
||||||
return controllers404.send404(req, res);
|
return controllers404.send404(req, res);
|
||||||
}
|
}
|
||||||
var cid = req.params.category_id;
|
var cid = req.params.category_id;
|
||||||
var category;
|
var category;
|
||||||
if (!parseInt(cid, 10)) {
|
if (!parseInt(cid, 10)) {
|
||||||
return next();
|
return setImmediate(callback);
|
||||||
}
|
}
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -177,6 +177,9 @@ function generateForCategory(req, res, next) {
|
|||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
category = results.category;
|
category = results.category;
|
||||||
|
if (!category) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
validateTokenIfRequiresLogin(!results.privileges.read, cid, req, res, next);
|
validateTokenIfRequiresLogin(!results.privileges.read, cid, req, res, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -191,7 +194,7 @@ function generateForCategory(req, res, next) {
|
|||||||
function (feed) {
|
function (feed) {
|
||||||
sendFeed(feed, res);
|
sendFeed(feed, res);
|
||||||
},
|
},
|
||||||
], next);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateForTopics(req, res, next) {
|
function generateForTopics(req, res, next) {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ describe('Categories', function () {
|
|||||||
stop: -1,
|
stop: -1,
|
||||||
uid: 0,
|
uid: 0,
|
||||||
}, function (err, categoryData) {
|
}, function (err, categoryData) {
|
||||||
assert.equal(err, null);
|
assert.ifError(err);
|
||||||
|
|
||||||
assert(categoryData);
|
assert(categoryData);
|
||||||
assert.equal('Test Category & NodeBB', categoryData.name);
|
assert.equal('Test Category & NodeBB', categoryData.name);
|
||||||
@@ -67,6 +67,17 @@ describe('Categories', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return null if category does not exist', function (done) {
|
||||||
|
Categories.getCategoryById({
|
||||||
|
cid: 123123123,
|
||||||
|
start: 0,
|
||||||
|
stop: -1,
|
||||||
|
}, function (err, categoryData) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.strictEqual(categoryData, null);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should load a category route', function (done) {
|
it('should load a category route', function (done) {
|
||||||
request(nconf.get('url') + '/api/category/' + categoryObj.cid + '/test-category', { json: true }, function (err, response, body) {
|
request(nconf.get('url') + '/api/category/' + categoryObj.cid + '/test-category', { json: true }, function (err, response, body) {
|
||||||
|
|||||||
Reference in New Issue
Block a user