Add routes for exposure scan signup and overview

This should make it easier to work on both in parallel while
minimising conflicts.
This commit is contained in:
Vincent 2023-04-12 14:13:04 +02:00 коммит произвёл Vincent
Родитель e1c95e5a92
Коммит 678e66cd09
9 изменённых файлов: 117 добавлений и 8 удалений

Просмотреть файл

@ -16,7 +16,7 @@ const exposureScanPage = (req, res, next) => {
}
/**
* @type {ViewPartialData<import('../views/partials/exposure-scan.js').PartialParameters>}
* @type {GuestViewPartialData<import('../views/partials/exposure-scan.js').PartialParameters>}
*/
const data = {
partial: exposureScan,

Просмотреть файл

@ -0,0 +1,53 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { mainLayout } from '../views/mainLayout.js'
import { generateToken } from '../utils/csrf.js'
import { exposuresSetup } from '../views/partials/exposures-setup.js'
import { exposuresList } from '../views/partials/exposures-list.js'
/**
* @type {import('express').RequestHandler}
*/
async function exposuresPage (req, res) {
const showDashboard = await hasSetUpExposureScanning(req.user)
if (!showDashboard) {
/**
* @type {MainViewPartialData<import('../views/partials/exposures-setup').PartialParameters>}
*/
const data = {
partial: exposuresSetup,
csrfToken: generateToken(res, req),
nonce: res.locals.nonce,
fxaProfile: req.user?.fxa_profile_json
}
res.send(mainLayout(data))
return
}
/**
* @type {MainViewPartialData<import('../views/partials/exposures-list').PartialParameters>}
*/
const data = {
partial: exposuresList,
csrfToken: generateToken(res, req),
nonce: res.locals.nonce,
fxaProfile: req.user?.fxa_profile_json
}
res.send(mainLayout(data))
}
/**
* @param {import('express').Request['user']} user
* @returns {Promise<boolean>} Whether the user has set up exposure scanning already
*/
async function hasSetUpExposureScanning (user) {
// TODO: Once the back-end supports storing a user's exposure scan data,
// check whether it has been entered:
return false
}
export { exposuresPage }

23
src/custom-types.d.ts поставляемый
Просмотреть файл

@ -13,8 +13,23 @@ interface HTMLElement {
// This lint rule does not apply to type definitions:
// eslint-disable-next-line no-unused-vars
type ViewPartial<ViewPartialParams = object> = (data: ViewPartialParams) => string;
type ViewPartialData<ViewPartialParams = object> = {
partial: ViewPartial<ViewPartialParams>,
nonce: string
type ViewPartial<ViewPartialParams = object> = (data: ViewPartialParams & { partial: { name: string } }) => string;
type GuestViewPartialData<ViewPartialParams = object> = {
partial: ViewPartial<ViewPartialParams>;
nonce: string;
} & ViewPartialParams;
type MainViewPartialData<ViewPartialParams = object> = {
fxaProfile: NonNullable<import('express').Request['user']>['fxa_profile_json'];
} & GuestViewPartialData<ViewPartialParams>;
declare namespace Express {
export interface Request {
user?: {
// TODO: Finish the type definition of the user object
fxa_profile_json?: {
avatar: string;
email: string;
}
};
}
}

Просмотреть файл

@ -10,6 +10,7 @@ import { requireSessionUser } from '../middleware/auth.js'
import { logout } from '../controllers/auth.js'
// import { dashboardPage } from '../controllers/dashboard.js'
import { breachesPage } from '../controllers/breaches.js'
import { exposuresPage } from '../controllers/exposures.js'
import { dataRemovalPage } from '../controllers/data-removal.js'
import { settingsPage } from '../controllers/settings.js'
import {
@ -31,6 +32,9 @@ router.get('/dashboard', (req, res) => res.redirect(302, '/user/breaches'))
// data breaches detail page
router.get('/breaches', requireSessionUser, breachesPage)
// data exposures detail page
router.get('/exposures', requireSessionUser, exposuresPage)
// data removal page
router.get('/data-removal', requireSessionUser, dataRemovalPage)

Просмотреть файл

@ -6,9 +6,7 @@ import AppConstants from '../app-constants.js'
import { getMessage, getLocale } from '../utils/fluent.js'
/**
* @template {object} PartialParameters
* @param {ViewPartialData<PartialParameters>} data
* @returns {string}
* @type {ViewPartial<GuestViewPartialData<any>>}
*/
const guestLayout = data => `
<!doctype html>

Просмотреть файл

@ -5,6 +5,9 @@
import AppConstants from '../app-constants.js'
import { getMessage, getLocale } from '../utils/fluent.js'
/**
* @type {ViewPartial<MainViewPartialData<any>>}
*/
const mainLayout = data => `
<!doctype html>
<html lang=${getLocale()}>
@ -126,6 +129,9 @@ const mainLayout = data => `
</html>
`
/**
* @type {ViewPartial<MainViewPartialData>}
*/
const userMenu = data => `
<div class='user-menu-wrapper' tabindex='-1'>
<button

Просмотреть файл

@ -0,0 +1,15 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* @typedef {object} PartialParameters
* @property {string} csrfToken
*/
/**
* @type {ViewPartial<PartialParameters>}
*/
export const exposuresList = data => `
This page will show the user's exposures dashboard, when they have already set up exposure scanning.
`

Просмотреть файл

@ -0,0 +1,15 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* @typedef {object} PartialParameters
* @property {string} csrfToken
*/
/**
* @type {ViewPartial<PartialParameters>}
*/
export const exposuresSetup = data => `
This page will allow the user to enter their information to do a scan for public data exposures.
`

Просмотреть файл

@ -5,7 +5,10 @@
"src/views/partials/add-email.js",
"src/views/partials/admin.js",
"src/views/partials/exposure-scan.js",
"src/views/partials/exposures-setup.js",
"src/views/partials/exposures-list.js",
"src/controllers/exposure-scan.js",
"src/controllers/exposures.js",
"src/utils/emailAddress.js",
// Replace the above with the following when our entire codebase has type annotations:
// "src/**/*",