add JSON output for newsroom unified feed; User model fixes

master
rob 1 year ago
parent 52604d5435
commit 43179e454b

1
.gitignore vendored

@ -4,5 +4,6 @@ ssl/*crt
ssl/*key
data/minio
data/minio.old
node_modules
dist

@ -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({

@ -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 ||

Loading…
Cancel
Save