sc-site-sync/lib/common/dashboardWorkflow.js
2026-10-19 01:25:16 -05:00

45 lines
1.9 KiB
JavaScript

// A configuration_workflow that bounces straight to the plugin's own dashboard.
//
// The plugin "gear" on Settings -> Plugins always opens /plugins/configure/<name>,
// which renders the plugin's configuration workflow form (the core configure
// route has no redirect hook -- server/routes/plugins.js). Plugins whose real
// settings live in their own dashboard use this single step to get there with NO
// extra click.
//
// NOTE: blurb MUST be an ARRAY -- the array path is rendered raw (form.ts join),
// whereas a string blurb is run through the text() XSS whitelist, which strips
// <script>/<meta>. CSP allows 'unsafe-inline', so the inline script redirect is
// the primary path; the <noscript> meta-refresh and the visible button are
// fallbacks (the link is what shows if script/meta are ever stripped).
const { escapeHtml } = require("./htmlEscape");
// name = the plugin name shown on the step and the button; url = its dashboard.
const createDashboardWorkflow = ({ name, url }) => {
const Workflow = require("@saltcorn/data/models/workflow");
const Form = require("@saltcorn/data/models/form");
const href = escapeHtml(url);
const label = escapeHtml(name);
return new Workflow({
steps: [
{
name: name,
form: async () =>
new Form({
blurb: [
`<script>window.location.replace(${JSON.stringify(url)});</script>`,
`<noscript><meta http-equiv="refresh" content="0; url=${href}"></noscript>`,
`<p>Opening the ${label} dashboard&hellip; <a class="btn btn-primary" role="button" href="${href}">Open the ${label} dashboard</a></p>`
],
fields: []
})
}
]
});
};
module.exports = {
createDashboardWorkflow
};