From dcbf876d03f2c7e52bb4bb3003c42e014b5b8385 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 27 Aug 2020 16:24:43 -0400 Subject: [PATCH] hooks: New mechanism to deprecate hooks I plan on splitting authFailure into authnFailure and authzFailure so that separate authentication and authentication plugins can coexist peacefully. This change will make it possible to mark the authFailure hook as deprecated (which simply logs a warning). --- src/static/js/pluginfw/hooks.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/static/js/pluginfw/hooks.js b/src/static/js/pluginfw/hooks.js index aadb2216e..7bc8dd2b7 100644 --- a/src/static/js/pluginfw/hooks.js +++ b/src/static/js/pluginfw/hooks.js @@ -1,10 +1,33 @@ var _ = require("underscore"); +// Maps the name of a server-side hook to a string explaining the deprecation +// (e.g., 'use the foo hook instead'). +// +// If you want to deprecate the fooBar hook, do the following: +// +// const hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks'); +// hooks.deprecationNotices.fooBar = 'use the newSpiffy hook instead'; +// +exports.deprecationNotices = {}; + +const deprecationWarned = {}; + +function checkDeprecation(hook) { + const notice = exports.deprecationNotices[hook.hook_name]; + if (notice == null) return; + if (deprecationWarned[hook.hook_fn_name]) return; + console.warn('%s hook used by the %s plugin (%s) is deprecated: %s', + hook.hook_name, hook.part.name, hook.hook_fn_name, notice); + deprecationWarned[hook.hook_fn_name] = true; +} + exports.bubbleExceptions = true var hookCallWrapper = function (hook, hook_name, args, cb) { if (cb === undefined) cb = function (x) { return x; }; + checkDeprecation(hook); + // Normalize output to list for both sync and async cases var normalize = function(x) { if (x === undefined) return [];