mirror of
https://github.com/wassname/talk.git
synced 2026-07-30 12:40:41 +08:00
Moved the moderation queue to its own folder and change the route to /queue/comments/pending
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
const express = require('express');
|
||||
const Comment = require('../../../models/comment');
|
||||
|
||||
const Setting = require('../../../models/setting');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
//==============================================================================
|
||||
@@ -25,11 +23,7 @@ router.get('/:comment_id', (req, res, next) => {
|
||||
});
|
||||
});
|
||||
|
||||
//==============================================================================
|
||||
// Moderation Queues Routes
|
||||
//==============================================================================
|
||||
|
||||
// Get all the comments that have that action_type over them.
|
||||
// Get all the comments that have an action_type over them.
|
||||
router.get('/action/:action_type', (req, res, next) => {
|
||||
Comment.findByActionType(req.params.action_type).then((comments) => {
|
||||
res.status(200).json(comments);
|
||||
@@ -47,19 +41,19 @@ router.get('/status/rejected', (req, res, next) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Returns back all the comments that are in the moderation queue. The moderation queue is pre or post moderated,
|
||||
// depending on the settings. The :moderation overwrites this settings.
|
||||
// Pre-moderation: New comments are shown in the moderator queues immediately.
|
||||
// Post-moderation: New comments do not appear in moderation queues unless they are flagged by other users.
|
||||
router.get('/status/pending', (req, res, next) => {
|
||||
Setting.getModerationSetting().then(function({moderation}){
|
||||
let moderationValue = req.query.moderation;
|
||||
if (typeof moderationValue === 'undefined' || moderationValue === undefined) {
|
||||
moderationValue = moderation;
|
||||
}
|
||||
Comment.moderationQueue(moderationValue).then((comments) => {
|
||||
res.status(200).json(comments);
|
||||
});
|
||||
// Get all the comments that were accepted.
|
||||
router.get('/status/accepted', (req, res, next) => {
|
||||
Comment.findByStatus('accepted').then((comments) => {
|
||||
res.status(200).json(comments);
|
||||
}).catch(error => {
|
||||
next(error);
|
||||
});
|
||||
});
|
||||
|
||||
// Get all the not moderated comments.
|
||||
router.get('/status/new', (req, res, next) => {
|
||||
Comment.findByStatus('').then((comments) => {
|
||||
res.status(200).json(comments);
|
||||
}).catch(error => {
|
||||
next(error);
|
||||
});
|
||||
@@ -94,7 +88,7 @@ router.post('/:comment_id', (req, res, next) => {
|
||||
});
|
||||
|
||||
router.post('/:comment_id/status', (req, res, next) => {
|
||||
|
||||
|
||||
Comment
|
||||
.changeStatus(req.params.comment_id, req.body.status)
|
||||
.then(comment => res.status(200).send(comment))
|
||||
|
||||
@@ -4,6 +4,7 @@ const router = express.Router();
|
||||
|
||||
router.use('/asset', require('./asset'));
|
||||
router.use('/comments', require('./comments'));
|
||||
router.use('/queue', require('./queue'));
|
||||
router.use('/settings', require('./settings'));
|
||||
router.use('/stream', require('./stream'));
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
const express = require('express');
|
||||
const Comment = require('../../../models/comment');
|
||||
|
||||
const Setting = require('../../../models/setting');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
//==============================================================================
|
||||
// Get Routes
|
||||
//==============================================================================
|
||||
|
||||
// Returns back all the comments that are in the moderation queue. The moderation queue is pre or post moderated,
|
||||
// depending on the settings. The :moderation overwrites this settings.
|
||||
// Pre-moderation: New comments are shown in the moderator queues immediately.
|
||||
// Post-moderation: New comments do not appear in moderation queues unless they are flagged by other users.
|
||||
router.get('/comments/pending', (req, res, next) => {
|
||||
Setting.getModerationSetting().then(function({moderation}){
|
||||
let moderationValue = req.query.moderation;
|
||||
if (typeof moderationValue === 'undefined' || moderationValue === undefined) {
|
||||
moderationValue = moderation;
|
||||
}
|
||||
Comment.moderationQueue(moderationValue).then((comments) => {
|
||||
res.status(200).json(comments);
|
||||
});
|
||||
}).catch(error => {
|
||||
next(error);
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -75,7 +75,7 @@ describe('Get /comments', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Get moderation queues rejected, pending, flags', () => {
|
||||
describe('Get comments by status and action', () => {
|
||||
const comments = [{
|
||||
id: 'abc',
|
||||
body: 'comment 10',
|
||||
@@ -133,21 +133,20 @@ describe('Get moderation queues rejected, pending, flags', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return all the pending comments', function(done){
|
||||
it('should return all the approved comments', function(done){
|
||||
chai.request(app)
|
||||
.get('/api/v1/comments/status/pending')
|
||||
.get('/api/v1/comments/status/accepted')
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body[0]).to.have.property('id', 'def');
|
||||
expect(res.body[0]).to.have.property('id', 'hij');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return all the pending comments as pre moderated', function(done){
|
||||
it('should return all the new comments', function(done){
|
||||
chai.request(app)
|
||||
.get('/api/v1/comments/status/pending')
|
||||
.query({'moderation': 'pre'})
|
||||
.get('/api/v1/comments/status/new')
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
@@ -156,18 +155,6 @@ describe('Get moderation queues rejected, pending, flags', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return all the pending comments as post moderated', function(done){
|
||||
chai.request(app)
|
||||
.get('/api/v1/comments/status/pending')
|
||||
.query({'moderation': 'post'})
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body).to.have.lengthOf(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return all the flagged comments', function(done){
|
||||
chai.request(app)
|
||||
.get('/api/v1/comments/action/flag')
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
process.env.NODE_ENV = 'test';
|
||||
|
||||
require('../../../utils/mongoose');
|
||||
|
||||
const app = require('../../../../app');
|
||||
const chai = require('chai');
|
||||
const expect = chai.expect;
|
||||
|
||||
// Setup chai.
|
||||
chai.should();
|
||||
chai.use(require('chai-http'));
|
||||
|
||||
const Comment = require('../../../../models/comment');
|
||||
const Action = require('../../../../models/action');
|
||||
const User = require('../../../../models/user');
|
||||
|
||||
const Setting = require('../../../../models/setting');
|
||||
const settings = {id: '1', moderation: 'pre'};
|
||||
|
||||
beforeEach(() => {
|
||||
return Setting.create(settings);
|
||||
});
|
||||
|
||||
describe('Get moderation queues rejected, pending, flags', () => {
|
||||
const comments = [{
|
||||
id: 'abc',
|
||||
body: 'comment 10',
|
||||
asset_id: 'asset',
|
||||
author_id: '123',
|
||||
status: 'rejected'
|
||||
}, {
|
||||
id: 'def',
|
||||
body: 'comment 20',
|
||||
asset_id: 'asset',
|
||||
author_id: '456'
|
||||
}, {
|
||||
id: 'hij',
|
||||
body: 'comment 30',
|
||||
asset_id: '456',
|
||||
status: 'accepted'
|
||||
}];
|
||||
|
||||
const users = [{
|
||||
displayName: 'Ana',
|
||||
email: 'ana@gmail.com',
|
||||
password: '123'
|
||||
}, {
|
||||
displayName: 'Maria',
|
||||
email: 'maria@gmail.com',
|
||||
password: '123'
|
||||
}];
|
||||
|
||||
const actions = [{
|
||||
action_type: 'flag',
|
||||
item_id: 'abc',
|
||||
item_type: 'comment'
|
||||
}, {
|
||||
action_type: 'like',
|
||||
item_id: 'hij',
|
||||
item_type: 'comment'
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return Promise.all([
|
||||
Comment.create(comments),
|
||||
User.createLocalUsers(users),
|
||||
Action.create(actions)
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return all the pending comments', function(done){
|
||||
chai.request(app)
|
||||
.get('/api/v1/queue/comments/pending')
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body[0]).to.have.property('id', 'def');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return all the pending comments as pre moderated', function(done){
|
||||
chai.request(app)
|
||||
.get('/api/v1/queue/comments/pending')
|
||||
.query({'moderation': 'pre'})
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body[0]).to.have.property('id', 'def');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return all the pending comments as post moderated', function(done){
|
||||
chai.request(app)
|
||||
.get('/api/v1/queue/comments/pending')
|
||||
.query({'moderation': 'post'})
|
||||
.end(function(err, res){
|
||||
expect(err).to.be.null;
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body).to.have.lengthOf(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
from pymongo import MongoClient
|
||||
import requests
|
||||
|
||||
url = 'http://localhost:3000/api/v1/'
|
||||
url_asset = '%sasset' % url
|
||||
url_comment = '%scomments' % url
|
||||
|
||||
def main():
|
||||
client = MongoClient('localhost', 27017)
|
||||
db_wapo = client.original_wapo
|
||||
wcomments = db_wapo.comments
|
||||
|
||||
for comment in wcomments.find():
|
||||
ncomment = {}
|
||||
nasset = {}
|
||||
status = comment['object']['status']
|
||||
if (status == 'Untouched'):
|
||||
ncomment['status'] = ''
|
||||
elif (status == 'CommunityFlagged'):
|
||||
ncomment['status'] = ''
|
||||
elif (status == 'ModeratorApproved'):
|
||||
ncomment['status'] = 'accepted'
|
||||
elif (status == 'ModeratorDeleted'):
|
||||
ncomment['status'] = 'rejected'
|
||||
ncomment['body'] = comment['object']['content']
|
||||
nasset['url'] = comment['targets'][0]['conversationID']
|
||||
ncomment['asset_id'] = post_asset(nasset)
|
||||
ncomment['author_id'] = '1'
|
||||
post_comment(ncomment)
|
||||
|
||||
def post_asset(nasset):
|
||||
print 'Posting %s into %s.' % (nasset, url_asset)
|
||||
try:
|
||||
r = requests.put(url_asset, json=nasset)
|
||||
if 'id' in r.json():
|
||||
return r.json()['id']
|
||||
else:
|
||||
ra = requests.get(url_asset, { url: nasset['url']})
|
||||
return ra.json()['id']
|
||||
except:
|
||||
print('Error when getting asset.')
|
||||
return 'asset'
|
||||
|
||||
def post_comment(ncomment):
|
||||
print 'Posting %s into %s.' % (ncomment, url_comment)
|
||||
r = requests.post(url_comment, json=ncomment)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user