From 9b5c784bdc3a10d3c850e486c97dce5b794166a3 Mon Sep 17 00:00:00 2001 From: Aleksey Gurianov Date: Tue, 17 Jul 2018 18:32:21 +0400 Subject: [PATCH] Admin page to approve deleteme request --- web/app/common/api.js | 5 +++ web/app/common/constants.js | 45 ++++++++--------------- web/app/common/settings.js | 1 + web/app/deleteme.js | 28 +++++++++++++++ web/app/utils/email.js | 2 +- web/deleteme.html | 71 +++++++++++++++++++++++++++++++++++++ web/webpack.config.js | 3 +- 7 files changed, 122 insertions(+), 33 deletions(-) create mode 100644 web/app/deleteme.js create mode 100644 web/deleteme.html diff --git a/web/app/common/api.js b/web/app/common/api.js index 8534874b..56a36175 100644 --- a/web/app/common/api.js +++ b/web/app/common/api.js @@ -76,6 +76,11 @@ export const deleteMe = () => url: `/deleteme?site=${siteId}`, }); +export const approveDeleteMe = token => + fetcher.get({ + url: `/admin/deleteme?token=${token}`, + }); + /* admin */ export const pinComment = ({ id, url }) => fetcher.put({ diff --git a/web/app/common/constants.js b/web/app/common/constants.js index 971feea7..b28b4bb5 100644 --- a/web/app/common/constants.js +++ b/web/app/common/constants.js @@ -1,24 +1,24 @@ -const BASE_URL = process.env.REMARK_URL; -const API_BASE = '/api/v1'; -const NODE_ID = process.env.REMARK_NODE; -const COUNTER_NODE_CLASSNAME = 'remark42__counter'; -const COMMENT_NODE_CLASSNAME_PREFIX = 'remark42__comment-'; -const LAST_COMMENTS_NODE_CLASSNAME = 'remark42__last-comments'; -const DEFAULT_LAST_COMMENTS_MAX = 15; -const DEFAULT_MAX_COMMENT_SIZE = 1000; -const MAX_SHOWN_ROOT_COMMENTS = 10; -const DEFAULT_SORT = '-score'; -const PROVIDER_NAMES = { +export const BASE_URL = process.env.REMARK_URL; +export const API_BASE = '/api/v1'; +export const NODE_ID = process.env.REMARK_NODE; +export const COUNTER_NODE_CLASSNAME = 'remark42__counter'; +export const COMMENT_NODE_CLASSNAME_PREFIX = 'remark42__comment-'; +export const LAST_COMMENTS_NODE_CLASSNAME = 'remark42__last-comments'; +export const DEFAULT_LAST_COMMENTS_MAX = 15; +export const DEFAULT_MAX_COMMENT_SIZE = 1000; +export const MAX_SHOWN_ROOT_COMMENTS = 10; +export const DEFAULT_SORT = '-score'; +export const PROVIDER_NAMES = { google: 'Google', facebook: 'Facebook', github: 'GitHub', yandex: 'Yandex', dev: 'Dev', }; -const LS_COLLAPSE_KEY = '__remarkCollapsed'; -const LS_SORT_KEY = '__remarkSort'; +export const LS_COLLAPSE_KEY = '__remarkCollapsed'; +export const LS_SORT_KEY = '__remarkSort'; -const BLOCKING_DURATIONS = [ +export const BLOCKING_DURATIONS = [ { label: 'Permanently', value: 'permanently', @@ -36,20 +36,3 @@ const BLOCKING_DURATIONS = [ value: `${60 * 24}m`, }, ]; - -module.exports = { - BASE_URL, - API_BASE, - NODE_ID, - COUNTER_NODE_CLASSNAME, - LAST_COMMENTS_NODE_CLASSNAME, - COMMENT_NODE_CLASSNAME_PREFIX, - DEFAULT_LAST_COMMENTS_MAX, - DEFAULT_MAX_COMMENT_SIZE, - MAX_SHOWN_ROOT_COMMENTS, - PROVIDER_NAMES, - DEFAULT_SORT, - LS_COLLAPSE_KEY, - LS_SORT_KEY, - BLOCKING_DURATIONS, -}; diff --git a/web/app/common/settings.js b/web/app/common/settings.js index 8d5862d6..8cee687c 100644 --- a/web/app/common/settings.js +++ b/web/app/common/settings.js @@ -11,3 +11,4 @@ const querySettings = export const siteId = querySettings['site_id']; export const url = querySettings['url']; export const maxShownComments = querySettings['max_shown_comments']; +export const token = querySettings['token']; diff --git a/web/app/deleteme.js b/web/app/deleteme.js new file mode 100644 index 00000000..2186461c --- /dev/null +++ b/web/app/deleteme.js @@ -0,0 +1,28 @@ +import { NODE_ID } from 'common/constants'; +import { approveDeleteMe } from 'common/api'; +import { token } from 'common/settings'; + +if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', init); +} else { + init(); +} + +function init() { + const node = document.getElementById(NODE_ID); + + if (!node) { + console.error("Remark42: Can't find root node."); + return; + } + approveDeleteMe(token).then( + data => + (node.innerHTML = ` +

User deleted successfully

+
${JSON.stringify(data, null, 4)}
`), + err => + (node.innerHTML = ` +

Something went wrong

+
${err}
`) + ); +} diff --git a/web/app/utils/email.js b/web/app/utils/email.js index a980c834..5ad99850 100644 --- a/web/app/utils/email.js +++ b/web/app/utils/email.js @@ -30,6 +30,6 @@ export function requestDeletion() { deleteMe().then(data => { const email = store.get('config').admin_email; const { subject, message } = getDeleteInformationMessage(data.user_id, siteId, data.link); - window.open(`mailto:${email}?subject=${subject}&body=${message}`); + window.location = `mailto:${email}?subject=${subject}&body=${message}`; }); } diff --git a/web/deleteme.html b/web/deleteme.html new file mode 100644 index 00000000..32081e7a --- /dev/null +++ b/web/deleteme.html @@ -0,0 +1,71 @@ + + + + + + remark42 + + + + +
+
+
+
+
+
+
+ + + diff --git a/web/webpack.config.js b/web/webpack.config.js index c71449f3..cceb3a6f 100644 --- a/web/webpack.config.js +++ b/web/webpack.config.js @@ -46,6 +46,7 @@ module.exports = { counter: './app/counter', 'last-comments': './app/last-comments', remark: './app/remark', + deleteme: './app/deleteme', }, output: { path: publicFolder, @@ -129,7 +130,7 @@ module.exports = { openAnalyzer: false, }), ]), - new Copy(['./iframe.html']), + new Copy(['./iframe.html', './deleteme.html']), ], watchOptions: { ignored: /(node_modules|\.vendor\.js$)/,