From 208c7a849c2019d9baca63c35763f219e2526f63 Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 14 Apr 2020 11:00:47 +0000 Subject: [PATCH] pad.html: UI telling the user that a contribution is required before importing This commit is an integration to 24ee37a38ff8. --- src/locales/en.json | 3 ++- src/node/handler/PadMessageHandler.js | 13 ++++++++++++- src/static/css/pad.css | 6 +++++- src/static/js/collab_client.js | 10 ++++++++++ src/static/js/pad_editbar.js | 11 +++++++++++ src/static/js/pad_impexp.js | 2 ++ src/templates/pad.html | 1 + 7 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index 46563d226..fab3c6d2b 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -144,5 +144,6 @@ "pad.impexp.importfailed": "Import failed", "pad.impexp.copypaste": "Please copy paste", "pad.impexp.exportdisabled": "Exporting as {{type}} format is disabled. Please contact your system administrator for details.", - "pad.impexp.maxFileSize": "File too big. Contact your site administrator to increase the allowed file size for import" + "pad.impexp.maxFileSize": "File too big. Contact your site administrator to increase the allowed file size for import", + "pad.impexp.permission": "Import is disabled because you never contributed to this pad. Please contribute at least once before importing" } diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index fb04a4e30..9e23fea21 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -939,6 +939,16 @@ async function handleClientReady(client, message) }); })); + let thisUserHasEditedThisPad = false; + if (historicalAuthorData[statusObject.authorID]) { + /* + * This flag is set to true when a user contributes to a specific pad for + * the first time. It is used for deciding if importing to that pad is + * allowed or not. + */ + thisUserHasEditedThisPad = true; + } + // glue the clientVars together, send them and tell the other clients that a new one is there // Check that the client is still here. It might have disconnected between callbacks. @@ -1118,7 +1128,8 @@ async function handleClientReady(client, message) "scrollWhenCaretIsInTheLastLineOfViewport": settings.scrollWhenFocusLineIsOutOfViewport.scrollWhenCaretIsInTheLastLineOfViewport, "percentageToScrollWhenUserPressesArrowUp": settings.scrollWhenFocusLineIsOutOfViewport.percentageToScrollWhenUserPressesArrowUp, }, - "initialChangesets": [] // FIXME: REMOVE THIS SHIT + "initialChangesets": [], // FIXME: REMOVE THIS SHIT + "thisUserHasEditedThisPad": thisUserHasEditedThisPad, } // Add a username to the clientVars if one avaiable diff --git a/src/static/css/pad.css b/src/static/css/pad.css index 2e073dfdb..cf89ed35d 100644 --- a/src/static/css/pad.css +++ b/src/static/css/pad.css @@ -70,4 +70,8 @@ input { @media (max-width: 800px) { .hide-for-mobile { display: none; } -} \ No newline at end of file +} + +#importmessagepermission { + display: none; +} diff --git a/src/static/js/collab_client.js b/src/static/js/collab_client.js index 4bcc6ad2b..ca83af9dd 100644 --- a/src/static/js/collab_client.js +++ b/src/static/js/collab_client.js @@ -313,6 +313,16 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) } else if (msg.type == "ACCEPT_COMMIT") { + /* + * this is the first time this user contributed to this pad. Let's record + * it, because it will be used for allowing import. + * + * TODO: here, we are changing this variable on the client side only. The + * server has all the informations to make the same deduction, and + * broadcast to the client. + */ + clientVars.thisUserHasEditedThisPad = true; + var newRev = msg.newRev; if (msgQueue.length > 0) { diff --git a/src/static/js/pad_editbar.js b/src/static/js/pad_editbar.js index f1e0fb17e..ba2171b0d 100644 --- a/src/static/js/pad_editbar.js +++ b/src/static/js/pad_editbar.js @@ -394,6 +394,17 @@ var padeditbar = (function() toolbar.registerCommand("import_export", function () { toolbar.toggleDropDown("import_export", function(){ + + if (clientVars.thisUserHasEditedThisPad) { + // the user has edited this pad historically or in this session + $('#importform').show(); + $('#importmessagepermission').hide(); + } else { + // this is the first time this user visits this pad + $('#importform').hide(); + $('#importmessagepermission').show(); + } + // If Import file input exists then focus on it.. if($('#importfileinput').length !== 0){ setTimeout(function(){ diff --git a/src/static/js/pad_impexp.js b/src/static/js/pad_impexp.js index 001c4f83d..ceb363b31 100644 --- a/src/static/js/pad_impexp.js +++ b/src/static/js/pad_impexp.js @@ -113,6 +113,8 @@ var padimpexp = (function() msg = html10n.get("pad.impexp.padHasData"); } else if(status === "maxFileSize"){ msg = html10n.get("pad.impexp.maxFileSize"); + } else if(status === "permission"){ + msg = html10n.get("pad.impexp.permission"); } function showError(fade) diff --git a/src/templates/pad.html b/src/templates/pad.html index 10d27cecc..45f9a7d3d 100644 --- a/src/templates/pad.html +++ b/src/templates/pad.html @@ -201,6 +201,7 @@ +
<% e.end_block(); %>