From e54e30c586ad5b6cbe26a78de1e5f9c927e948ef Mon Sep 17 00:00:00 2001 From: fatchan Date: Thu, 27 Jun 2019 17:54:17 +0000 Subject: [PATCH] board name and description can be changed in manage page --- controllers/forms.js | 6 ++++++ models/forms/changeboardsettings.js | 10 ++++++++-- models/forms/makepost.js | 1 + views/includes/boardheader.pug | 4 ++-- views/pages/manage.pug | 6 ++++++ wipe.js | 14 +++++++------- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/controllers/forms.js b/controllers/forms.js index 9ce6cd2f..203c58ff 100644 --- a/controllers/forms.js +++ b/controllers/forms.js @@ -259,6 +259,12 @@ router.post('/board/:board/settings', csrf, Boards.exists, checkPermsMiddleware, const errors = []; + if (req.body.description && (req.body.description.length < 1 || req.body.description.length > 50)) { + errors.push('Board description must be 1-50 characters'); + } + if (req.body.name && (req.body.name.length < 1 || req.body.name.length > 50)) { + errors.push('Board name must be 1-50 characters'); + } if (req.body.default_name && (req.body.default_name.length < 1 || req.body.default_name.length > 50)) { errors.push('Anon name must be 1-50 characters'); } diff --git a/models/forms/changeboardsettings.js b/models/forms/changeboardsettings.js index 981cdacc..9482700c 100644 --- a/models/forms/changeboardsettings.js +++ b/models/forms/changeboardsettings.js @@ -3,7 +3,7 @@ const Boards = require(__dirname+'/../../db/boards.js') , Posts = require(__dirname+'/../../db/posts.js') , uploadDirectory = require(__dirname+'/../../helpers/uploadDirectory.js') - , { buildCatalog, buildBoardMultiple } = require(__dirname+'/../../build.js') + , { buildHomepage, buildCatalog, buildBoardMultiple } = require(__dirname+'/../../build.js') , remove = require('fs-extra').remove module.exports = async (req, res, next) => { @@ -11,9 +11,11 @@ module.exports = async (req, res, next) => { const oldSettings = res.locals.board.settings; const newSettings = { + name: req.body.name && req.body.name.trim().length > 0 ? req.body.name : oldSettings.name, + description: req.body.description && req.body.description.trim().length > 0 ? req.body.description : oldSettings.description, + ids: req.body.ids ? true : false, captcha: req.body.captcha ? true : false, forceAnon: req.body.force_anon ? true : false, - ids: req.body.ids ? true : false, userPostDelete: req.body.user_post_delete ? true : false, userPostSpoiler: req.body.user_post_spoiler ? true : false, userPostUnlink: req.body.user_post_unlink ? true : false, @@ -73,6 +75,10 @@ module.exports = async (req, res, next) => { promises.push(remove(`${uploadDirectory}html/${req.params.board}/`)); } + if (oldSettings.name !== newSettings.name || oldSettings.description !== newSettings.description) { + promises.push(buildHomepage()) + } + if (promises.length > 0) { await Promise.all(promises); } diff --git a/models/forms/makepost.js b/models/forms/makepost.js index b46c9db0..f46aafe0 100644 --- a/models/forms/makepost.js +++ b/models/forms/makepost.js @@ -241,6 +241,7 @@ module.exports = async (req, res, next) => { capcode, subject, 'message': message || null, + 'nomarkup': req.body.message || null, 'thread': req.body.thread || null, 'password': req.body.password || null, email, diff --git a/views/includes/boardheader.pug b/views/includes/boardheader.pug index 4bdaa9b1..b36203da 100644 --- a/views/includes/boardheader.pug +++ b/views/includes/boardheader.pug @@ -2,5 +2,5 @@ section.board-header img.board-banner(src=`/randombanner?board=${board._id}` width='300' height='100') br a.no-decoration(href=`/${board._id}/index.html`) - h1.board-title /#{board._id}/ - #{board.name} - h4.board-description #{board.description} + h1.board-title /#{board._id}/ - #{board.settings.name} + h4.board-description #{board.settings.description} diff --git a/views/pages/manage.pug b/views/pages/manage.pug index 3cb488dd..7619af16 100644 --- a/views/pages/manage.pug +++ b/views/pages/manage.pug @@ -12,6 +12,12 @@ block content section.form-wrapper.flexleft.mv-10 form.form-post(action=`/forms/board/${board._id}/settings` method='POST' enctype='application/x-www-form-urlencoded') input(type='hidden' name='_csrf' value=csrf) + section.postform-row + .postform-label Board name + input(type='text' name='name' placeholder=board.settings.name) + section.postform-row + .postform-label Board Description + input(type='text' name='description' placeholder=board.settings.description) section.postform-row .postform-label IDs label.postform-style.ph-5 diff --git a/wipe.js b/wipe.js index fbc12a1f..929ee409 100644 --- a/wipe.js +++ b/wipe.js @@ -33,13 +33,13 @@ const Mongo = require(__dirname+'/db/db.js') await Bans.deleteAll(); console.log('adding boards') await Boards.insertOne({ - _id: 'pol', - name: 'Politically Incorrect', - description: 'Political posts go here.', + _id: 'pol', owner: '', moderators: [], banners: [], settings: { + name: 'politically incorrect', + description: 'posts about politics', captcha: true, forceAnon: true, ids: true, @@ -57,13 +57,13 @@ const Mongo = require(__dirname+'/db/db.js') } }) await Boards.insertOne({ - _id: 'b', - name: 'Random', - description: 'post anything here', + _id: 'b', owner: '', moderators: [], banners: [], settings: { + name: 'random', + description: 'anything and everything', captcha: false, forceAnon: false, ids: false, @@ -83,7 +83,7 @@ const Mongo = require(__dirname+'/db/db.js') await Boards.insertOne({ _id: 't', name: 'text', - description: 'text only board', + description: 'no images allowed', owner: '', moderators: [], banners: [],