37bba69b6bc2f9135aa5891fb86c17b1bc5885d8
[squeep-indie-auther] / src / template / admin-ticket-html.js
1 'use strict';
2
3 /**
4 * This renders the interface for submitting a ticket proffer to a third-party.
5 */
6
7 const th = require('./template-helper');
8 const { sessionNavLinks } = require('@squeep/authentication-module');
9
10
11 function renderProfileOption(profile) {
12 return `<option value="${profile}">${profile}</option>`;
13 }
14
15 function renderScopeCheckboxTR(scope) {
16 const defaultChecked = ['read'];
17 const checked = defaultChecked.includes(scope) ? ' checked' : '';
18 return `<tr class="scope">
19 \t<td><input type="checkbox" id="scopes-${scope}" name="scopes" value="${scope}"${checked}></td>
20 \t<td>${scope}</td>
21 </tr>`;
22 }
23
24 function mainContent(ctx) {
25 const profileOptions = th.indented(4, (ctx?.profilesScopes?.profiles || []).map((profile) => renderProfileOption(profile)))
26 .join('\n');
27 const elideScopes = ['profile', 'email'];
28 const allScopes = Object.keys(ctx?.profilesScopes?.scopeIndex || {});
29 const displayScopes = (allScopes).filter((scope) => !elideScopes.includes(scope));
30 const scopesCheckboxRows = th.indented(4, displayScopes.map((scope) => renderScopeCheckboxTR(scope)))
31 .join('\n');
32 return `<section>
33 \t<form action="" method="POST">
34 \t\t<div>
35 \t\t\tYou may proactively send a ticket to a third-party site,
36 \t\t\twhich they may redeem for an access token which grants additional
37 \t\t\taccess to the specified resource.
38 \t\t</div>
39 \t\t<br>
40 \t\t<fieldset>
41 \t\t\t<legend>Proffer A Ticket</legend>
42 \t\t\t<label for="profile-select">Profile Granting this Ticket</label>
43 \t\t\t<select id="profile-select" name="profile">
44 ${profileOptions}
45 \t\t\t</select>
46 \t\t\t<br>
47 \t\t\t<label for="resource-url">Resource URL:</label>
48 \t\t\t<input type="url" id="resource-url" name="resource" size="96">
49 \t\t\t<br>
50 \t\t\t<label for="recipient-url">Recipient URL:</label>
51 \t\t\t<input type="url" id="recipient-url" name="subject" size="96">
52 \t\t\t<br>
53 <fieldset>
54 <legend>Scopes</legend>
55 \t\t\t<table>
56 ${scopesCheckboxRows}
57 \t\t\t</table>
58 </fieldset>
59 \t\t\t<br>
60 \t\t\t<label for="scopes-adhoc">Additional Scopes (space separated):</label>
61 \t\t\t<input type="text" id="scopes-adhoc" name="adhoc" size="96">
62 \t\t\t<br>
63 \t\t\t<button name="action" value="proffer-ticket">Send Ticket</button>
64 \t\t</fieldset>
65 \t</form>
66 </section>`;
67 }
68
69
70 /**
71 *
72 * @param {Object} ctx
73 * @param {Object} ctx.profilesScopes.scopeIndex
74 * @param {String[]} ctx.profileScopes.profiles
75 * @param {Object} options
76 * @param {Object} options.manager
77 * @param {String} options.manager.pageTitle
78 * @param {String} options.manager.logoUrl
79 * @param {String[]} options.manager.footerEntries
80 * @returns {String}
81 */
82 module.exports = (ctx, options) => {
83 const pagePathLevel = 1;
84 const htmlOptions = {
85 padeIdentifier: 'ticketProffer',
86 pageTitle: options.manager.pageTitle + ' - Ticket Proffer',
87 logoUrl: options.manager.logoUrl,
88 footerEntries: options.manager.footerEntries,
89 errorContent: ['Unable to send ticket.'],
90 };
91 th.navLinks(pagePathLevel, ctx, htmlOptions);
92 sessionNavLinks(pagePathLevel, ctx, htmlOptions);
93 const content = [
94 mainContent(ctx),
95 ];
96 return th.htmlPage(pagePathLevel, ctx, htmlOptions, content);
97 };