@@ -240,24 +240,34 @@ var LifeCycle = (() => {
240240
241241 // put here any version specific upgrade adjustment in stored data
242242
243- if ( Ver . is ( previousVersion , "<=" , "11.0.10" ) ) {
244- log ( `Upgrading from 11.0.10 or below (${ previousVersion } ): configure the "ping" capability.` ) ;
245- await ns . initializing ;
246- ns . policy . TRUSTED . capabilities . add ( "ping" ) ;
247- await ns . savePolicy ( ) ;
248- }
249- if ( Ver . is ( previousVersion , "<=" , "11.2.1" ) ) {
250- log ( `Upgrading from ${ previousVersion } : configure the "noscript" capability.` ) ;
243+ let configureNewCap = async ( cap , presets , presetFilter ) => {
244+ log ( `Upgrading from ${ previousVersion } : configure the "${ cap } " capability.` ) ;
251245 await ns . initializing ;
252- let { DEFAULT , TRUSTED , UNTRUSTED } = ns . policy ;
253- // let's add "noscript" to DEFAULY, TRUSTED and any CUSTOM preset
254- let presets = [ DEFAULT , TRUSTED ] ;
255- presets = presets . concat ( [ ...ns . policy . sites . values ( ) ] . filter ( p => p !== TRUSTED && p !== UNTRUSTED ) ) ;
246+ let policy = ns . policy ;
247+ let customIdx = presets . indexOf ( "CUSTOM" ) ;
248+ presets = presets . map ( p => policy [ p ] )
249+ if ( customIdx !== - 1 ) {
250+ let { TRUSTED , UNTRUSTED } = policy ;
251+ // insert custom presets, if any
252+ presets . splice ( customIdx , 1 , ...[ ...policy . sites . values ( ) ] . filter ( p => p !== TRUSTED && p !== UNTRUSTED ) ) ;
253+ }
254+ if ( presetFilter ) presets = presets . filter ( presetFilter ) ;
256255 for ( let p of presets ) {
257- p . capabilities . add ( "noscript" ) ;
256+ p . capabilities . add ( cap ) ;
258257 }
259258 await ns . savePolicy ( ) ;
260259 }
260+
261+ if ( Ver . is ( previousVersion , "<=" , "11.0.10" ) ) {
262+ await configureNewCap ( "ping" , [ "TRUSTED" ] ) ;
263+ }
264+ if ( Ver . is ( previousVersion , "<=" , "11.2.1" ) ) {
265+ await configureNewCap ( "noscript" , [ "DEFAULT" , "TRUSTED" , "CUSTOM" ] )
266+ }
267+ if ( Ver . is ( previousVersion , "<=" , "11.2.4" ) ) {
268+ // add the csspp0 capability to any preset which already has the script capability
269+ await configureNewCap ( "csspp0" , [ "TRUSTED" , "CUSTOM" , "DEFAULT" ] , p => p . capabilities . has ( "script" ) ) ;
270+ }
261271 } ,
262272
263273 async onUpdateAvailable ( details ) {
0 commit comments