-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into BC-4913-Remove-passage-on-user-registration
- Loading branch information
Showing
26 changed files
with
253 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const express = require('express'); | ||
const { URL } = require('url'); | ||
const { DOCUMENT_BASE_DIR, SC_THEME } = require('../config/global'); | ||
const { specificFiles } = require('../config/documents'); | ||
const { getBase64File } = require('../helpers/fileHelper'); | ||
const { getConsentVersion } = require('../helpers/consentVersionHelper'); | ||
|
||
const router = express.Router(); | ||
|
||
const termsUrl = () => new URL(`${SC_THEME}/${specificFiles.termsOfUseSchool}`, DOCUMENT_BASE_DIR); | ||
|
||
router.get('/', async (req, res, next) => { | ||
try { | ||
const consentVersions = await getConsentVersion(req, res, 'termsOfUse'); | ||
|
||
if (consentVersions.data.length) { | ||
const fileId = consentVersions.data[0].consentDataId; | ||
if (!fileId) { | ||
res.redirect(termsUrl().toString()); | ||
} | ||
|
||
const fileTitle = res.$t('global.text.termsOfUseFile'); | ||
|
||
await getBase64File(req, res, fileId, fileTitle); | ||
} else { | ||
res.redirect(termsUrl().toString()); | ||
} | ||
} catch (err) { | ||
next(err); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const api = require('../api'); | ||
const authHelper = require('./authentication'); | ||
|
||
const getConsentVersion = async (req, res, consentType) => { | ||
const isAuthenticated = await authHelper.isAuthenticated(req); | ||
const qs = { | ||
$limit: 1, | ||
consentTypes: [consentType], | ||
$sort: { | ||
publishedAt: -1, | ||
}, | ||
}; | ||
|
||
if (isAuthenticated && res.locals.currentSchool) { | ||
qs.schoolId = res.locals.currentSchool; | ||
} | ||
|
||
const consentVersion = await api(req).get('/consentVersions', { qs }); | ||
return consentVersion; | ||
}; | ||
|
||
module.exports = { | ||
getConsentVersion, | ||
}; |
Oops, something went wrong.