Per user preferences: small, non-sensitive settings a user has chosen for themselves, such as which admin menu they want. Stored as one JSON document per profile in the tenant's file storage. Nothing here belongs in the database: these are user interface choices, they are read far more often than written, and losing one is a mild annoyance rather than data loss. This is the same file, in the same format, that admin-lib's userPrefsService has always used for intro panel state - that service is now a thin wrapper over this one, so there is a single implementation of the concern. Hence the directory name, which is historical and now misleading: renaming it would silently reset every user's dismissed panels, which is not worth a tidier string. Values keep their JSON type. Intro panel state is written as a JSON boolean and read back in script as prefs[panelId] === true, so coercing everything to strings here would quietly un-dismiss every panel. Menu code consults preferences many times per request - MenuItem.setActiveIds alone is called from 141 places - so a read must not hit storage every time. Each request caches the document it loaded, keyed by profile, in the request attributes. Outside a request there is no cache and no default user, so callers get the supplied default.
Group: Managers
Methods
get(Profile profile, String key, String defaultValue)
Returns: String
Read a preference.
| Parameter | Description |
|---|---|
profile | whose preferences to read. May be null, eg an anonymous or system context |
key | the preference name. Must not be null |
defaultValue | what to return when the profile is null, the preference has never been set, or the stored document cannot be read |
getBoolean(Profile profile, String key, boolean defaultValue)
Returns: boolean
Read a boolean preference.
| Parameter | Description |
|---|---|
profile | whose preferences to read. May be null |
key | the preference name. Must not be null |
defaultValue | what to return when the preference has never been set or cannot be read |
set(Profile profile, String key, String value)
Returns: void
Write a preference, replacing any previous value for that key and leaving the profile's other preferences alone.
| Parameter | Description |
|---|---|
profile | whose preferences to write. Must not be null |
key | the preference name. Must not be null |
value | the value to store. Null removes the preference |
setBoolean(Profile profile, String key, boolean value)
Returns: void
Write a boolean preference.
| Parameter | Description |
|---|---|
profile | whose preferences to write. Must not be null |
key | the preference name. Must not be null |
value | the value to store |
setAll(Profile profile, Map<String,Object> prefs)
Returns: void
Replace a profile's preferences wholesale.
| Parameter | Description |
|---|---|
profile | whose preferences to write. Must not be null |
prefs | the complete set of preferences. Must not be null. Values keep their type |
all(Profile profile)
Returns: Map<String,Object>
All of a profile's preferences.
| Parameter | Description |
|---|---|
profile | whose preferences to read. May be null |