parent
95792f274c
commit
7c92310483
@ -0,0 +1,96 @@
|
||||
// admin/core-user.js
|
||||
// Copyright (C) 2022 DTP Technologies, LLC
|
||||
// License: Apache-2.0
|
||||
|
||||
'use strict';
|
||||
|
||||
const express = require('express');
|
||||
// const multer = require('multer');
|
||||
|
||||
const { SiteController, SiteError } = require('../../../lib/site-lib');
|
||||
|
||||
class CoreUserController extends SiteController {
|
||||
|
||||
constructor (dtp) {
|
||||
super(dtp, module.exports);
|
||||
}
|
||||
|
||||
async start ( ) {
|
||||
// const upload = multer({ dest: `/tmp/${this.dtp.config.site.domainKey}/upload` });
|
||||
|
||||
const router = express.Router();
|
||||
router.use(async (req, res, next) => {
|
||||
res.locals.currentView = 'admin';
|
||||
res.locals.adminView = 'core-user';
|
||||
return next();
|
||||
});
|
||||
|
||||
router.param('coreUserId', this.populateCoreUserId.bind(this));
|
||||
|
||||
router.post('/:coreUserId', this.postUpdateCoreUser.bind(this));
|
||||
|
||||
router.get('/:coreUserId', this.getCoreUserView.bind(this));
|
||||
router.get('/', this.getIndex.bind(this));
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
async populateCoreUserId (req, res, next, coreUserId) {
|
||||
const { coreNode: coreNodeService } = this.dtp.services;
|
||||
try {
|
||||
res.locals.userAccount = await coreNodeService.getUserByLocalId(coreUserId);
|
||||
if (!res.locals.userAccount) {
|
||||
throw new SiteError(404, 'Core Member not found');
|
||||
}
|
||||
return next();
|
||||
} catch (error) {
|
||||
this.log.error('failed to populate coreUserId', { coreUserId, error });
|
||||
return next(error);
|
||||
}
|
||||
}
|
||||
|
||||
async postUpdateCoreUser (req, res, next) {
|
||||
const { coreNode: coreNodeService } = this.dtp.services;
|
||||
try {
|
||||
await coreNodeService.updateUserForAdmin(res.locals.userAccount, req.body);
|
||||
res.redirect('/admin/core-user');
|
||||
} catch (error) {
|
||||
return next(error);
|
||||
}
|
||||
}
|
||||
|
||||
async getCoreUserView (req, res, next) {
|
||||
const { comment: commentService } = this.dtp.services;
|
||||
try {
|
||||
res.locals.pagination = this.getPaginationParameters(req, 20);
|
||||
res.locals.recentComments = await commentService.getForAuthor(res.locals.userAccount, res.locals.pagination);
|
||||
res.render('admin/core-user/form');
|
||||
} catch (error) {
|
||||
this.log.error('failed to produce user view', { error });
|
||||
return next(error);
|
||||
}
|
||||
}
|
||||
|
||||
async getIndex (req, res, next) {
|
||||
const { coreNode: coreNodeService } = this.dtp.services;
|
||||
const search = { };
|
||||
try {
|
||||
res.locals.pagination = this.getPaginationParameters(req, 20);
|
||||
res.locals.users = await coreNodeService.searchUsers(search, res.locals.pagination);
|
||||
res.render('admin/core-user/index');
|
||||
} catch (error) {
|
||||
this.log.error('failed to render Core User home', {
|
||||
search,
|
||||
pagination: res.locals.pagination,
|
||||
error,
|
||||
});
|
||||
return next(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'adminCoreUser',
|
||||
slug: 'admin-core-user',
|
||||
create: async (dtp) => { return new CoreUserController(dtp); },
|
||||
};
|
@ -0,0 +1,120 @@
|
||||
extends ../layouts/main
|
||||
block content
|
||||
|
||||
include ../../comment/components/comment-review
|
||||
|
||||
div(uk-grid).uk-grid-small
|
||||
div(class="uk-width-1-1 uk-width-2-3@l")
|
||||
form(method="POST", action=`/admin/core-user/${userAccount._id}`).uk-form
|
||||
input(type="hidden", name="username", value= userAccount.username)
|
||||
input(type="hidden", name="displayName", value= userAccount.displayName)
|
||||
.uk-card.uk-card-default.uk-card-small
|
||||
.uk-card-header
|
||||
if userAccount.displayName
|
||||
.uk-text-large= userAccount.displayName
|
||||
div
|
||||
a(href=`/user/${userAccount._id}`) @#{userAccount.username}
|
||||
|
||||
.uk-card-body
|
||||
.uk-margin
|
||||
label(for="bio").uk-form-label Bio
|
||||
textarea(id="bio", name="bio", rows="3", placeholder="Enter profile bio").uk-textarea= userAccount.bio
|
||||
|
||||
.uk-margin
|
||||
label.uk-form-label Flags
|
||||
div(uk-grid).uk-grid-small
|
||||
label
|
||||
input(id="is-admin", name="isAdmin", type="checkbox", checked= userAccount.flags.isAdmin)
|
||||
| Admin
|
||||
label
|
||||
input(id="is-moderator", name="isModerator", type="checkbox", checked= userAccount.flags.isModerator)
|
||||
| Moderator
|
||||
label
|
||||
input(id="is-email-verified", name="isEmailVerified", type="checkbox", checked= userAccount.flags.isEmailVerified)
|
||||
| Email Verified
|
||||
|
||||
.uk-margin
|
||||
label.uk-form-label Permissions
|
||||
.uk-margin
|
||||
div(uk-grid).uk-grid-small
|
||||
label
|
||||
input(id="can-login", name="canLogin", type="checkbox", checked= userAccount.permissions.canLogin)
|
||||
| Can Login
|
||||
label
|
||||
input(id="can-chat", name="canChat", type="checkbox", checked= userAccount.permissions.canChat)
|
||||
| Can Chat
|
||||
label
|
||||
input(id="can-comment", name="canComment", type="checkbox", checked= userAccount.permissions.canComment)
|
||||
| Can Comment
|
||||
label
|
||||
input(id="can-report", name="canReport", type="checkbox", checked= userAccount.permissions.canReport)
|
||||
| Can Report
|
||||
|
||||
.uk-margin
|
||||
label.uk-form-label Opt-Ins
|
||||
div(uk-grid).uk-grid-small
|
||||
label
|
||||
input(id="optin-system", name="optInSystem", type="checkbox", checked= userAccount.optIn.system)
|
||||
| System
|
||||
label
|
||||
input(id="optin-marketing", name="optInMarketing", type="checkbox", checked= userAccount.optIn.marketing)
|
||||
| Marketing
|
||||
|
||||
.uk-card-footer
|
||||
div(uk-grid).uk-grid-small
|
||||
.uk-width-expand
|
||||
+renderBackButton()
|
||||
.uk-width-auto
|
||||
button(type="submit").uk-button.uk-button-primary Update User
|
||||
|
||||
div(class="uk-width-1-1 uk-width-1-3@l")
|
||||
|
||||
.uk-margin
|
||||
.uk-card.uk-card-default.uk-card-small
|
||||
.uk-card-header
|
||||
h4.uk-card-title
|
||||
div(uk-grid).uk-grid-small
|
||||
.uk-width-expand
|
||||
div= userAccount.core.meta.name
|
||||
.uk-width-auto
|
||||
img(src="/img/icon/dtp-core.svg", alt="DTP Core Icon", style="height: 1em; width: auto;")
|
||||
|
||||
.uk-card-body
|
||||
.uk-margin
|
||||
label.uk-form-label Description
|
||||
div= userAccount.core.meta.description
|
||||
|
||||
.uk-margin
|
||||
div(uk-grid)
|
||||
.uk-width-auto
|
||||
label.uk-form-label Name
|
||||
div= userAccount.core.meta.name
|
||||
.uk-width-auto
|
||||
label.uk-form-label Created
|
||||
div= moment(userAccount.core.created).fromNow()
|
||||
.uk-width-auto
|
||||
label.uk-form-label Updated
|
||||
div= moment(userAccount.core.updated).fromNow()
|
||||
|
||||
.uk-margin
|
||||
div(uk-grid)
|
||||
.uk-width-auto
|
||||
label.uk-form-label Domain
|
||||
div= userAccount.core.meta.domain
|
||||
.uk-width-auto
|
||||
label.uk-form-label Domain Key
|
||||
div= userAccount.core.meta.domainKey
|
||||
|
||||
.uk-margin
|
||||
.uk-card.uk-card-default.uk-card-small
|
||||
.uk-card-header
|
||||
h4.uk-card-title Recent Comments
|
||||
|
||||
.uk-card-body
|
||||
if Array.isArray(recentComments) && (recentComments.length > 0)
|
||||
ul.uk-list.uk-list-divider
|
||||
each comment in recentComments
|
||||
li
|
||||
+renderCommentReview(comment)
|
||||
else
|
||||
div #{userAccount.displayName || userAccount.uslername} has no recent comments.
|
@ -0,0 +1,33 @@
|
||||
extends ../layouts/main
|
||||
block content
|
||||
h1 Core Users
|
||||
|
||||
if Array.isArray(users) && (users.length > 0)
|
||||
.uk-overflow-auto
|
||||
table.uk-table.uk-table-divider.uk-table-small.uk-table-justify
|
||||
thead
|
||||
th Username
|
||||
th Display Name
|
||||
th Created
|
||||
th Core
|
||||
th Core Domain
|
||||
th Core User ID
|
||||
th User ID
|
||||
tbody
|
||||
each userAccount in users
|
||||
tr
|
||||
td
|
||||
a(href=`/admin/core-user/${userAccount._id}`)= userAccount.username
|
||||
td
|
||||
if userAccount.displayName
|
||||
a(href=`/admin/core-user/${userAccount._id}`)= userAccount.displayName
|
||||
else
|
||||
.uk-text-muted N/A
|
||||
td= moment(userAccount.created).format('YYYY-MM-DD hh:mm a')
|
||||
td= userAccount.core.meta.name
|
||||
td= userAccount.core.meta.domainKey
|
||||
td= userAccount.coreUserId
|
||||
td= userAccount._id
|
||||
|
||||
else
|
||||
div There are no Core users.
|
Loading…
Reference in new issue