From f2341ca9d3c1335cbd04322c123d98d03a401e7d Mon Sep 17 00:00:00 2001 From: gaba Date: Thu, 9 Feb 2017 09:17:56 -0800 Subject: [PATCH] Adds tag label plugin. --- client/coral-embed-stream/src/Comment.js | 9 +++++++ client/coral-plugin-tag-label/TagLabel.js | 18 +++++++++++++ client/coral-plugin-tag-label/styles.css | 5 ++++ models/comment.js | 32 ++++++++++++++++++---- services/comments.js | 33 +++++++++++------------ services/users.js | 7 +++-- 6 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 client/coral-plugin-tag-label/TagLabel.js create mode 100644 client/coral-plugin-tag-label/styles.css diff --git a/client/coral-embed-stream/src/Comment.js b/client/coral-embed-stream/src/Comment.js index c0c0d57d1..83a950a9f 100644 --- a/client/coral-embed-stream/src/Comment.js +++ b/client/coral-embed-stream/src/Comment.js @@ -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 {
+
diff --git a/client/coral-plugin-tag-label/TagLabel.js b/client/coral-plugin-tag-label/TagLabel.js new file mode 100644 index 000000000..103982138 --- /dev/null +++ b/client/coral-plugin-tag-label/TagLabel.js @@ -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 ( +
+ {tags && tags} +
+ ); + } +} diff --git a/client/coral-plugin-tag-label/styles.css b/client/coral-plugin-tag-label/styles.css new file mode 100644 index 000000000..eee8d7201 --- /dev/null +++ b/client/coral-plugin-tag-label/styles.css @@ -0,0 +1,5 @@ +.tagLabel { + color: black; + display: inline-block; + margin: 10px 0; +} diff --git a/models/comment.js b/models/comment.js index 42b7425b9..b6848d0bc 100644 --- a/models/comment.js +++ b/models/comment.js @@ -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: { diff --git a/services/comments.js b/services/comments.js index bca56a2db..876128c47 100644 --- a/services/comments.js +++ b/services/comments.js @@ -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(); } /** diff --git a/services/users.js b/services/users.js index e7049a347..9d3d57532 100644 --- a/services/users.js +++ b/services/users.js @@ -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; }); } };