mirror of
https://github.com/wassname/talk.git
synced 2026-09-12 13:01:11 +08:00
Adds Tag Model that will be apply to different models.
This commit is contained in:
@@ -30,27 +30,6 @@ const StatusSchema = new Schema({
|
||||
_id: false
|
||||
});
|
||||
|
||||
/**
|
||||
* The Mongo schema for a Comment Tag.
|
||||
* @type {Schema}
|
||||
*/
|
||||
const TagSchema = new Schema({
|
||||
name: String,
|
||||
|
||||
// The User ID of the user that assigned the status.
|
||||
assigned_by: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
|
||||
created_at: {
|
||||
type: Date,
|
||||
default: Date
|
||||
}
|
||||
}, {
|
||||
_id: false
|
||||
});
|
||||
|
||||
/**
|
||||
* The Mongo schema for a Comment.
|
||||
* @type {Schema}
|
||||
@@ -74,7 +53,6 @@ const CommentSchema = new Schema({
|
||||
enum: STATUSES,
|
||||
default: 'NONE'
|
||||
},
|
||||
tags: [TagSchema],
|
||||
parent_id: String,
|
||||
|
||||
// Additional metadata stored on the field.
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
const mongoose = require('../services/mongoose');
|
||||
const uuid = require('uuid');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
// in settings
|
||||
// --> decide who can apply them (self, role, anyone) and
|
||||
|
||||
// Who can see the tag (self, by role, anyone)
|
||||
const PRIVACY_TYPES = [
|
||||
'ADMIN',
|
||||
'SELF',
|
||||
'PUBLIC'
|
||||
];
|
||||
|
||||
// The type of item that the tag is apply on.
|
||||
const ITEM_TYPES = [
|
||||
'ASSETS',
|
||||
'COMMENTS',
|
||||
'USERS'
|
||||
];
|
||||
|
||||
/**
|
||||
* The Mongo schema for a Comment Tag.
|
||||
* @type {Schema}
|
||||
*/
|
||||
const TagSchema = new Schema({
|
||||
id: {
|
||||
type: String,
|
||||
default: uuid.v4,
|
||||
unique: true
|
||||
},
|
||||
|
||||
name: {
|
||||
type: String,
|
||||
unique: true
|
||||
},
|
||||
|
||||
item_type: {
|
||||
type: String,
|
||||
enum: ITEM_TYPES
|
||||
},
|
||||
|
||||
item_id: String,
|
||||
|
||||
// The User ID of the user that assigned the status.
|
||||
assigned_by: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
|
||||
privacy_type: {
|
||||
type: String,
|
||||
enum: PRIVACY_TYPES
|
||||
},
|
||||
|
||||
// Additional metadata stored on the field.
|
||||
metadata: Schema.Types.Mixed
|
||||
}, {
|
||||
_id: false
|
||||
});
|
||||
|
||||
const Tag = mongoose.model('Tag', TagSchema);
|
||||
|
||||
module.exports = Tag;
|
||||
+4
-2
@@ -185,7 +185,9 @@ const USER_GRAPH_OPERATIONS = [
|
||||
'mutation:suspendUser',
|
||||
'mutation:setCommentStatus',
|
||||
'mutation:addCommentTag',
|
||||
'mutation:removeCommentTag'
|
||||
'mutation:removeCommentTag',
|
||||
'mutation:addUserTag',
|
||||
'mutation:removeUserTag'
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -207,7 +209,7 @@ UserSchema.method('can', function(...actions) {
|
||||
|
||||
// {add,remove}CommentTag - requires admin and/or moderator role
|
||||
const userCanModifyTags = user => ['ADMIN', 'MODERATOR'].some(r => user.hasRoles(r));
|
||||
if (actions.some(a => ['mutation:removeCommentTag', 'mutation:addCommentTag'].includes(a)) && ! userCanModifyTags(this)) {
|
||||
if (actions.some(a => ['mutation:removeCommentTag', 'mutation:addCommentTag', 'mutation:removeUserTag', 'mutation: addUserTag'].includes(a)) && ! userCanModifyTags(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user