diff --git a/config/env/torrents.js b/config/env/torrents.js index 0371efde..6a64960e 100644 --- a/config/env/torrents.js +++ b/config/env/torrents.js @@ -77,7 +77,9 @@ module.exports = { userInvitationExchange: {name: 'userInvitationExchange', enable: true}, userAnnounceData: {name: 'userAnnounceData', enable: true}, - userScoreChange: {name: 'userScoreChange', enable: true} + userScoreChange: {name: 'userScoreChange', enable: true}, + + forumDeleteTopic: {name: 'forumDeleteTopic', enable: true} } }, torrentType: { diff --git a/modules/core/client/app/trans-string-en.js b/modules/core/client/app/trans-string-en.js index 1c7fd9b8..bbfc2f8b 100644 --- a/modules/core/client/app/trans-string-en.js +++ b/modules/core/client/app/trans-string-en.js @@ -655,6 +655,12 @@ POST_SEND_FAILED: 'Post new topic failed', REPLY_EDIT_SUCCESSFULLY: 'Reply content modify successfully', REPLY_EDIT_FAILED: 'Reply content modify failed', + DELETE_TOPIC_SUCCESSFULLY: 'Topic deleted successfully', + DELETE_TOPIC_FAILED: 'Topic deleted failed', + DELETE_TOPIC_CONFIRM_OK: 'Delete', + DELETE_TOPIC_CONFIRM_CANCEL: 'Cancel', + DELETE_TOPIC_CONFIRM_HEADER_TEXT: 'Delete Topic', + DELETE_TOPIC_CONFIRM_BODY_TEXT: 'Are you sure want to delete this topic?', CATEGORY: { AFFAIRS: 'Affairs', @@ -682,9 +688,11 @@ REPLY_BY_3: 'post at {{createdAt}}' }, TITLES: { - QUOTE: 'quote and reply', - EDIT: 'edit reply', - DELETE: 'delete reply' + REPLY_QUOTE: 'quote and reply', + REPLY_EDIT: 'edit reply', + REPLY_DELETE: 'delete reply', + TOPIC_EDIT: 'edit topic', + TOPIC_DELETE: 'delete topic' } }, diff --git a/modules/core/client/app/trans-string-zh.js b/modules/core/client/app/trans-string-zh.js index 4d5bb966..79b15d71 100644 --- a/modules/core/client/app/trans-string-zh.js +++ b/modules/core/client/app/trans-string-zh.js @@ -655,6 +655,12 @@ POST_SEND_FAILED: '新话题发布失败', REPLY_EDIT_SUCCESSFULLY: '回复内容修改成功', REPLY_EDIT_FAILED: '回复内容修改失败', + DELETE_TOPIC_SUCCESSFULLY: '话题删除成功', + DELETE_TOPIC_FAILED: '话题删除失败', + DELETE_TOPIC_CONFIRM_OK: '删除', + DELETE_TOPIC_CONFIRM_CANCEL: '取消', + DELETE_TOPIC_CONFIRM_HEADER_TEXT: '删除确认', + DELETE_TOPIC_CONFIRM_BODY_TEXT: '您确定要删除这个话题?', CATEGORY: { AFFAIRS: '站务区', @@ -682,9 +688,11 @@ REPLY_BY_3: '发表于 at {{createdAt}}' }, TITLES: { - QUOTE: '引用并回复', - EDIT: '编辑回复', - DELETE: '删除回复' + REPLY_QUOTE: '引用并回复', + REPLY_EDIT: '编辑回复', + REPLY_DELETE: '删除回复', + TOPIC_EDIT: '编辑话题', + TOPIC_DELETE: '删除话题' } }, diff --git a/modules/forums/client/controllers/forums-post.client.controller.js b/modules/forums/client/controllers/forums-post.client.controller.js index ebe0f13c..b3e692e0 100644 --- a/modules/forums/client/controllers/forums-post.client.controller.js +++ b/modules/forums/client/controllers/forums-post.client.controller.js @@ -50,7 +50,7 @@ } var post = new TopicsService(vm.postFields); - post._forumId = vm.forum._id; + post.forum = vm.forum._id; post.$save(function (response) { successCallback(response); diff --git a/modules/forums/client/controllers/forums-topic.client.controller.js b/modules/forums/client/controllers/forums-topic.client.controller.js index 702b1d36..0332509f 100644 --- a/modules/forums/client/controllers/forums-topic.client.controller.js +++ b/modules/forums/client/controllers/forums-topic.client.controller.js @@ -96,10 +96,10 @@ }; /** - * beginEditReply + * beginEditTopic * @param t */ - vm.beginEditReply = function (t) { + vm.beginEditTopic = function (t) { var el = $('#' + t._id); el.markdown({ @@ -147,5 +147,28 @@ } }); }; + + /** + * beginDeleteTopic + * @param t + */ + vm.beginDeleteTopic = function (t) { + var modalOptions = { + closeButtonText: $translate.instant('FORUMS.DELETE_TOPIC_CONFIRM_CANCEL'), + actionButtonText: $translate.instant('FORUMS.DELETE_TOPIC_CONFIRM_OK'), + headerText: $translate.instant('FORUMS.DELETE_TOPIC_CONFIRM_HEADER_TEXT'), + bodyText: $translate.instant('FORUMS.DELETE_TOPIC_CONFIRM_BODY_TEXT') + }; + + ModalConfirmService.showModal({}, modalOptions) + .then(function (result) { + vm.topic.$remove(function (res) { + NotifycationService.showSuccessNotify('FORUMS.DELETE_TOPIC_SUCCESSFULLY'); + $state.go('forums.view', {forumId: vm.forum._id}); + }, function (res) { + NotifycationService.showErrorNotify(res.data.message, 'FORUMS.DELETE_TOPIC_FAILED'); + }); + }); + }; } }()); diff --git a/modules/forums/client/views/topic.client.view.html b/modules/forums/client/views/topic.client.view.html index 9a881195..9eec746f 100644 --- a/modules/forums/client/views/topic.client.view.html +++ b/modules/forums/client/views/topic.client.view.html @@ -92,14 +92,15 @@
diff --git a/modules/forums/server/controllers/forums.admin.server.controller.js b/modules/forums/server/controllers/forums.admin.server.controller.js index d3205308..1885854d 100644 --- a/modules/forums/server/controllers/forums.admin.server.controller.js +++ b/modules/forums/server/controllers/forums.admin.server.controller.js @@ -106,6 +106,12 @@ exports.addModerator = function (req, res) { } }; +/** + * removeModerator + * @param req + * @param res + * @returns {*} + */ exports.removeModerator = function (req, res) { var forum = req.forum; var mu = req.nameuser; diff --git a/modules/forums/server/controllers/forums.server.controller.js b/modules/forums/server/controllers/forums.server.controller.js index 6d6e700c..2c1d2f15 100644 --- a/modules/forums/server/controllers/forums.server.controller.js +++ b/modules/forums/server/controllers/forums.server.controller.js @@ -10,7 +10,10 @@ var path = require('path'), User = mongoose.model('User'), Forum = mongoose.model('Forum'), Topic = mongoose.model('Topic'), - async = require('async'); + async = require('async'), + traceLogCreate = require(path.resolve('./config/lib/tracelog')).create; + +var traceConfig = config.meanTorrentConfig.trace; /** * list forums @@ -57,7 +60,7 @@ exports.listTopics = function (req, res) { Topic.find({ forum: req.params.forumId }) - .sort('-isTop -createdAt') + .sort('-isTop -lastReplyAt -createdAt') .populate('user', 'username displayName profileImageURL uploaded downloaded') .populate('lastUser', 'username displayName profileImageURL uploaded downloaded') .exec(function (err, topics) { @@ -130,6 +133,45 @@ exports.updateTopic = function (req, res) { }); }; +/** + * deleteTopic + * @param req + * @param res + */ +exports.deleteTopic = function (req, res) { + var forum = req.forum; + var topic = req.topic; + + topic.remove(function (err) { + if (err) { + return res.status(422).send({ + message: errorHandler.getErrorMessage(err) + }); + } else { + res.json(topic); + } + }); + + //create trace log + traceLogCreate(req, traceConfig.action.forumDeleteTopic, { + forum: forum._id, + topic: topic._id + }); + + Topic.findOne({ + forum: forum._id + }) + .sort('-lastReplyAt -createdAt') + .exec(function (err, topic) { + if (!err) { + forum.update({ + $inc: {topicCount: -1}, + lastTopic: topic + }).exec(); + } + }); +}; + /** * Invitation middleware */ diff --git a/modules/forums/server/models/topic.server.model.js b/modules/forums/server/models/topic.server.model.js index fef64019..dcb07c57 100644 --- a/modules/forums/server/models/topic.server.model.js +++ b/modules/forums/server/models/topic.server.model.js @@ -92,7 +92,8 @@ var TopicSchema = new Schema({ ref: 'User' }, lastReplyAt: { - type: Date + type: Date, + default: Date.now }, updatedAt: { type: Date diff --git a/modules/forums/server/routes/forums.server.routes.js b/modules/forums/server/routes/forums.server.routes.js index 92ed3bdc..7dc28b81 100644 --- a/modules/forums/server/routes/forums.server.routes.js +++ b/modules/forums/server/routes/forums.server.routes.js @@ -19,7 +19,8 @@ module.exports = function (app) { app.route('/api/topics/:forumId/:topicId').all(forumsPolicy.isAllowed) .get(forums.readTopic) - .put(forums.updateTopic); + .put(forums.updateTopic) + .delete(forums.deleteTopic); app.param('topicId', forums.topicById); }; diff --git a/modules/traces/server/controllers/traces.server.controller.js b/modules/traces/server/controllers/traces.server.controller.js index 9af0bda4..198f3996 100644 --- a/modules/traces/server/controllers/traces.server.controller.js +++ b/modules/traces/server/controllers/traces.server.controller.js @@ -25,6 +25,10 @@ exports.list = function (req, res) { select: 'username displayName', model: 'User' }) + .populate({ + path: 'content.forum', + model: 'Forum' + }) .exec(function (err, traces) { if (err) { return res.status(422).send({