From 427cf836b11fe86333226a6980457f17865b91a5 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 22 Oct 2019 12:04:30 +0200 Subject: [PATCH] Improve password change workflow --- www/common/drive-ui.js | 6 ++++++ www/common/outer/async-store.js | 11 ++++++++++- www/common/proxy-manager.js | 3 +++ www/common/sframe-common-outer.js | 24 ++++++++++++++++++++---- www/common/userObject.js | 8 ++++---- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index ec7245885..072f144fa 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -1857,6 +1857,12 @@ define([ $span.addClass('cp-app-drive-element-sharedf'); _addOwnership($span, $state, data); + var hrefData = Hash.parsePadUrl(data.href || data.roHref); + if (hrefData.hashData && hrefData.hashData.password) { + var $password = $passwordIcon.clone().appendTo($state); + $password.attr('title', Messages.fm_passwordProtected || ''); + } + var $shared = $sharedIcon.clone().appendTo($state); $shared.attr('title', Messages.fm_canBeShared); } diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 1e419548a..eaa019384 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1919,7 +1919,7 @@ define([ store.manager.user.userObject.getHref(data) : data.href; var parsed = Hash.parsePadUrl(href); var secret = Hash.getSecrets(parsed.type, parsed.hash, o); - SF.updatePassword({ + SF.updatePassword(Store, { oldChannel: secret.channel, password: n, href: href @@ -2063,6 +2063,15 @@ define([ /////////////////////// Init ///////////////////////////////////// ////////////////////////////////////////////////////////////////// + Store.refreshDriveUI = function () { + getAllStores().forEach(function (_s) { + var send = _s.id ? _s.sendEvent : sendDriveEvent; + send('DRIVE_CHANGE', { + path: ['drive', UserObject.FILES_DATA] + }); + }); + }; + var onReady = function (clientId, returned, cb) { var proxy = store.proxy; var unpin = function (data, cb) { diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index aae33e6d8..cf7f7d78b 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -49,6 +49,9 @@ define([ var deprecateProxy = function (Env, id, channel) { Env.unpinPads([channel], function () {}); Env.user.userObject.deprecateSharedFolder(id); + if (Env.Store && Env.Store.refreshDriveUI) { + Env.Store.refreshDriveUI(); + } }; /* diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 87b477d5c..84c08416a 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -215,8 +215,15 @@ define([ if (wrongPasswordStored) { // Store the correct password nThen(function (w) { + // XXX noPasswordStored: return; ? Cryptpad.setPadAttribute('password', password, w(), parsed.getUrl()); Cryptpad.setPadAttribute('channel', secret.channel, w(), parsed.getUrl()); + if (parsed.hashData.mode === 'edit') { + var href = window.location.pathname + '#' + Utils.Hash.getEditHashFromKeys(secret); + Cryptpad.setPadAttribute('href', href, w(), parsed.getUrl()); + var roHref = window.location.pathname + '#' + Utils.Hash.getViewHashFromKeys(secret); + Cryptpad.setPadAttribute('roHref', roHref, w(), parsed.getUrl()); + } }).nThen(correctPassword); } else { correctPassword(); @@ -244,10 +251,19 @@ define([ } password = val; - Cryptpad.getFileSize(window.location.href, password, waitFor(function (e, size) { - if (size !== 0) { - return void todo(); - } + if (parsed.type === "file") { + // `isNewChannel` doesn't work for files (not a channel) + // `getFileSize` is not adapted to channels because of metadata + Cryptpad.getFileSize(window.location.href, password, waitFor(function (e, size) { + if (size !== 0) { return void todo(); } + // Wrong password or deleted file? + askPassword(true); + })); + return; + } + // Not a file, so we can use `isNewChannel` + Cryptpad.isNewChannel(window.location.href, password, waitFor(function(e, isNew) { + if (!isNew) { return void todo(); } if (parsed.hashData.mode === 'view' && (val || !parsed.hashData.password)) { // Error, wrong password stored, the view seed has changed with the password // password will never work diff --git a/www/common/userObject.js b/www/common/userObject.js index 398ebe301..7a81e220f 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -385,8 +385,8 @@ define([ var result; var noPassword = function (str) { if (!str) { return; } - var value = str.replace(/\/p\/?/, '/'); - return Hash.getRelativeHref(value); + var parsed = Hash.parsePadUrl(str); + return parsed.getUrl().replace(/\/p\/?/, '/'); }; var href = noPassword(_href); getFiles([FILES_DATA]).some(function (id) { @@ -403,8 +403,8 @@ define([ var result; var noPassword = function (str) { if (!str) { return; } - var value = str.replace(/\/p\/?/, '/'); - return Hash.getRelativeHref(value); + var parsed = Hash.parsePadUrl(str); + return parsed.getUrl().replace(/\/p\/?/, '/'); }; var href = noPassword(_href); getFiles([SHARED_FOLDERS]).some(function (id) {