Skip to content

Node.js based forum software built for the modern web

deleted topic feed fix

barisusakli870bf95e5b16
diff --git a/src/controllers/topics.js b/src/controllers/topics.js
index dce634ebff..e82e2ddad7 100644
--- a/src/controllers/topics.js
+++ b/src/controllers/topics.js
@@ -56,7 +56,7 @@ topicsController.get = function(req, res, next) {
topics.getTopicWithPosts(tid, set, uid, start, end, reverse, function (err, topicData) {
if (topicData) {
- if (parseInt(topicData.deleted, 10) === 1 && !userPrivileges.view_deleted) {
+ if (topicData.deleted && !userPrivileges.view_deleted) {
return next(new Error('[[error:no-topic]]'));
}
topicData.currentPage = page;
diff --git a/src/routes/feeds.js b/src/routes/feeds.js
index 30b3cb6c4c..13b76d1031 100644
--- a/src/routes/feeds.js
+++ b/src/routes/feeds.js
@@ -40,45 +40,56 @@ function hasPrivileges(method, id, req, res, next) {
function generateForTopic(req, res, next) {
var tid = req.params.topic_id;
var uid = req.user ? req.user.uid : 0;
- topics.getTopicWithPosts(tid, 'tid:' + tid + ':posts', uid, 0, 25, false, function (err, topicData) {
+
+ privileges.topics.get(tid, uid, function(err, userPrivileges) {
if (err) {
return next(err);
}
- var description = topicData.posts.length ? topicData.posts[0].content : '';
- var image_url = topicData.posts.length ? topicData.posts[0].picture : '';
- var author = topicData.posts.length ? topicData.posts[0].username : '';
-
- var feed = new rss({
- title: topicData.title,
- description: description,
- feed_url: nconf.get('url') + '/topic/' + tid + '.rss',
- site_url: nconf.get('url') + '/topic/' + topicData.slug,
- image_url: image_url,
- author: author,
- ttl: 60
- }),
- dateStamp;
-
- if (topicData.posts.length > 0) {
- feed.pubDate = new Date(parseInt(topicData.posts[0].timestamp, 10)).toUTCString();
- }
+ topics.getTopicWithPosts(tid, 'tid:' + tid + ':posts', uid, 0, 25, false, function (err, topicData) {
+ if (err) {
+ return next(err);
+ }
- topicData.posts.forEach(function(postData) {
- if (!postData.deleted) {
- dateStamp = new Date(parseInt(parseInt(postData.edited, 10) === 0 ? postData.timestamp : postData.edited, 10)).toUTCString();
-
- feed.item({
- title: 'Reply to ' + topicData.title + ' on ' + dateStamp,
- description: postData.content,
- url: nconf.get('url') + '/topic/' + topicData.slug + '#' + postData.pid,
- author: postData.username,
- date: dateStamp
- });
+ if (topicData.deleted && !userPrivileges.view_deleted) {
+ return res.redirect('404');
}
- });
- sendFeed(feed, res);
+ var description = topicData.posts.length ? topicData.posts[0].content : '';
+ var image_url = topicData.posts.length ? topicData.posts[0].picture : '';
+ var author = topicData.posts.length ? topicData.posts[0].username : '';
+
+ var feed = new rss({
+ title: topicData.title,
+ description: description,
+ feed_url: nconf.get('url') + '/topic/' + tid + '.rss',
+ site_url: nconf.get('url') + '/topic/' + topicData.slug,
+ image_url: image_url,
+ author: author,
+ ttl: 60
+ }),
+ dateStamp;
+
+ if (topicData.posts.length > 0) {
+ feed.pubDate = new Date(parseInt(topicData.posts[0].timestamp, 10)).toUTCString();
+ }
+
+ topicData.posts.forEach(function(postData) {
+ if (!postData.deleted) {
+ dateStamp = new Date(parseInt(parseInt(postData.edited, 10) === 0 ? postData.timestamp : postData.edited, 10)).toUTCString();
+
+ feed.item({
+ title: 'Reply to ' + topicData.title + ' on ' + dateStamp,
+ description: postData.content,
+ url: nconf.get('url') + '/topic/' + topicData.slug + '#' + postData.pid,
+ author: postData.username,
+ date: dateStamp
+ });
+ }
+ });
+
+ sendFeed(feed, res);
+ });
});
}