diff --git a/public/src/client/notifications.js b/public/src/client/notifications.js index 024fe6715c..fb778ec18f 100644 --- a/public/src/client/notifications.js +++ b/public/src/client/notifications.js @@ -1,10 +1,19 @@ +'use strict'; + +/* globals define, socket, app */ + define('forum/notifications', function() { var Notifications = {}; Notifications.init = function() { var listEl = $('.notifications-list'); - listEl.on('click', 'li', function(e) { - this.querySelector('a').click(); + listEl.on('click', 'a', function(e) { + var nid = $(this).parents('[data-nid]').attr('data-nid'); + socket.emit('notifications.markRead', nid, function(err) { + if (err) { + return app.alertError(err); + } + }); }); $('span.timeago').timeago(); @@ -20,8 +29,7 @@ define('forum/notifications', function() { listEl.empty(); }); }); - - } + }; return Notifications; }); diff --git a/src/controllers/index.js b/src/controllers/index.js index 8a43da5c9f..d8ddf81735 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -16,6 +16,7 @@ var async = require('async'), helpers = require('./helpers'); var Controllers = { + posts: require('./posts'), topics: require('./topics'), categories: require('./categories'), tags: require('./tags'), diff --git a/src/controllers/posts.js b/src/controllers/posts.js new file mode 100644 index 0000000000..e5a32e9791 --- /dev/null +++ b/src/controllers/posts.js @@ -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; diff --git a/src/posts/category.js b/src/posts/category.js index 761738cb1f..68ae42474b 100644 --- a/src/posts/category.js +++ b/src/posts/category.js @@ -13,10 +13,7 @@ module.exports = function(Posts) { }, function(tid, next) { topics.getTopicField(tid, 'cid', next); - }, - function(cid, next) { - next(!cid ? new Error('[[error:invalid-cid]]') : null, cid); - } + } ], callback); }; diff --git a/src/privileges/categories.js b/src/privileges/categories.js index 5ff70730d4..267c9e2c81 100644 --- a/src/privileges/categories.js +++ b/src/privileges/categories.js @@ -46,6 +46,9 @@ module.exports = function(privileges) { }; privileges.categories.can = function(privilege, cid, uid, callback) { + if (!cid) { + return callback(null, false); + } categories.getCategoryField(cid, 'disabled', function(err, disabled) { if (err) { return callback(err); diff --git a/src/privileges/posts.js b/src/privileges/posts.js index 7de1167726..7c304a1a2c 100644 --- a/src/privileges/posts.js +++ b/src/privileges/posts.js @@ -153,9 +153,10 @@ module.exports = function(privileges) { helpers.some([ function(next) { posts.getCidByPid(pid, function(err, cid) { - if (err) { - return next(err); + if (err || !cid) { + return next(err, false); } + user.isModerator(uid, cid, next); }); }, diff --git a/src/routes/api.js b/src/routes/api.js index 47632ccce7..ef1c297e49 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -16,6 +16,7 @@ module.exports = function(app, middleware, controllers) { router.get('/widgets/render', controllers.api.renderWidgets); 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('/categories/:cid/moderators', getModerators); router.get('/recent/posts/:term?', getRecentPosts); diff --git a/src/socket.io/admin/categories.js b/src/socket.io/admin/categories.js index 9a9ef0ea7e..55d8300819 100644 --- a/src/socket.io/admin/categories.js +++ b/src/socket.io/admin/categories.js @@ -113,12 +113,18 @@ Categories.setGroupPrivilege = function(socket, data, callback) { Categories.groupsList = function(socket, cid, callback) { groups.list({ expand: false, + isAdmin: true, showSystemGroups: true }, function(err, data) { if(err) { return callback(err); } + // Remove privilege groups + data = data.filter(function(groupObj) { + return groupObj.name.indexOf(':privileges:') === -1; + }); + async.map(data, function(groupObj, next) { privileges.categories.groupPrivileges(cid, groupObj.name, function(err, privileges) { if(err) { diff --git a/src/topics/fork.js b/src/topics/fork.js index 4cd5e0c53e..3302797f38 100644 --- a/src/topics/fork.js +++ b/src/topics/fork.js @@ -41,6 +41,10 @@ module.exports = function(Topics) { posts.getCidByPid(mainPid, callback); } }, function(err, results) { + if (err) { + return callback(err); + } + Topics.create({uid: results.postData.uid, title: title, cid: results.cid}, function(err, tid) { if (err) { return callback(err); diff --git a/src/views/admin/header.tpl b/src/views/admin/header.tpl index 89b0dc4ac4..4193857410 100644 --- a/src/views/admin/header.tpl +++ b/src/views/admin/header.tpl @@ -16,100 +16,100 @@ - - - - + + + - - - - - - - - - - + app.inAdmin = true; + + + + + + + + + + + - - - - + + + + -
-