From 854f1825849411a89d45866957d99341da6b0b37 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sat, 29 May 2021 14:49:21 +0200 Subject: [PATCH] Add revoke capabilities --- _locales/en/messages.json | 4 ++++ background/style-manager.js | 19 ++++++++++++----- background/token-manager.js | 4 ++-- edit.html | 14 ++++++++++--- edit/edit.js | 18 ++++++++++------ edit/usw-debug.js | 16 -------------- edit/usw-linking.js | 42 +++++++++++++++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 32 deletions(-) delete mode 100644 edit/usw-debug.js create mode 100644 edit/usw-linking.js diff --git a/_locales/en/messages.json b/_locales/en/messages.json index d735ab85..29f6105e 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1365,6 +1365,10 @@ "message": "Sections", "description": "Header for the table of contents block listing style section names in the left panel of the classic editor" }, + "linking": { + "message": "Linking", + "description": "Header for the section to link the style with other services." + }, "shortcuts": { "message": "Shortcuts", "description": "Go to shortcut configuration" diff --git a/background/style-manager.js b/background/style-manager.js index 781ccef5..8c9c6f3c 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -354,14 +354,23 @@ const styleMan = (() => { if (port.name !== 'link-style-usw') { return; } - port.onMessage.addListener(async style => { + port.onMessage.addListener(async incData => { + const {data: style, reason} = incData; if (!style.id) { return; } - const resultToken = await tokenMan.getToken('userstylesworld', true, style.id); - style._uswToken = resultToken; - await saveStyle(style); - broadcastStyleUpdated(style, 'updateLinking'); + switch (reason) { + case 'link': + style._uswToken = await tokenMan.getToken('userstylesworld', true, style.id); + handleSave(await saveStyle(style), 'success-linking', true); + break; + + case 'revoke': + await tokenMan.revokeToken('userstylesworld', style.id); + style._uswToken = ''; + handleSave(await saveStyle(style), 'success-revoke', true); + break; + } }); } diff --git a/background/token-manager.js b/background/token-manager.js index 3820ac1d..40c8c0ea 100644 --- a/background/token-manager.js +++ b/background/token-manager.js @@ -94,9 +94,9 @@ const tokenMan = (() => { return authUser(name, k, interactive); }, - async revokeToken(name) { + async revokeToken(name, styleId) { const provider = AUTH[name]; - const k = tokenMan.buildKeys(name); + const k = tokenMan.buildKeys(name, styleId); if (provider.revoke) { try { const token = await chromeLocal.getValue(k.TOKEN); diff --git a/edit.html b/edit.html index 377db734..ad1fffd7 100644 --- a/edit.html +++ b/edit.html @@ -59,6 +59,7 @@ +