Replace user:local_name with user.local_name macro in restrictions

This commit is contained in:
Eric Lippmann 2021-06-28 14:26:42 +02:00
parent 7e7e2415dc
commit d1aaaf7fb0
3 changed files with 15 additions and 3 deletions

View File

@ -154,10 +154,13 @@ application/share/groups | which groups a user can share navigation items with
### Username placeholder
It is possible to reference the local username (without the domain part) of the user in restrictions. To accomplish
this, put the macro `$user:local_name$` in the restriction where you want it to appear.
this, put the macro `$user.local_name$` in the restriction where you want it to appear.
This can come in handy if you have e.g. an attribute on hosts or services defining which user is responsible for it:
`_host_deputy=$user:local_name$|_service_deputy=$user:local_name$`
`_host_deputy=$user.local_name$|_service_deputy=$user.local_name$`
> Please note that since version 2.9 the use of `user.local_name` instead of `user:local_name` is supported and
> recommended. `user:local_name` is deprecated and will be removed in version 2.11.
### Filter Expressions

View File

@ -10,6 +10,8 @@ v2.6 to v2.8 requires to follow the instructions for v2.7 too.
* Support for EOL PHP versions (5.6, 7.0, 7.1 and 7.2) will be removed with version 2.11
* Support for Internet Explorer will be completely removed with version 2.11
* New features after v2.9 will already not (necessarily) be available in Internet Explorer
* `user.local_name` replaces the `user:local_name` macro in restrictions, and the latter will be removed with
version 2.11
## Upgrading to Icinga Web 2 2.8.x

View File

@ -204,7 +204,14 @@ class AdmissionLoader
$roleRestrictions = $role->getRestrictions();
foreach ($roleRestrictions as $name => & $restriction) {
$restriction = str_replace('$user:local_name$', $user->getLocalUsername(), $restriction);
// TODO(el): user.local_name is supported since version 2.9.
// and therefore user:local_name is deprecated.
// The latter will be removed in version 2.11.
$restriction = str_replace(
['$user.local_name$', '$user:local_name$'],
$user->getLocalUsername(),
$restriction
);
$restrictions[$name][] = $restriction;
}