[fedi] comment/instance/user moderation

This commit is contained in:
les
2019-11-13 10:56:01 +01:00
parent fe9057e343
commit c944541d04
20 changed files with 545 additions and 177 deletions

View File

@@ -96,7 +96,7 @@ const eventController = {
{ model: Tag, attributes: ['tag', 'weigth'], through: { attributes: [] } },
{ model: User, attributes: ['username'] },
{ model: Place, attributes: ['name', 'address'] },
Comment
{ model: Comment, where: !is_admin && { hidden: false }, required: false }
],
order: [ [Comment, 'id', 'DESC'] ]
})

View File

@@ -0,0 +1,27 @@
const { fed_users: FedUsers, comment: Comment } = require('../models')
const fedUserController = {
async toggleBlock (req, res) {
const user_id = req.body.user_id
const user = await FedUsers.findByPk(user_id)
user.update({ blocked: !user.blocked })
res.json(user)
},
async hideComment (req, res) {
const comment_id = req.params.comment_id
const hidden = req.body.hidden
const comment = await Comment.findByPk(comment_id)
await comment.update({ hidden })
res.json(comment)
},
async removeComment (req, res) {
const comment_id = req.params.comment_id
const comment = await Comment.findByPk(comment_id)
await comment.destroy()
res.sendStatus(200)
}
}
module.exports = fedUserController

View File

@@ -1,5 +1,5 @@
const Sequelize = require('sequelize')
const { fed_users: FedUsers, instances: Instances } = require('../models')
const { fed_users: FedUsers, instances: Instances, comment: Comment } = require('../models')
const instancesController = {
async getAll (req, res) {
@@ -12,6 +12,15 @@ const instancesController = {
})
return res.json(instances)
},
/**
* get instance users
*/
async get (req, res) {
const fedi_users = await FedUsers.findAll({ where: { instanceDomain: req.params.instance_domain }, include: [Comment] })
return res.json(fedi_users)
},
async toggleBlock (req, res) {
const instance = await Instances.findByPk(req.body.instance)
if (!instance) { return res.status(404).send('Not found') }