|
|
|
@ -42,6 +42,10 @@ class PostService extends SiteService {
|
|
|
|
|
async createPlaceholder (author) {
|
|
|
|
|
const NOW = new Date();
|
|
|
|
|
|
|
|
|
|
if (!author.permissions.canAuthorPosts) {
|
|
|
|
|
throw new SiteError(403, 'You are not permitted to author posts');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let post = new Post();
|
|
|
|
|
post.created = NOW;
|
|
|
|
|
post.authorType = author.type;
|
|
|
|
@ -51,7 +55,7 @@ class PostService extends SiteService {
|
|
|
|
|
await post.save();
|
|
|
|
|
|
|
|
|
|
post = post.toObject();
|
|
|
|
|
post.author = author; // I'll populate it myself
|
|
|
|
|
post.author = author; // self-populate instead of calling db
|
|
|
|
|
|
|
|
|
|
return post;
|
|
|
|
|
}
|
|
|
|
@ -59,6 +63,13 @@ class PostService extends SiteService {
|
|
|
|
|
async create (author, postDefinition) {
|
|
|
|
|
const NOW = new Date();
|
|
|
|
|
|
|
|
|
|
if (!author.permissions.canAuthorPosts) {
|
|
|
|
|
throw new SiteError(403, 'You are not permitted to author posts');
|
|
|
|
|
}
|
|
|
|
|
if ((postDefinition.status === 'published') && !author.permisstions.canPublishPosts) {
|
|
|
|
|
throw new SiteError(403, 'You are not permitted to publish posts');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const post = new Post();
|
|
|
|
|
post.created = NOW;
|
|
|
|
|
post.authorType = author.type;
|
|
|
|
@ -78,9 +89,13 @@ class PostService extends SiteService {
|
|
|
|
|
return post.toObject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async update (post, postDefinition) {
|
|
|
|
|
async update (user, post, postDefinition) {
|
|
|
|
|
const { coreNode: coreNodeService } = this.dtp.services;
|
|
|
|
|
|
|
|
|
|
if (!user.permissions.canAuthorPosts) {
|
|
|
|
|
throw new SiteError(403, 'You are not permitted to author posts');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NOW = new Date();
|
|
|
|
|
const updateOp = {
|
|
|
|
|
$setOnInsert: {
|
|
|
|
@ -113,6 +128,12 @@ class PostService extends SiteService {
|
|
|
|
|
if (!postDefinition.status) {
|
|
|
|
|
throw new SiteError(406, 'Must include post status');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (post.status !== 'published' && postDefinition.status === 'published') {
|
|
|
|
|
if (!user.permissions.canPublishPosts) {
|
|
|
|
|
throw new SiteError(403, 'You are not permitted to publish posts');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
updateOp.$set.status = striptags(postDefinition.status.trim());
|
|
|
|
|
|
|
|
|
|
updateOp.$set['flags.enableComments'] = postDefinition.enableComments === 'on';
|
|
|
|
@ -149,6 +170,11 @@ class PostService extends SiteService {
|
|
|
|
|
|
|
|
|
|
async updateImage (user, post, file) {
|
|
|
|
|
const { image: imageService } = this.dtp.services;
|
|
|
|
|
|
|
|
|
|
if (!user.permissions.canAuthorPosts) {
|
|
|
|
|
throw new SiteError(403, 'You are not permitted to change posts');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const images = [
|
|
|
|
|
{
|
|
|
|
|
width: 960,
|
|
|
|
|