Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | 1x 1x 8x 4x 1x 1x 1x 134x 3x 1x 1x 1x 1x 1x 3x 3x 2x 2x 2x 2x 2x 2x 3x 2x 3x 2x 2x 5x 5x 5x 5x 5x 5x 5x 15x 15x 3x 5x 3x 3x 3x 3x 1x 3x | import DefaultHandler from './default'; import constants from '../../constants'; import { Asset, Assets } from '../../../types'; export const supportedPages = constants.PAGE_NAMES.filter((p) => p.includes('.json')).map((p) => p.replace('.json', '') ); export const pageNameMap = { guardian_multifactor: 'guardian_mfa_page', password_reset: 'change_password', error_page: 'error_page', }; export type Page = { show_log_link?: boolean; name: string; enabled?: boolean; html?: string; url?: string; }; // With this schema, we can only validate property types but not valid properties on per type basis export const schema = { type: 'array', items: { type: 'object', properties: { name: { type: 'string', enum: supportedPages }, html: { type: 'string', default: '' }, url: { type: 'string' }, show_log_link: { type: 'boolean' }, enabled: { type: 'boolean' }, }, required: ['name'], }, }; export default class PagesHandler extends DefaultHandler { constructor(options: DefaultHandler) { super({ ...options, type: 'pages', identifiers: ['name'], }); } objString(page): string { return super.objString({ name: page.name, enabled: page.enabled }); } async updateLoginPage(page): Promise<void> { const globalClient = await this.client.clients.getAll({ is_global: true, paginate: true, include_totals: true, }); Iif (!globalClient[0]) { throw new Error('Unable to find global client id when trying to update the login page'); } await this.client.clients.update( { client_id: globalClient[0].client_id }, { custom_login_page: page.html, custom_login_page_on: page.enabled, } ); this.updated += 1; this.didUpdate(page); } async updatePages(pages: Asset[]): Promise<void> { const toUpdate = pages.filter((p) => supportedPages.includes(p.name)); const update = toUpdate.reduce((accum, page) => { Eif (supportedPages.includes(page.name)) { const pageName = pageNameMap[page.name]; Iif (!pageName) { throw new Error(`Unable to map page ${page.name} into tenant level page setting`); } accum[pageName] = { ...page }; delete accum[pageName].name; } return accum; }, {}); if (Object.keys(update).length) { await this.client.tenant.updateSettings(update); } toUpdate.forEach((page) => { this.updated += 1; this.didUpdate(page); }); } async getType(): Promise<Asset[]> { const pages: { name: string; enabled: boolean; html: string; }[] = []; // Login page is handled via the global client const globalClient = await this.client.clients.getAll({ is_global: true, paginate: true, include_totals: true, }); Iif (!globalClient[0]) { throw new Error('Unable to find global client id when trying to dump the login page'); } Eif (globalClient[0].custom_login_page) { pages.push({ name: 'login', enabled: !!globalClient[0].custom_login_page_on, html: globalClient[0].custom_login_page, }); } const tenantSettings = await this.client.tenant.getSettings(); Object.entries(pageNameMap).forEach(([key, name]) => { const page = tenantSettings[name]; if (tenantSettings[name]) { pages.push({ ...page, name: key, }); } }); return pages; } async processChanges(assets: Assets): Promise<void> { const { pages } = assets; // Do nothing if not set Iif (!pages) return; // Login page is handled via the global client const loginPage = pages.find((p) => p.name === 'login'); if (loginPage !== undefined) { await this.updateLoginPage(loginPage); } // Rest of pages are on tenant level settings await this.updatePages(pages.filter((p) => p.name !== 'login')); } } |