2013-08-02 16:37:47 +02:00
|
|
|
# Preferences
|
|
|
|
|
|
|
|
Preferences are user based configuration for Icinga 2 Web. For example max page
|
|
|
|
items, languages or date time settings can controlled by users.
|
|
|
|
|
2013-08-05 10:57:51 +02:00
|
|
|
# Architecture
|
2013-08-02 16:37:47 +02:00
|
|
|
|
|
|
|
Preferences are initially loaded from a provider (ini files or database) and
|
|
|
|
stored into session at login time. After this step preferences are only
|
|
|
|
persisted to the configured backend, but never reloaded from them.
|
|
|
|
|
|
|
|
# Configuration
|
|
|
|
|
2013-08-05 10:57:51 +02:00
|
|
|
Preferences can be configured in config.ini in **preferences** section, default
|
|
|
|
settings are this:
|
2013-08-02 16:37:47 +02:00
|
|
|
|
|
|
|
[preferences]
|
|
|
|
type=ini
|
|
|
|
|
|
|
|
The ini provider uses the directory **config/preferences** to create one ini
|
2013-08-05 16:55:42 +02:00
|
|
|
file per user and persists the data into a single file. If you want to drop your
|
2013-08-02 16:37:47 +02:00
|
|
|
preferences just drop the file from disk and you'll start with a new profile.
|
|
|
|
|
|
|
|
## Database provider
|
|
|
|
|
|
|
|
To be more flexible in distributed setups you can store preferences in a
|
|
|
|
database (pgsql or mysql), a typical configuration looks like the following
|
|
|
|
example:
|
|
|
|
|
|
|
|
[preferences]
|
|
|
|
type=db
|
2013-08-15 14:16:34 +02:00
|
|
|
resource=icingaweb-pgsql
|
2013-08-02 16:37:47 +02:00
|
|
|
|
|
|
|
### Settings
|
|
|
|
|
2013-08-15 14:16:34 +02:00
|
|
|
* **resource**: A reference to a database declared in *resources.ini*. Please read the chapter about
|
|
|
|
resources for a detailed description about how to set up resources.
|
2013-08-02 16:37:47 +02:00
|
|
|
|
|
|
|
### Preparation
|
|
|
|
|
|
|
|
To use this feature you need a running database environment. After creating a
|
|
|
|
database and a writable user you need to import the initial table file:
|
|
|
|
|
|
|
|
* etc/schema/preferences.mysql.sql (for mysql database)
|
|
|
|
* etc/schema/preferemces.pgsql.sql (for postgres databases)
|
|
|
|
|
|
|
|
#### Example for mysql
|
|
|
|
|
|
|
|
# mysql -u root -p
|
|
|
|
mysql> create database icingaweb;
|
|
|
|
mysql> GRANT SELECT,INSERT,UPDATE,DELETE ON icingaweb.* TO \
|
|
|
|
'icingaweb'@'localhost' IDENTIFIED BY 'icingaweb';
|
|
|
|
mysql> exit
|
|
|
|
# mysql -u root -p icingaweb < /path/to/icingaweb/etc/schema/preferences.mysql.sql
|
|
|
|
|
2013-08-05 16:55:42 +02:00
|
|
|
After following these steps above you can configure your preferences provider.
|
2013-08-02 16:37:47 +02:00
|
|
|
|
|
|
|
## Coding API
|
|
|
|
|
2013-08-05 16:55:42 +02:00
|
|
|
You can set, update or remove preferences using the Preference data object
|
|
|
|
which is bound to the user. Here are some simple examples how to work with
|
|
|
|
that:
|
2013-08-02 16:37:47 +02:00
|
|
|
|
|
|
|
$preferences = $user->getPreferences();
|
|
|
|
// Get language with en_US as fallback
|
|
|
|
$preferences->get('app.language', 'en_US');
|
|
|
|
$preferences->set('app.language', 'de_DE');
|
|
|
|
$preferences->remove('app.language');
|
|
|
|
|
|
|
|
// Using transactional mode
|
|
|
|
$preferences->startTransaction();
|
|
|
|
$preferences->set('test.pref1', 'pref1');
|
|
|
|
$preferences->set('test.pref2', 'pref2');
|
|
|
|
$preferences->remove('test.pref3');
|
|
|
|
$preferemces->commit(); // Stores 3 changes in one operation
|
|
|
|
|
2013-08-05 10:57:51 +02:00
|
|
|
More information can be found in the api docs.
|
|
|
|
|
2013-08-02 16:37:47 +02:00
|
|
|
## Namespaces and behaviour
|
|
|
|
|
2013-08-05 10:57:51 +02:00
|
|
|
If you are using this API please obey the following rules:
|
2013-08-02 16:37:47 +02:00
|
|
|
|
|
|
|
* Use dotted notation for preferences
|
|
|
|
* Namespaces starting with one context identifier
|
|
|
|
* **app** as global identified (e.g. app.language)
|
|
|
|
* **mymodule** for your module
|
|
|
|
* **monitoring** for the monitoring module
|
|
|
|
* Use preferences wisely (set only when needed and write small settings)
|
|
|
|
* Use only simple data types, e.g. strings or numbers
|
|
|
|
* If you need complex types you have to do it your self (e.g. serialization)
|