From 4d643e51a146351d574553687bebb10ccb3ee243 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 13 Sep 2023 15:43:20 +0200 Subject: [PATCH] Add new error message with deleted template --- customize.dist/login.js | 3 --- www/common/common-interface.js | 34 +++++++++++++++++++++++++++---- www/common/cryptpad-common.js | 8 ++++---- www/common/sframe-common-outer.js | 8 ++++---- www/common/sframe-common.js | 9 ++++++-- www/drive/inner.js | 2 +- 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/customize.dist/login.js b/customize.dist/login.js index 82826366d..3517af787 100644 --- a/customize.dist/login.js +++ b/customize.dist/login.js @@ -604,9 +604,6 @@ define([ }); break; case 'DELETED_USER': - if (result.reason === 'PASSWORD_CHANGE') { - // XXX PLACEHOLDER: account password change login page - } UI.errorLoadingScreen(UI.getDestroyedPlaceholder(result.reason, true)); break; case 'INVAL_PASS': diff --git a/www/common/common-interface.js b/www/common/common-interface.js index b9812c2c0..e8698e124 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -1048,9 +1048,11 @@ define([ if (e.which === 27) { e.preventDefault(); e.stopPropagation(); + // Function: call the function (should be a redirect) + if (typeof(exitable) === "function") { return void exitable(); } + // Otherwise remove the loading screen $loading.hide(); $('html').toggleClass('cp-loading-noscroll', false); - if (typeof(exitable) === "function") { exitable(); } } }); } @@ -1549,18 +1551,29 @@ define([ // XXX Messages.dph_reason = "Reason: {0}"; + + Messages.dph_default = "This content is no longer available"; // default key when custom message not found + Messages.dph_account_destroyed = "This account has been deleted by its owner"; Messages.dph_account_inactive = "This account has been deleted for inactivity"; Messages.dph_account_moderated = "This account has been suspended by the moderation team"; Messages.dph_account_pw = "This account's password has been changed"; + Messages.dph_pad_destroyed = "This document has been destroyed by its owner"; Messages.dph_pad_inactive = "This document has been deleted for inactivity"; Messages.dph_pad_moderated = "This document has been deleted by the moderation team"; - Messages.dph_pad_moderated_account = "This document has deleted with its owner's account"; // Keep this key ??? + Messages.dph_pad_moderated_account = "This document has been deleted with its owner's account"; // Keep this key ??? Messages.dph_pad_pw = "The document you are trying to open is protected with a new password. Enter the correct password to access the content."; + Messages.dph_tmp_destroyed = "This template has been destroyed by its owner"; + Messages.dph_tmp_moderated = "This template has been deleted by the moderation team"; + Messages.dph_tmp_moderated_account = "This template has been deleted with its owner's account"; // Keep this key ??? + Messages.dph_tmp_pw = "This template is protected with a new password. Open it from your drive to enter its new password."; - UI.getDestroyedPlaceholderMessage = (code, isAccount) => { + + + + UI.getDestroyedPlaceholderMessage = (code, isAccount, isTemplate) => { var account = { ARCHIVE_OWNED: Messages.dph_account_destroyed, INACTIVE: Messages.dph_account_inactive, @@ -1568,6 +1581,12 @@ define([ MODERATION_BLOCK: Messages.dph_account_moderated, PASSWORD_CHANGE: Messages.dph_account_pw, }; + var template = { + ARCHIVE_OWNED: Messages.dph_tmp_destroyed, + MODERATION_PAD: Messages.dph_tmp_moderated, + MODERATION_ACCOUNT: Messages.dph_tmp_moderated_account, + PASSWORD_CHANGE: Messages.dph_tmp_pw + }; var pad = { ARCHIVE_OWNED: Messages.dph_pad_destroyed, INACTIVE: Messages.dph_pad_inactive, @@ -1576,7 +1595,14 @@ define([ MODERATION_ACCOUNT: Messages.dph_pad_moderated_account, PASSWORD_CHANGE: Messages.dph_pad_pw }; - return isAccount ? account[code] : pad[code]; + var msg = pad[code]; + if (isAccount) { + msg = account[code]; + } else if (isTemplate) { + msg = template[code]; + } + if (!msg) { msg = Messages.dph_default; } + return msg; }; UI.getDestroyedPlaceholder = function (reason, isAccount) { if (typeof(reason) !== "string") { return; } diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 6fd93f48b..ed20b69cc 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -961,9 +961,9 @@ define([ optsPut.accessKeys = keys; })); }).nThen(function () { - Crypt.get(parsed.hash, function (err, val) { + Crypt.get(parsed.hash, function (err, val, errData) { if (err) { - return void cb(err); + return void cb(err, errData); } if (!val) { return void cb('ENOENT'); @@ -1005,10 +1005,10 @@ define([ optsGet.accessKeys = keys; })); }).nThen(function () { - Crypt.get(parsed.hash, function (err, _val) { + Crypt.get(parsed.hash, function (err, _val, errData) { if (err) { _waitFor.abort(); - return void cb(err); + return void cb(err, errData); } try { val = JSON.parse(_val); diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 1fe44e859..b8db20e59 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -2264,13 +2264,13 @@ define([ // server Cryptpad.useTemplate({ href: data.template - }, Cryptget, function (err) { + }, Cryptget, function (err, errData) { if (err) { // TODO: better messages in case of expired, deleted, etc.? if (err === 'ERESTRICTED') { sframeChan.event('EV_RESTRICTED_ERROR'); } else { - sframeChan.query("EV_LOADING_ERROR", "DELETED"); + sframeChan.query("EV_LOADING_ERROR", errData || 'DELETED'); } return; } @@ -2281,13 +2281,13 @@ define([ } // if we open a new code from a file if (Cryptpad.fromFileData && !isOO) { - Cryptpad.useFile(Cryptget, function (err) { + Cryptpad.useFile(Cryptget, function (err, errData) { if (err) { // TODO: better messages in case of expired, deleted, etc.? if (err === 'ERESTRICTED') { sframeChan.event('EV_RESTRICTED_ERROR'); } else { - sframeChan.query("EV_LOADING_ERROR", "DELETED"); + sframeChan.query("EV_LOADING_ERROR", errData || 'DELETED'); } return; } diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index ef39e02bf..a71d0babc 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -894,10 +894,15 @@ define([ ctx.sframeChan.on('EV_LOADING_ERROR', function (err) { var msg = err; - if (err === 'DELETED') { + if (err === 'DELETED' || (err && err.type === 'EDELETED')) { // XXX You can still use the current version in read-only mode by pressing Esc. // what if they don't have a keyboard (ie. mobile) - msg = Messages.deletedError + '
' + Messages.errorRedirectToHome; + if (err.type && err.message) { + msg = UI.getDestroyedPlaceholderMessage(err.message, false, true); + } else { + msg = Messages.deletedError; + } + msg += '
' + Messages.errorRedirectToHome; } else if (err === "INVALID_HASH") { msg = Messages.invalidHashError; } else if (err === 'ACCOUNT') { // block 404 but no placeholder diff --git a/www/drive/inner.js b/www/drive/inner.js index 91ee3c3c1..28dc8ef38 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -57,7 +57,7 @@ define([ if (!newObj || !Object.keys(newObj).length) { // Empty anon drive: deleted var msg = Messages.deletedError + '
' + Messages.errorRedirectToHome; - setTimeout(function () { UI.errorLoadingScreen(msg, false, function () {}); }); + setTimeout(function () { UI.errorLoadingScreen(msg, false, true); }); APP.newSharedFolder = null; } }