Merge pull request 'Added author and publisher view, made posts editable by publishers' (#29) from authorDashboard into develop

Reviewed-on: https://git.digitaltelepresence.com/digital-telepresence/dtp-sites/pulls/29
master
CyberShell 2 years ago
commit 7920ddc3da

@ -18,7 +18,7 @@ class SiteLinkAdminController extends SiteController {
const router = express.Router();
router.use(async (req, res, next) => {
res.locals.currentView = 'admin';
res.locals.adminView = 'venue';
res.locals.adminView = 'site-link';
return next();
});

@ -20,20 +20,32 @@ class AuthorController extends SiteController {
const { limiter: limiterService } = dtp.services;
const { author: authorLimiter } = limiterService.config;
async function checkPermissions(req, res, next) {
if (!req.user){
return res.redirect(302, '/');
}
const canAuthor = req.user.permissions.canAuthorPages || req.user.permissions.canAuthorPosts;
const canPublish = req.user.permissions.canPublishPages || req.user.permissions.canPublishPosts;
if (!canAuthor && !canPublish) {
return next(new SiteError(403, 'Author privileges are required'));
}
return next();
}
async function checkAuthorPublisherPermissions (req, res, next) {
res.locals.currentView = 'author';
const canAuthorOrPublish = await checkPermissions(req, res, next);
return canAuthorOrPublish;
}
// const upload = multer({ dest: `/tmp/dtp-sites/${this.dtp.config.site.domainKey}`});
const router = express.Router();
dtp.app.use('/author', router);
router.use(checkAuthorPublisherPermissions);
router.use(
async (req, res, next) => {
res.locals.currentView = 'author';
if (!req.user || !req.user.permissions.canAuthorPages) {
return next(new SiteError(403, 'Author privileges are required'));
}
return next();
},
);
router.get('/post',
limiterService.createMiddleware(authorLimiter.getPostIndex),
@ -66,12 +78,30 @@ class AuthorController extends SiteController {
async getAuthorHome (req, res, next) {
const { /*comment: commentService,*/ post: postService } = this.dtp.services;
try {
res.locals.drafts = await postService.getForAuthor(req.user, ['draft'], { skip: 0, cpp: 5 });
res.locals.published = await postService.getForAuthor(req.user, ['published'], { skip: 0, cpp: 5 });
res.locals.pagination = this.getPaginationParameters(req, 20);
res.locals.authorComments = await postService.getCommentsForAuthor(req.user, res.locals.pagination);
const canAuthor = req.user.permissions.canAuthorPosts;
const canPublish = req.user.permissions.canPublishPosts;
if(canAuthor){
if(canPublish){
res.locals.published = await postService.getPosts({ skip: 0, cpp: 5 });
res.locals.drafts = await postService.getPosts({ skip: 0, cpp: 5 }, ['draft']);
res.locals.authorComments = await postService.getCommentsForAuthor(req.user, res.locals.pagination);
res.locals.pagination = this.getPaginationParameters(req, 20);
} else {
res.locals.drafts = await postService.getForAuthor(req.user, ['draft'], { skip: 0, cpp: 5 });
res.locals.published = await postService.getForAuthor(req.user, ['published'], { skip: 0, cpp: 5 });
res.locals.pagination = this.getPaginationParameters(req, 20);
res.locals.authorComments = await postService.getCommentsForAuthor(req.user, res.locals.pagination);
}
// return res.render('author/index');
}
else if (canPublish){
res.locals.posts = await postService.getAllPosts({ skip: 0, cpp: 5 });
}
res.render('author/index');
} catch (error) {
this.log.error('failed to render Author dashboard', { error });

@ -190,7 +190,8 @@ class PostController extends SiteController {
async postUpdatePost (req, res, next) {
const { post: postService } = this.dtp.services;
try {
if (!req.user._id.equals(res.locals.post.author._id)) {
if (!req.user._id.equals(res.locals.post.author._id) &&
!req.user.permissions.canPublishPosts) {
throw new SiteError(403, 'This is not your post');
}
await postService.update(req.user, res.locals.post, req.body);
@ -317,7 +318,8 @@ class PostController extends SiteController {
async deletePost (req, res) {
const { post: postService } = this.dtp.services;
try {
if (!req.user._id.equals(res.locals.post.author._id)) {
if (!req.user._id.equals(res.locals.post.author._id) ||
!req.user.permissions.canPublishPosts) {
throw new SiteError(403, 'This is not your post');
}

@ -9,38 +9,95 @@ block content
include ../comment/components/comment
section.uk-section.uk-section-default.uk-section-xsmall
.uk-container.uk-container-expand
div(uk-grid).uk-flex-middle
.uk-width-expand
h1.uk-margin-remove Author Dashboard
.uk-width-auto
a(href= "/post/compose").uk-button.uk-button-primary.uk-border-rounded
span
i.fas.fa-plus
span.uk-margin-small-left.uk-text-bold Create Post
div(uk-grid)
div(class="uk-width-1-1 uk-width-2-3@m")
+renderSectionTitle('Recent Comments', { url: '/author/comments', title: 'See All', label: 'SEE ALL' })
.content-block
if (user.permissions.canAuthorPosts && user.permissions.canPublishPosts)
section.uk-section.uk-section-default.uk-section-xsmall
.uk-container.uk-container-expand
div(uk-grid).uk-flex-middle
.uk-width-expand
h1.uk-margin-remove Author Dashboard
.uk-width-auto
a(href= "/post/compose").uk-button.uk-button-primary.uk-border-rounded
span
i.fas.fa-plus
span.uk-margin-small-left.uk-text-bold Create Post
div(uk-grid)
if authorComments.length > 0
div(class="uk-width-1-1 uk-width-2-3@m")
+renderSectionTitle('Recent Comments', { url: '/author/comments', title: 'See All', label: 'SEE ALL' })
.content-block
.uk-margin
ul#post-comment-list.uk-list.uk-list-divider.uk-list-large.uk-margin
each comment in authorComments
li
.uk-margin
a(href=`/post/${comment.resource.slug}`).uk-display-block.uk-link-reset
+renderPostSummary(comment.resource)
+renderComment(comment, { })
+renderPaginationBar('/author', published.totalPostCount)
else
div(class="uk-width-1-1 uk-width-2-3@m")
+renderSectionTitle('Comments')
div There are no comments.
div(class="uk-width-1-1 uk-width-1-3@m")
.uk-margin
+renderSectionTitle('Drafts')
+renderPostDraftList(drafts)
.uk-margin
+renderSectionTitle('Recent Posts', { title: 'View All', label: 'View All', url: '/author/post' })
+renderPostList(published)
else if user.permissions.canAuthorPosts
section.uk-section.uk-section-default.uk-section-xsmall
.uk-container.uk-container-expand
div(uk-grid).uk-flex-middle
.uk-width-expand
h1.uk-margin-remove Author Dashboard
.uk-width-auto
a(href= "/post/compose").uk-button.uk-button-primary.uk-border-rounded
span
i.fas.fa-plus
span.uk-margin-small-left.uk-text-bold Create Post
div(uk-grid)
if authorComments.comments.length > 0
div(class="uk-width-1-1 uk-width-2-3@m")
+renderSectionTitle('Recent Comments', { url: '/author/comments', title: 'See All', label: 'SEE ALL' })
.content-block
.uk-margin
ul#post-comment-list.uk-list.uk-list-divider.uk-list-large.uk-margin
each comment in authorComments.comments
li
.uk-margin
a(href=`/post/${comment.resource.slug}`).uk-display-block.uk-link-reset
+renderPostSummary(comment.resource)
+renderComment(comment, { })
+renderPaginationBar('/author', published.totalPostCount)
else
div(class="uk-width-1-1 uk-width-2-3@m")
+renderSectionTitle('Comments')
div There are no comments.
div(class="uk-width-1-1 uk-width-1-3@m")
.uk-margin
+renderSectionTitle('Drafts')
+renderPostDraftList(drafts.posts)
.uk-margin
+renderSectionTitle('Recent Posts', { title: 'View All', label: 'View All', url: '/author/post' })
+renderPostList(published.posts)
else if user.permissions.canPublishPosts
section.uk-section.uk-section-default.uk-section-xsmall
.uk-container.uk-container-expand
div(uk-grid).uk-flex-middle
.uk-width-expand
h1.uk-margin-remove Author Dashboard
.uk-width-auto
.uk-margin
div(class="uk-width-1-1 uk-width-3-3@m")
.uk-margin
ul#post-comment-list.uk-list.uk-list-divider.uk-list-large.uk-margin
each comment in authorComments.comments
li
.uk-margin
a(href=`/post/${comment.resource.slug}`).uk-display-block.uk-link-reset
+renderPostSummary(comment.resource)
+renderComment(comment, { })
+renderPaginationBar('/author', published.totalPostCount)
div(class="uk-width-1-1 uk-width-1-3@m")
.uk-margin
+renderSectionTitle('Drafts')
+renderPostDraftList(drafts.posts)
.uk-margin
+renderSectionTitle('Recent Posts', { title: 'View All', label: 'View All', url: '/author/post' })
+renderPostList(published.posts)
+renderSectionTitle('All Posts')
+renderPostList(posts)

@ -41,7 +41,7 @@ block content
.uk-margin
button(type="submit").uk-button.dtp-button-primary.uk-border-pill Enable 2FA
div(class="uk-width-1-1 uk-text-center uk-text-left@m", hidden)
div(class="uk-width-1-1 uk-text-center uk-text-left@m")
.uk-margin
p Or, if your authenticator doesn't support scanning QR codes, you can enter the OTP configuration information shown here to begin displaying codes:
pre(

@ -33,7 +33,7 @@ block content
if user && user.hasAuthorDashboard
.uk-width-auto= post.status
if post.author._id.equals(user._id)
if post.author._id.equals(user._id) || user.permissions.canPublishPosts
.uk-width-auto
a(href=`/post/${post._id}/edit`).uk-display-block
+renderButtonIcon('fa-pen', 'edit')

@ -14,7 +14,7 @@ block content
.uk-margin
label(for="email").uk-form-label Email
input(id="email", name="email", type="email", autocomplete="off", placeholder="Enter your email address").uk-input
.uk-text-small.uk-text-muted.uk-margin-small-top(class="uk-visible@m") I'm throwing your email address away after the demo, and I'm not verifying it. You won't receive email.
.uk-text-small.uk-text-muted.uk-margin-small-top(class="uk-visible@m") Enter a valid email, and not one from a temporary service
.uk-margin
label(for="username").uk-form-label Username

Loading…
Cancel
Save