Files
dc/sas/mocks/sasjs/services/public/startupservice.js
T
hermes 966dc072e0
Build / Build-and-ng-test (pull_request) Successful in 5m41s
Lighthouse Checks / lighthouse (pull_request) Successful in 22m13s
Build / Build-and-test-development (pull_request) Successful in 25m42s
feat(system): show session timezone on system information screen
Add TIMEZONE, SYSTIMEZONEIDENT and SYSTIMEZONEOFFSET to the startupservice
globvars and display them in the Environment Details block, so the session
clock used to stamp submission timestamps is directly visible to admins.
2026-09-04 12:15:01 +00:00

142 lines
4.9 KiB
JavaScript

const nodePath = require('path')
let appLoc = nodePath.join(..._program.split('services')[0].split('/'))
const sasjsRoot = nodePath.resolve(weboutPath, '..', '..', '..')
const driveRoot = nodePath.resolve(sasjsRoot, 'drive')
// Load shared DC mock utilities
eval(fs.readFileSync(nodePath.resolve(driveRoot, 'files', appLoc, 'services', 'dcMockUtils.js'), 'utf8'))
const licenceStore = nodePath.resolve(driveRoot, 'files', appLoc, 'mock-storage', 'licence.json')
const usersStore = nodePath.resolve(driveRoot, 'files', appLoc, 'mock-storage', 'users.json')
let licence = {
activationKey: '',
licenceKey: ''
}
let users = {}
let dcLibref = 'DC_JSLIB'
let adminGroup = 'Data Management Business Approvers'
let licenceKey = ''
let activationKey = ''
users = {
REGISTERCOUNT: 1,
ISREGISTERED: 1
}
try {
const licenceRaw = fs.readFileSync(licenceStore, {encoding:'utf8'}).toString()
licence = JSON.parse(licenceRaw)
} catch(err) {
}
try {
const usersRaw = fs.readFileSync(usersStore, {encoding:'utf8'}).toString()
users = JSON.parse(usersRaw)
if (users.ISREGISTERED === 0) {
const newUsers = {
REGISTERCOUNT: users.REGISTERCOUNT,
ISREGISTERED: 1
}
try {
fs.writeFileSync(usersStore, JSON.stringify(newUsers, null, 2))
} catch (err) {}
}
} catch(err) {
}
// DC database location and admin group come from services/settings.js
// (written by makedata). Defaults apply when makedata hasn't run yet.
const dcConf = loadDcSettings(driveRoot, appLoc)
dcLibref = dcConf.dcLibref
let dataDir = dcConf.dataDir
if (dcConf.dcAdminGroup) adminGroup = dcConf.dcAdminGroup
// Build sasdatasets from the MPE_TABLES data file
let sasdatasets = []
if (dataDir) {
try {
const mpeTablesFile = nodePath.resolve(dataDir, 'mpe_tables.json')
const mpeTablesRaw = fs.readFileSync(mpeTablesFile, {encoding:'utf8'}).toString()
const mpeTables = JSON.parse(mpeTablesRaw)
// Filter out any malformed rows (e.g. missing libref/dsn) so the
// sasdatasets list never contains empty objects.
sasdatasets = mpeTables.rows
.filter(r => r.libref && r.dsn)
.map(r => ({ LIBREF: r.libref, DSN: r.dsn }))
sasdatasets.sort((a, b) => a.DSN.localeCompare(b.DSN))
} catch(err) {}
}
// Fallback if makedata hasn't run or MPE_TABLES isn't available
if (sasdatasets.length === 0) {
sasdatasets = [
{ LIBREF: dcLibref, DSN: 'MPE_X_TEST' },
{ LIBREF: dcLibref, DSN: 'MPE_TABLES' }
]
}
if (licence.licenceKey) licenceKey = licence.licenceKey
if (licence.activationKey) activationKey = licence.activationKey
// Keys registered via admin/registerkey are stored in mpe_config
// (DC_LICENCE_KEY / DC_ACTIVATION_KEY), mirroring the real backend's
// dc_getsettings. Prefer the active mpe_config values; mock-storage/licence.json
// remains as a fallback for pre-existing deployments.
if (dataDir) {
try {
const configFile = nodePath.resolve(dataDir, 'mpe_config.json')
const configRaw = fs.readFileSync(configFile, {encoding:'utf8'}).toString()
const config = JSON.parse(configRaw)
if (config && config.rows) {
const getVar = (name) => {
const rows = config.rows.filter(r =>
r.var_scope === 'DC' && r.var_name === name && r.var_active === 1)
if (rows.length === 0) return ''
// TXTEMPORAL: the active row is the one with the high tx_to
const active = rows.find(r => Number(r.tx_to) >= 253717919999) || rows[rows.length - 1]
const val = (active.var_value || '').toString()
return val.trim()
}
const configLicence = getVar('DC_LICENCE_KEY')
const configActivation = getVar('DC_ACTIVATION_KEY')
if (configLicence) licenceKey = configLicence
if (configActivation) activationKey = configActivation
}
} catch(err) { /* mpe_config not available - keep mock-storage values */ }
}
const globvars = [
{
DCLIB: dcLibref,
SAS9LINEAGE_ENABLED: 1,
ISADMIN: 1,
ISREGISTERED: users.ISREGISTERED,
REGISTERCOUNT: users.REGISTERCOUNT,
DC_ADMIN_GROUP: adminGroup,
LICENCE_KEY: licenceKey,
ACTIVATION_KEY: activationKey,
DC_RESTRICT_EDITRECORD: 'NO',
TIMEZONE: 'Europe/London',
SYSTIMEZONEIDENT: 'Europe/London',
SYSTIMEZONEOFFSET: '+0100'
}
]
const xlmaps = [
['BASEL-CR2', '', dcLibref + '.MPE_XLMAP_DATA'],
['BASEL-KM1', 'Basel 3 Key Metrics report', dcLibref + '.MPE_XLMAP_DATA'],
['SAMPLE', '', dcLibref + '.MPE_XLMAP_DATA']
]
webOutOpen()
webOutObj(sasdatasets, 'sasdatasets')
webOutObj([{ LIBREF: dcLibref, LIBRARYNAME: 'Data Controller(' + dcLibref + ')', LIBRARYID: dcLibref, ENGINE: 'V9' }], 'saslibs')
webOutObj(globvars, 'globvars')
webOutObj(xlmaps, 'xlmaps')
webOutClose()