mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
[web] add includeReferer flag to SplitTestHandler.getAssignment (#33235)
* [web] add includeReferer flag to SplitTestHandler.getAssignment * [web] tests: migrate User.getSplitTestAssignment to async/await I don't want to fight with callbacks and optional arguments. Just move it to async/await. New tests should use async/await, so there is no point in making this work in callback-hell. * [web] remove unused URL import GitOrigin-RevId: 6251001e6ba7354f704fa663be8ef365ca0b9d23
This commit is contained in:
@@ -47,11 +47,17 @@ const DEFAULT_ASSIGNMENT = {
|
||||
* @param req the request
|
||||
* @param res the Express response object
|
||||
* @param splitTestName the unique name of the split test
|
||||
* @param options {Object<sync: boolean>} - for test purposes only, to force the synchronous update of the user's profile
|
||||
* @param {Object} options
|
||||
* @param {boolean} options.sync - for test purposes only, to force the synchronous update of the user's profile
|
||||
* @param {boolean} options.includeReferer For ajax requests and downloads include the split test overrides of the page
|
||||
* @returns {Promise<Assignment>}
|
||||
*/
|
||||
async function getAssignment(req, res, splitTestName, { sync = false } = {}) {
|
||||
const query = req.query || {}
|
||||
async function getAssignment(
|
||||
req,
|
||||
res,
|
||||
splitTestName,
|
||||
{ sync = false, includeReferer = false } = {}
|
||||
) {
|
||||
let assignment
|
||||
|
||||
try {
|
||||
@@ -60,6 +66,20 @@ async function getAssignment(req, res, splitTestName, { sync = false } = {}) {
|
||||
} else {
|
||||
await _loadSplitTestInfoInLocals(res.locals, splitTestName, req.session)
|
||||
|
||||
let query = req.query || {}
|
||||
if (includeReferer && req.headers.referer) {
|
||||
// Pick up the query of the top-level page, i.e. what's in the browsers address bar, from ajax requests.
|
||||
// E.g. /project/:id?split-test=foo -> ajax /project/:id/compile should see split-test=foo.
|
||||
// E.g. /project/:id?split-test=foo -> redirect /project/:id/download/zip should see split-test=foo.
|
||||
try {
|
||||
const u = new URL(req.headers.referer, Settings.siteUrl)
|
||||
query = {
|
||||
...Object.fromEntries(u.searchParams.entries()),
|
||||
...query,
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
// Check the query string for an override, ignoring an invalid value
|
||||
const queryVariant = query[splitTestName]
|
||||
if (queryVariant) {
|
||||
|
||||
Reference in New Issue
Block a user