mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	api/post/pid route
This commit is contained in:
		| @@ -16,6 +16,7 @@ var async = require('async'), | |||||||
| 	helpers = require('./helpers'); | 	helpers = require('./helpers'); | ||||||
|  |  | ||||||
| var Controllers = { | var Controllers = { | ||||||
|  | 	posts: require('./posts'), | ||||||
| 	topics: require('./topics'), | 	topics: require('./topics'), | ||||||
| 	categories: require('./categories'), | 	categories: require('./categories'), | ||||||
| 	tags: require('./tags'), | 	tags: require('./tags'), | ||||||
|   | |||||||
							
								
								
									
										36
									
								
								src/controllers/posts.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/controllers/posts.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | |||||||
|  | "use strict"; | ||||||
|  |  | ||||||
|  | var async = require('async'), | ||||||
|  | 	 | ||||||
|  | 	posts = require('../posts'), | ||||||
|  | 	privileges = require('../privileges'), | ||||||
|  | 	helpers = require('./helpers'), | ||||||
|  | 	postsController = {}; | ||||||
|  |  | ||||||
|  | postsController.getPost = function(req, res, next) { | ||||||
|  | 	var uid = req.user ? parseInt(req.user.uid) : 0; | ||||||
|  | 	async.parallel({ | ||||||
|  | 		canRead: function(next) { | ||||||
|  | 			privileges.posts.can('read', req.params.pid, uid, next); | ||||||
|  | 		}, | ||||||
|  | 		postData: function(next) { | ||||||
|  | 			posts.getPostData(req.params.pid, next); | ||||||
|  | 		} | ||||||
|  | 	}, function(err, results) { | ||||||
|  | 		if (err) { | ||||||
|  | 			return next(err); | ||||||
|  | 		} | ||||||
|  | 		if (!results.postData) { | ||||||
|  | 			return helpers.notFound(req, res); | ||||||
|  | 		} | ||||||
|  | 		if (!results.canRead) { | ||||||
|  | 			return helpers.notAllowed(req, res); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		res.json(results.postData); | ||||||
|  | 	}); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | module.exports = postsController; | ||||||
| @@ -13,9 +13,6 @@ module.exports = function(Posts) { | |||||||
| 			}, | 			}, | ||||||
| 			function(tid, next) { | 			function(tid, next) { | ||||||
| 				topics.getTopicField(tid, 'cid', next); | 				topics.getTopicField(tid, 'cid', next); | ||||||
| 			}, |  | ||||||
| 			function(cid, next) { |  | ||||||
| 				next(!cid ? new Error('[[error:invalid-cid]]') : null, cid); |  | ||||||
| 			}			 | 			}			 | ||||||
| 		], callback); | 		], callback); | ||||||
| 	}; | 	}; | ||||||
|   | |||||||
| @@ -46,6 +46,9 @@ module.exports = function(privileges) { | |||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	privileges.categories.can = function(privilege, cid, uid, callback) { | 	privileges.categories.can = function(privilege, cid, uid, callback) { | ||||||
|  | 		if (!cid) { | ||||||
|  | 			return callback(null, false); | ||||||
|  | 		} | ||||||
| 		categories.getCategoryField(cid, 'disabled', function(err, disabled) { | 		categories.getCategoryField(cid, 'disabled', function(err, disabled) { | ||||||
| 			if (err) { | 			if (err) { | ||||||
| 				return callback(err); | 				return callback(err); | ||||||
|   | |||||||
| @@ -153,9 +153,10 @@ module.exports = function(privileges) { | |||||||
| 		helpers.some([ | 		helpers.some([ | ||||||
| 			function(next) { | 			function(next) { | ||||||
| 				posts.getCidByPid(pid, function(err, cid) { | 				posts.getCidByPid(pid, function(err, cid) { | ||||||
| 					if (err) { | 					if (err || !cid) { | ||||||
| 						return next(err); | 						return next(err, false); | ||||||
| 					} | 					} | ||||||
|  | 					 | ||||||
| 					user.isModerator(uid, cid, next); | 					user.isModerator(uid, cid, next); | ||||||
| 				}); | 				}); | ||||||
| 			}, | 			}, | ||||||
|   | |||||||
| @@ -16,6 +16,7 @@ module.exports =  function(app, middleware, controllers) { | |||||||
| 	router.get('/widgets/render', controllers.api.renderWidgets); | 	router.get('/widgets/render', controllers.api.renderWidgets); | ||||||
|  |  | ||||||
| 	router.get('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.accounts.getUserByUID); | 	router.get('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.accounts.getUserByUID); | ||||||
|  | 	router.get('/post/:pid', controllers.posts.getPost); | ||||||
| 	router.get('/get_templates_listing', templatesController.getTemplatesListing); | 	router.get('/get_templates_listing', templatesController.getTemplatesListing); | ||||||
| 	router.get('/categories/:cid/moderators', getModerators); | 	router.get('/categories/:cid/moderators', getModerators); | ||||||
| 	router.get('/recent/posts/:term?', getRecentPosts); | 	router.get('/recent/posts/:term?', getRecentPosts); | ||||||
|   | |||||||
| @@ -41,6 +41,10 @@ module.exports = function(Topics) { | |||||||
| 				posts.getCidByPid(mainPid, callback); | 				posts.getCidByPid(mainPid, callback); | ||||||
| 			} | 			} | ||||||
| 		}, function(err, results) { | 		}, function(err, results) { | ||||||
|  | 			if (err) { | ||||||
|  | 				return callback(err); | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
| 			Topics.create({uid: results.postData.uid, title: title, cid: results.cid}, function(err, tid) { | 			Topics.create({uid: results.postData.uid, title: title, cid: results.cid}, function(err, tid) { | ||||||
| 				if (err) { | 				if (err) { | ||||||
| 					return callback(err); | 					return callback(err); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user