IP masked users use localStorage for settings

Bug: T330517
Change-Id: Ib283e37f379e8cccc7f49ab0ce9aadd6535ea668
This commit is contained in:
Jon Robson 2023-06-12 09:08:27 -07:00
parent 140c9bf1ab
commit 049729626c
11 changed files with 33 additions and 10 deletions

View file

@ -72,7 +72,7 @@
"bundlesize": [
{
"path": "resources/dist/index.js",
"maxSize": "14.3kB"
"maxSize": "14.4kB"
}
]
}

Binary file not shown.

Binary file not shown.

View file

@ -89,7 +89,7 @@ export function boot(
id: config.get( 'wgArticleId' )
},
user: {
isAnon: user.isAnon(),
isAnon: user.isAnon() || mw.user.isTemp(),
editCount
}
};

View file

@ -0,0 +1,11 @@
/**
* Can the current user save to user preferences?
*
* @param {User} user
* @return {boolean}
*/
const canSaveToUserPreferences = ( user ) => {
return !user.isAnon() && user.isNamed();
};
module.exports = canSaveToUserPreferences;

View file

@ -1,6 +1,7 @@
/**
* @module isPagePreviewsEnabled
*/
const canSaveToUserPreferences = require( './canSaveToUserPreferences.js' );
/**
* Given the global state of the application, creates a function that gets
@ -24,9 +25,9 @@ export default function isPagePreviewsEnabled( user, userSettings, config ) {
return null;
}
// For anonymous users, the code loads always, but the feature can be toggled at run-time via
// local storage.
if ( user.isAnon() ) {
// For anonymous users, and for IP masked usersm the code loads always,
// but the feature can be toggled at run-time via local storage.
if ( !canSaveToUserPreferences( user ) ) {
return userSettings.isPagePreviewsEnabled();
}

View file

@ -1,6 +1,7 @@
/**
* @module isReferencePreviewsEnabled
*/
const canSaveToUserPreferences = require( './canSaveToUserPreferences.js' );
/**
* Given the global state of the application, creates a function that gets
@ -29,7 +30,7 @@ export default function isReferencePreviewsEnabled( user, userSettings, config )
// For anonymous users, the code loads always, but the feature can be toggled at run-time via
// local storage.
if ( user.isAnon() ) {
if ( !canSaveToUserPreferences( user ) ) {
return userSettings.isReferencePreviewsEnabled();
}

View file

@ -1,6 +1,7 @@
/**
* @module previewBehaviour
*/
const canSaveToUserPreferences = require( './canSaveToUserPreferences.js' );
/**
* A collection of event handlers specific to how the user interacts with all
@ -33,7 +34,7 @@
export default function createPreviewBehavior( user, actions ) {
let settingsUrl, showSettings = () => {};
if ( user.isAnon() ) {
if ( !canSaveToUserPreferences( user ) ) {
showSettings = ( event ) => {
event.preventDefault();

View file

@ -123,7 +123,10 @@ QUnit.test( 'all relevant combinations of flags', ( assert ) => {
expected: null
}
].forEach( ( data ) => {
const user = { isAnon: () => data.isAnon },
const user = {
isNamed: () => !data.isAnon && !data.isIPMasked,
isAnon: () => data.isAnon
},
userSettings = {
isReferencePreviewsEnabled: () => data.isAnon ?
data.enabledByAnon :

View file

@ -10,6 +10,12 @@ export function createStubUser( isAnon ) {
getPageviewToken() {
return '9876543210';
},
isNamed() {
return !isAnon;
},
isTemp() {
return false;
},
isAnon() {
return isAnon;
},

View file

@ -112,8 +112,8 @@ module.exports = ( env, argv ) => ( {
// Minified uncompressed size limits for chunks / assets and entrypoints. Keep these numbers
// up-to-date and rounded to the nearest 10th of a kibibyte so that code sizing costs are
// well understood. Related to bundlesize minified, gzipped compressed file size tests.
maxAssetSize: 45.5 * 1024,
maxEntrypointSize: 45.5 * 1024,
maxAssetSize: 45.6 * 1024,
maxEntrypointSize: 45.6 * 1024,
// The default filter excludes map files but we rename ours.
assetFilter: ( filename ) => !filename.endsWith( srcMapExt )