Add check in logic for user when loading non-published post

Alternative to error page before:

`Cannot read properties of undefined (reading '_id')` during checking `!res.locals.post.author._id.equals(req.user._id)` in line 268.
master
CyberShell 2 years ago
parent 1273baac1a
commit 26e6fd9b53

@ -260,7 +260,8 @@ class PostController extends SiteController {
async getView (req, res, next) {
const { comment: commentService, resource: resourceService } = this.dtp.services;
try {
if ((res.locals.post.status !== 'published') &&
if ((res.locals.post.status !== 'published') &&
req.user &&
!res.locals.post.author._id.equals(req.user._id) &&
!req.user.hasAuthorDashboard) {
throw new SiteError(403, 'The post is not published');

Loading…
Cancel
Save