Add clear button for moderators

This commit is contained in:
jamesdeacon 2022-07-21 16:29:21 +01:00
parent 5675d708e9
commit a8bb9fb3b5
7 changed files with 102 additions and 9 deletions

View file

@ -83,7 +83,7 @@ If you feel like contributing to this collaborative project, you can [translate
WBO supports authentication with a JWT. This should be passed in as a query with the key `token`, eg, `http://myboard.com/boards/test?token={token}`
Within the payload, you can provide a `moderator` key to declare the user as a moderator.
Within the payload, you can provide a `moderator` key to declare the user as a moderator. Moderators have access to the Clear tool, which will wipe all content from the board.
The `AUTH_SECRET_KEY` variable in [`configuration.js`](./server/configuration.js) should be filled with the secret key for the JWT.

View file

@ -102,6 +102,7 @@
<script src="../tools/grid/grid.js"></script>
<script src="../tools/download/download.js"></script>
<script src="../tools/zoom/zoom.js"></script>
{{#moderator}}<script src="../tools/clear/clear.js"></script>{{/moderator}}
<script src="../js/canvascolor.js"></script>
</body>

View file

@ -0,0 +1,52 @@
/**
* WHITEBOPHIR
*********************************************************
* @licstart The following is the entire license notice for the
* JavaScript code in this page.
*
* Copyright (C) 2020 Ophir LOJKINE
*
*
* The JavaScript code in this page is free software: you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License (GNU GPL) as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. The code is distributed WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*
* As additional permission under GNU GPL version 3 section 7, you
* may distribute non-source (e.g., minimized or compacted) forms of
* that code without the copy of the GNU GPL normally required by
* section 4, provided you include this license notice and a URL
* through which recipients can access the Corresponding Source.
*
* @licend
*/
(function clear() { //Code isolation
function clearBoard() {
var msg = {
"type": "clear",
"id": ""
};
Tools.drawAndSend(msg, Tools.list["Clear"]);
}
function draw(data) {
Tools.drawingArea.innerHTML = "";
}
Tools.add({ //The new tool
"name": "Clear",
"shortcut": "c",
"listeners": {},
"icon": "tools/clear/clear.svg",
"oneTouch": true,
"onstart": clearBoard,
"draw": draw,
"mouseCursor": "crosshair",
});
})(); //End of code isolation

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 498.911 498.911" style="enable-background:new 0 0 498.911 498.911;" xml:space="preserve" width="512" height="512">
<g>
<path d="M357.914,399.307c2.587-1.198,4.271-3.759,4.346-6.609c0.075-2.85-1.473-5.496-3.994-6.828 c-31.661-16.731-43.886-39.109-37.301-68.313c9.01-3.785,13.721-13.964,10.544-23.365l-9.438-27.92 c-1.61-4.764-4.98-8.616-9.487-10.846c-4.507-2.229-9.614-2.571-14.377-0.96l-45.389,15.343c-3.924,1.326-6.03,5.583-4.703,9.507 c1.326,3.924,5.583,6.029,9.507,4.703l45.389-15.343c1.999-0.674,4.175,0.4,4.851,2.4l9.438,27.92c0.676,2-0.401,4.176-2.4,4.852 L40.072,396.751c-0.968,0.327-2.007,0.258-2.923-0.195c-0.917-0.453-1.602-1.236-1.929-2.205l-9.438-27.92 c-0.676-1.999,0.401-4.175,2.4-4.851l199.059-67.292c3.924-1.327,6.03-5.583,4.703-9.507c-1.326-3.924-5.584-6.028-9.507-4.703 l-29.85,10.091L102.215,22.831c-2.871-8.493-8.877-15.359-16.913-19.334S68.165-1.086,59.671,1.784 C42.139,7.711,32.697,26.796,38.624,44.328l13.481,39.88c1.326,3.924,5.582,6.029,9.507,4.703c3.924-1.327,6.03-5.583,4.703-9.507 l-13.481-39.88c-3.278-9.697,1.944-20.252,11.641-23.53c4.696-1.588,9.731-1.252,14.176,0.947 c4.444,2.199,7.766,5.997,9.354,10.694l90.372,267.337l-35.171,11.89l-67.74-200.388c-1.326-3.923-5.583-6.027-9.507-4.703 c-3.924,1.327-6.03,5.583-4.703,9.507l67.74,200.388L23.378,347.369c-9.834,3.325-15.131,14.03-11.806,23.865l9.438,27.92 c2.651,7.843,9.996,12.8,17.851,12.799c1.564,0,3.149-0.205,4.72-0.614c22.945,19.212,26.802,44.416,11.791,76.927 c-1.195,2.588-0.819,5.63,0.969,7.85c1.442,1.789,3.6,2.794,5.839,2.794c0.54,0,1.085-0.059,1.625-0.179 c58.844-13.061,117.245-29.917,173.638-50.097c1.075,0.323,2.164,0.609,3.277,0.82c4.434,11.501,12.866,20.814,23.956,26.387 c7.004,3.52,14.572,5.298,22.188,5.298c5.238,0,10.5-0.841,15.617-2.536c19.348-6.406,32.603-23.931,33.867-43.853 c7.917-3.423,13.452-11.35,13.452-20.354c0-3.687-0.91-7.164-2.51-10.225C350.795,402.586,354.342,400.961,357.914,399.307z M338.69,391.602c-1.35,0.609-2.67,1.195-4.001,1.791c-2.215-0.745-4.583-1.155-7.046-1.155c-2.952,0-5.851,0.592-8.535,1.717 c-3.382-2.891-7.107-5.27-11.052-7.131c-15.928-16.41-22.707-35.386-20.629-57.857l17.364-5.87 c-1.688,13.899,0.325,26.714,6.049,38.224C316.5,372.701,325.84,382.848,338.69,391.602z M189.857,448.97 c-4.452-27.357-12.373-53.906-23.562-79.055l31.981-10.811c4.17,17.556,9.845,34.757,16.884,51.291 c-1.283,5.583-1.104,11.573,0.824,17.397c1.291,3.9,3.293,7.42,5.815,10.463C211.216,441.947,200.565,445.519,189.857,448.97z M115.511,387.083c14.818,22.59,21.149,48.397,18.821,76.797c-0.047,0.568-0.139,1.188-0.251,1.831 c-8.46,2.353-16.945,4.624-25.447,6.822c6.815-29.835,1.389-55.879-16.168-77.66L115.511,387.083z M130.138,382.138l21.883-7.397 c11.039,24.574,19.428,52.189,23.773,78.692c-8.717,2.711-17.471,5.333-26.251,7.88 C151.223,432.316,144.705,405.744,130.138,382.138z M224.665,393.889c-4.918-12.888-8.972-26.145-12.106-39.614l21.892-7.4 c1.333,13.417,4.599,26.265,9.767,38.408c-2.573,0.203-5.14,0.707-7.646,1.538C231.991,388.338,227.979,390.791,224.665,393.889z M262.4,388.568c-7.672-14.367-12.135-30.02-13.318-46.639l23.029-7.785c-0.454,17.575,3.93,33.623,13.103,47.974 c-4.648,0.157-9.315,0.946-13.867,2.454C268.228,385.605,265.24,386.949,262.4,388.568z M78.172,439.973 c-2.433-12.624-8.608-24.031-18.383-34.054l17.351-5.865c19.176,20.835,24.053,45.962,14.896,76.665 c-5.869,1.443-11.744,2.855-17.626,4.223C79.312,466.186,80.578,452.454,78.172,439.973z M328.248,421.523 c-4.068,0.337-7.12,3.867-6.865,7.941c0.975,15.623-8.735,29.975-23.614,34.901c-8.757,2.899-18.115,2.215-26.356-1.926 c-8.24-4.141-14.375-11.243-17.274-19.999c-0.207-0.624-0.39-1.25-0.559-1.876c-0.871-3.226-3.771-5.487-7.113-5.544 c-7.391-0.126-13.918-4.926-16.243-11.944c-3.02-9.12,1.943-18.997,11.063-22.017c1.79-0.592,3.636-0.883,5.472-0.883 c3.778,0,7.51,1.23,10.6,3.591c2.655,2.028,6.33,2.055,9.014,0.069c2.949-2.183,6.209-3.874,9.689-5.026 c12.943-4.285,27.241-0.528,36.422,9.575c2.743,3.019,7.395,3.292,10.473,0.615c0.925-0.805,2.489-1.764,4.686-1.764 c3.948,0,7.161,3.212,7.161,7.161C334.803,418.088,331.924,421.217,328.248,421.523z"/>
<path d="M455.115,374.349c-10.934,0-20.877,5.924-26.179,15.182c-23.986,1.368-43.083,21.314-43.083,45.637 c0,25.206,20.506,45.713,45.712,45.713c25.206,0,45.712-20.507,45.712-45.713c0-3.11-0.315-6.198-0.94-9.229 c5.67-5.616,8.938-13.304,8.938-21.429C485.276,387.879,471.746,374.349,455.115,374.349z M463.642,417.046 c-2.759,1.882-3.94,5.362-2.898,8.535c1.018,3.101,1.534,6.326,1.534,9.587c0,16.935-13.777,30.713-30.712,30.713 c-16.935,0-30.712-13.778-30.712-30.713c0-16.935,13.777-30.712,30.712-30.712c0.585,0,1.165,0.021,1.742,0.053 c3.348,0.181,6.393-1.856,7.498-5.01c2.126-6.071,7.876-10.15,14.31-10.15c8.359,0,15.161,6.801,15.161,15.161 C470.276,409.525,467.796,414.211,463.642,417.046z"/>
<path d="M434.085,322.865c0-17.07-13.887-30.957-30.957-30.957s-30.957,13.887-30.957,30.957s13.887,30.957,30.957,30.957 S434.085,339.935,434.085,322.865z M387.171,322.865c0-8.799,7.158-15.957,15.957-15.957s15.957,7.158,15.957,15.957 s-7.158,15.957-15.957,15.957S387.171,331.664,387.171,322.865z"/>
<path d="M461.455,302.799c-4.768,4.565-1.406,12.911,5.203,12.911c3.674,0,6.886-2.796,7.418-6.419 c0.436-2.964-0.998-5.975-3.565-7.516C467.643,300.051,463.868,300.487,461.455,302.799z"/>
<path d="M354.39,451.865c-4.907,4.518-1.592,13.014,5.078,13.014c3.943,0,7.305-3.19,7.491-7.133 C367.268,451.196,359.224,447.415,354.39,451.865z"/>
<path d="M376.285,257.791c1.26-6.667-6.64-11.433-11.977-7.296c-5.51,4.271-2.37,13.405,4.61,13.405 C372.491,263.899,375.623,261.294,376.285,257.791z"/>
<path d="M412.296,233.206c-0.036,0.671-0.054,1.343-0.054,2.014c0,20.978,17.067,38.044,38.045,38.044 c20.978,0,38.044-17.067,38.044-38.044c0-9.907-3.933-19.436-10.74-26.481c0.957-2.905,1.452-5.951,1.452-9.022 c0-15.992-13.01-29.002-29.002-29.002c-10.88,0-20.691,6.125-25.63,15.469c-13.469,0.615-24.237,11.765-24.237,25.383 C400.174,220.469,404.936,228.651,412.296,233.206z M425.584,201.156c0.693,0,1.424,0.081,2.171,0.24 c3.892,0.826,7.751-1.526,8.797-5.365c1.655-6.075,7.202-10.317,13.489-10.317c7.721,0,14.002,6.281,14.002,14.002 c0,2.497-0.686,4.966-1.983,7.142c-1.97,3.304-1.122,7.562,1.964,9.858c5.915,4.401,9.307,11.145,9.307,18.503 c0,12.707-10.338,23.044-23.044,23.044c-12.707,0-23.045-10.338-23.045-23.044c0-1.639,0.178-3.291,0.53-4.912 c0.831-3.829-1.426-7.651-5.179-8.775c-4.369-1.308-7.42-5.406-7.42-9.967C415.174,205.826,419.844,201.156,425.584,201.156z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.6 KiB

View file

@ -122,6 +122,13 @@ class BoardData {
this.delaySave();
}
/** Clear the board of all data
*/
clear() {
this.board = {};
this.delaySave();
}
/** Removes data from the board
* @param {string} id - Identifier of the data to delete.
*/
@ -165,6 +172,9 @@ class BoardData {
case "child":
this.addChild(message.parent, message);
break;
case "clear":
this.clear();
break;
default:
//Add data
if (!id) throw new Error("Invalid message: ", message);

View file

@ -126,8 +126,9 @@ function handleRequest(request, response) {
var fileExt = path.extname(parsedUrl.pathname);
var staticResources = ['.js','.css', '.svg', '.ico', '.png', '.jpg', 'gif'];
// If we're not being asked for a file, then we should check permissions.
var isModerator = false;
if(!staticResources.includes(fileExt)) {
var isModerator = checkUserPermission(parsedUrl);
isModerator = checkUserPermission(parsedUrl);
}
switch (parts[0]) {
@ -141,7 +142,7 @@ function handleRequest(request, response) {
response.end();
} else if (parts.length === 2 && parsedUrl.pathname.indexOf(".") === -1) {
validateBoardName(parts[1]);
boardTemplate.serve(request, response);
boardTemplate.serve(request, response, isModerator);
// If there is no dot and no directory, parts[1] is the board name
} else {
request.url = "/" + parts.slice(1).join("/");

View file

@ -32,7 +32,7 @@ class Template {
const contents = fs.readFileSync(path, { encoding: "utf8" });
this.template = handlebars.compile(contents);
}
parameters(parsedUrl, request) {
parameters(parsedUrl, request, isModerator) {
const accept_language_str = parsedUrl.query.lang || request.headers["accept-language"];
const accept_languages = accept_language_parser.parse(accept_language_str);
const opts = { loose: true };
@ -50,11 +50,12 @@ class Template {
const configuration = client_config || {};
const prefix = request.url.split("/boards/")[0].substr(1);
const baseUrl = findBaseUrl(request) + (prefix ? prefix + "/" : "");
return { baseUrl, languages, language, translations, configuration };
const moderator = isModerator;
return { baseUrl, languages, language, translations, configuration, moderator };
}
serve(request, response) {
serve(request, response, isModerator) {
const parsedUrl = url.parse(request.url, true);
const parameters = this.parameters(parsedUrl, request);
const parameters = this.parameters(parsedUrl, request, isModerator);
var body = this.template(parameters);
var headers = {
"Content-Length": Buffer.byteLength(body),
@ -70,8 +71,8 @@ class Template {
}
class BoardTemplate extends Template {
parameters(parsedUrl, request) {
const params = super.parameters(parsedUrl, request);
parameters(parsedUrl, request, isModerator) {
const params = super.parameters(parsedUrl, request, isModerator);
const parts = parsedUrl.pathname.split("boards/", 2);
const boardUriComponent = parts[1];
params["boardUriComponent"] = boardUriComponent;