diff --git a/.gitignore b/.gitignore index 00c8845..1616fc5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ ssl/*crt ssl/*key data/minio +data/minio.old node_modules dist diff --git a/app/controllers/newsroom.js b/app/controllers/newsroom.js index 1b90af0..c2bbfb9 100644 --- a/app/controllers/newsroom.js +++ b/app/controllers/newsroom.js @@ -60,7 +60,16 @@ class NewsroomController extends SiteController { try { res.locals.pagination = this.getPaginationParameters(req, 20); res.locals.newsroom = await feedService.getNewsfeed(res.locals.pagination); - res.render('newsroom/unified-feed'); + + switch (req.query.fmt) { + case 'json': + res.status(200).json(res.locals.newsroom); + break; + + default: + res.render('newsroom/unified-feed'); + break; + } } catch (error) { this.log.error('failed to present newsfeed JSON', { error }); res.status(error.statusCode || 500).json({ diff --git a/app/models/user.js b/app/models/user.js index 63d5d72..5edef6c 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -45,14 +45,17 @@ const UserSchema = new Schema({ }); UserSchema.virtual('hasAuthorPermissions').get( function ( ) { - return this.permissions.canAuthorPages || this.permissions.canAuthorPosts; + return !!this && !!this.permissions && (this.permissions.canAuthorPages || this.permissions.canAuthorPosts); }); UserSchema.virtual('hasPublishPermissions').get( function ( ) { - return this.permissions.canPublishPages || this.permissions.canPublishPosts; + return !!this && !!this.permissions && (this.permissions.canPublishPages || this.permissions.canPublishPosts); }); UserSchema.virtual('hasAuthorDashboard').get( function ( ) { + if (!this || !this.permissions) { + return false; + } return this.permissions.canAuthorPages || this.permissions.cahAuthorPosts || this.permissions.canPublishPages ||