Repository navigation
Conversation
Fields values could not be used in the texts generated by GLPI.
Notification templates get two tags per field of the notified item,
listed in the "Tags" tab: ##fields.<block>.<field>## for the value as
displayed in the form, ##lang.fields.<block>.<field>## for the label in
the recipient language. A value is only sent to the recipients whose
profile can read the block in the entity of the item.
Followup, task and solution templates get the fields of tickets, changes
and problems, {{ ticket.fields.<block>.<field> }}, and of the assets
linked to a ticket, {{ asset.fields.<block>.<field> }} in
ticket.assets. They are listed in the documentation of the template
variables.
A followup template can be rendered for any user who can read the ticket (ajax/itilfollowup.php), so a requester could read the values of blocks hidden to his profile. As in the item form, the values are now only rendered if the current profile can read the block, except without right checks (template applied by a form) and in the cron.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist before requesting a review
Description
Fields values cannot be used in the texts generated by GLPI: notification templates and followup / task / solution templates. This has been requested several times (#359, #1184) and was started in #943, a draft limited to the "Insertion in the form" blocks of tickets, without value formatting, labels, rights or tests, which has not been updated for more than a year.
This PR starts again from
main, independently of #941, and covers the points raised in the review of #943: every field type is rendered as displayed in the form, labels follow the recipient language, and the behaviour is covered by tests.Notification templates
For the items having notifications (tickets, changes, problems, projects, etc.), two tags per active field, listed in the "Tags" tab of the templates:
##fields.<block>.<field>##: value as displayed in the form: dropdown label (also multiple dropdowns and GLPI item dropdowns), Yes / No, date and date-time in the recipient format, linked item name, rich text;##lang.fields.<block>.<field>##: field label, translated in the recipient language with the existing label translations.<block>and<field>are the system names, so templates do not break when a label is renamed. Header fields and inactive fields / blocks have no tag.Rights. As GLPI does for private followups, a value is only sent to a recipient whose profile can read the block (right
READor more on the block, profile in the entity of the item). It is empty for a recipient without GLPI account (requester email address). The label is always sent.GLPI reads
additionnaloption['users_id']to fillrecipient_datafor theitem_get_datashook, but does not set it. The plugin sets it from theadd_recipient_to_targethook, so the template data is computed by recipient for the items having fields.Followup, task and solution templates
Variables of the fields of tickets, changes and problems, and of the assets linked to a ticket:
{{ ticket.fields.<block>.<field> }} {% for asset in ticket.assets %}{{ asset.name }}: {{ asset.fields.<block>.<field> }}{% endfor %}They are listed in the documentation of the template variables, with the
nl2br/rawfilter for multiple lines text and rich text, through the existingget_content_template_parameter/get_content_template_valuehooks.As in the item form, these values are only rendered if the profile of the user applying the template can read the block:
ajax/itilfollowup.phprenders any template for a user who can read the ticket, including a requester. When the template is applied without right checks, as forms do when they create the ticket (Session::callAsSystem()), or by the cron (followups and reminders of pending reasons, sent to the requester), every value is rendered: the administrator chose the template. A typical use is a form submitted by a requester that adds a private followup with the administration data of the chosen server, for the technicians.ticket.assetsis built asTicketParameters::defineValues()does, with the fields in addition, since the values returned by a plugin replace the GLPI ones. This is only done when an asset type has blocks.Points to discuss
item_add_targets, which is run by theNotificationTargetconstructor, so they are listed in the "Tags" tab. A dedicated hook in GLPI would be cleaner.{{autocompletion of the template editor, which only uses the GLPI parameters. Theget_content_template_parameterhook is only used by the documentation; making the autocompletion use it would be a separate PR to GLPI.Session::isRightChecksDisabled(), which is marked@internalin GLPI. It is the only way I found to tell a ticket created by a form from a template rendered for the current user.Tests
tests/Units/NotificationTagTest.php: tags listing, rendering of every field type, empty values, default value, label translation, block of another entity, rights by recipient (no right, read right, email address), recipient passed to the template data, events without item, followup template rendering with and without right on the block, template rendered for a requester, template applied on ticket creation without right checks, linked assets, and documentation of the variables.Also tested on a production copy (GLPI 12.0.2, 25 blocks): change notifications, ticket notifications seen by a technician and by a self-service profile without right on the block, and a followup template applied by a form and rendered directly for a requester.