mirror of
https://github.com/wassname/talk.git
synced 2026-07-17 11:33:39 +08:00
Adds tag label plugin.
This commit is contained in:
@@ -10,6 +10,7 @@ import React, {PropTypes} from 'react';
|
||||
import PermalinkButton from 'coral-plugin-permalinks/PermalinkButton';
|
||||
|
||||
import AuthorName from 'coral-plugin-author-name/AuthorName';
|
||||
import TagLabel from 'coral-plugin-tag-label/TagLabel';
|
||||
import Content from 'coral-plugin-commentcontent/CommentContent';
|
||||
import PubDate from 'coral-plugin-pubdate/PubDate';
|
||||
import {ReplyBox, ReplyButton} from 'coral-plugin-replies';
|
||||
@@ -58,6 +59,12 @@ class Comment extends React.Component {
|
||||
PropTypes.shape({
|
||||
body: PropTypes.string.isRequired,
|
||||
id: PropTypes.string.isRequired
|
||||
})),
|
||||
tags: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
name: PropTypes.string,
|
||||
assigned_by: PropTypes.string,
|
||||
created_at: PropTypes.string
|
||||
})
|
||||
),
|
||||
user: PropTypes.shape({
|
||||
@@ -95,6 +102,8 @@ class Comment extends React.Component {
|
||||
<hr aria-hidden={true} />
|
||||
<AuthorName
|
||||
author={comment.user}/>
|
||||
<TagLabel
|
||||
tags={comment.tags}/>
|
||||
<PubDate created_at={comment.created_at} />
|
||||
<Content body={comment.body} />
|
||||
<div className="commentActionsLeft">
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import React, {Component} from 'react';
|
||||
const packagename = 'coral-plugin-tag-label';
|
||||
import styles from './styles.css';
|
||||
|
||||
export default class TagLabel extends Component {
|
||||
|
||||
render () {
|
||||
const {tags} = this.props;
|
||||
console.log('DEBUG ', tags);
|
||||
return (
|
||||
<div
|
||||
className={`${packagename}-text`}
|
||||
className={`${styles.tagLabel}`}>
|
||||
{tags && tags}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
.tagLabel {
|
||||
color: black;
|
||||
display: inline-block;
|
||||
margin: 10px 0;
|
||||
}
|
||||
+27
-5
@@ -9,6 +9,11 @@ const STATUSES = [
|
||||
null
|
||||
];
|
||||
|
||||
const TAGS = [
|
||||
'STAFF',
|
||||
null
|
||||
];
|
||||
|
||||
/**
|
||||
* The Mongo schema for a Comment Status.
|
||||
* @type {Schema}
|
||||
@@ -30,6 +35,27 @@ const StatusSchema = new Schema({
|
||||
_id: false
|
||||
});
|
||||
|
||||
/**
|
||||
* The Mongo schema for a Comment Tag.
|
||||
* @type {Schema}
|
||||
*/
|
||||
const TagSchema = new Schema({
|
||||
name: {
|
||||
type: String,
|
||||
enum: TAGS,
|
||||
},
|
||||
|
||||
// The User ID of the user that assigned the status.
|
||||
assigned_by: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
|
||||
created_at: Date
|
||||
}, {
|
||||
_id: false
|
||||
});
|
||||
|
||||
/**
|
||||
* The Mongo schema for a Comment.
|
||||
* @type {Schema}
|
||||
@@ -49,11 +75,7 @@ const CommentSchema = new Schema({
|
||||
author_id: String,
|
||||
status_history: [StatusSchema],
|
||||
status: {type: String, default: null},
|
||||
tags: [{
|
||||
name: String,
|
||||
assigned_by: String,
|
||||
created_at: Date
|
||||
}],
|
||||
tags: [TagSchema],
|
||||
parent_id: String
|
||||
}, {
|
||||
timestamps: {
|
||||
|
||||
+16
-17
@@ -27,26 +27,25 @@ module.exports = class CommentsService {
|
||||
author_id
|
||||
} = comment;
|
||||
|
||||
comment = new CommentModel({
|
||||
body,
|
||||
asset_id,
|
||||
parent_id,
|
||||
status_history: status ? [{
|
||||
type: status,
|
||||
created_at: new Date()
|
||||
}] : [],
|
||||
status,
|
||||
tags: [
|
||||
{
|
||||
name: UsersService.isStaff(author_id) ? 'STAFF' : null,
|
||||
return UsersService.isStaff(author_id).then((isStaff) => {
|
||||
comment = new CommentModel({
|
||||
body,
|
||||
asset_id,
|
||||
parent_id,
|
||||
status_history: status ? [{
|
||||
type: status,
|
||||
created_at: new Date()
|
||||
}] : [],
|
||||
status,
|
||||
tags: isStaff ? [{
|
||||
name: 'STAFF',
|
||||
assigned_by: null,
|
||||
created_at: new Date()
|
||||
}
|
||||
],
|
||||
author_id
|
||||
}] : [],
|
||||
author_id
|
||||
});
|
||||
return comment.save();
|
||||
});
|
||||
|
||||
return comment.save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+5
-2
@@ -694,8 +694,11 @@ module.exports = class UsersService {
|
||||
* @return {Promise}
|
||||
*/
|
||||
static isStaff(id) {
|
||||
return UserModel.findById(id).then((user) => {
|
||||
return user.hasRoles('ADMIN');
|
||||
return UsersService.findById(id).then((user) => {
|
||||
if (user) {
|
||||
return user.hasRoles('ADMIN');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user