Skip to content

Commit

Permalink
Merge branch 'support/2.13.0' into support/2.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Aug 25, 2023
2 parents 703d353 + 4815abe commit f106f0c
Show file tree
Hide file tree
Showing 20 changed files with 462 additions and 147 deletions.
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
<a name="2.13.7"></a>
## [2.13.7](https://github.com/pluginsGLPI/formcreator/compare/2.13.6..2.13.7) (2023-07-19)


### Bug Fixes

* Adding READ right for display reservations menu tab ([03e6281e](https://github.com/pluginsGLPI/formcreator/commit/03e6281e))
* bad lcoale in en_US ([db9986f1](https://github.com/pluginsGLPI/formcreator/commit/db9986f1))
* resize dashboard to match GLPI's core (#3306) ([9272cda3](https://github.com/pluginsGLPI/formcreator/commit/9272cda3))
* show FAQ without tabs for self-service ([c5499ad4](https://github.com/pluginsGLPI/formcreator/commit/c5499ad4))
* **TargetChange:** use RichText instead of plaintext ([8845b888](https://github.com/pluginsGLPI/formcreator/commit/8845b888))
* **checkboxesfield,radiosfield,selectfield:** add missing error messages ([66585193](https://github.com/pluginsGLPI/formcreator/commit/66585193))
* **datefield, datetimefield:** comparison against empty string ([be4831c7](https://github.com/pluginsGLPI/formcreator/commit/be4831c7))
* **dropdownfield:** SQL error for GLPI objects / tickets and some specific rights ([2539e366](https://github.com/pluginsGLPI/formcreator/commit/2539e366))
* **dropdownfield:** handle specific case with Entity itemtype ([bd25e7d1](https://github.com/pluginsGLPI/formcreator/commit/bd25e7d1))
* **dropdownfield:** missing entity restriction setting ([54543cb3](https://github.com/pluginsGLPI/formcreator/commit/54543cb3))
* **dropdownfield:** prevent language switching and log error ([49f8fc07](https://github.com/pluginsGLPI/formcreator/commit/49f8fc07))
* **fieldsfield:** restore mandatory field as read only ([52a9fc2b](https://github.com/pluginsGLPI/formcreator/commit/52a9fc2b))
* **form,category:** obey show count on tabs parameter ([f4ebf9e5](https://github.com/pluginsGLPI/formcreator/commit/f4ebf9e5))
* **form_language:** obey show counter in tab setting ([9dfc3b8d](https://github.com/pluginsGLPI/formcreator/commit/9dfc3b8d))
* **formanswer:** php warning ([ce078990](https://github.com/pluginsGLPI/formcreator/commit/ce078990))
* **formanswer:** prevent silent rejection of answers ([d630302d](https://github.com/pluginsGLPI/formcreator/commit/d630302d))
* **formanswer:** redirect to login if session expired ([eb0acb65](https://github.com/pluginsGLPI/formcreator/commit/eb0acb65))
* **glpiselectfield:** fix namespace (#3287) ([613e0fad](https://github.com/pluginsGLPI/formcreator/commit/613e0fad))
* **install:** missing row in sql query, causing PHP warning ([0c47776a](https://github.com/pluginsGLPI/formcreator/commit/0c47776a))
* **issue:** php warnings when anonymisation enabled ([f6f01d7d](https://github.com/pluginsGLPI/formcreator/commit/f6f01d7d))
* **issue:** prevent fatal error in tooltip ([3419affc](https://github.com/pluginsGLPI/formcreator/commit/3419affc))
* **question,section:** duplicate a question or section must duplicate inner conditions ([22597832](https://github.com/pluginsGLPI/formcreator/commit/22597832))
* **section:** cannot rename section twice ([7bbb9b81](https://github.com/pluginsGLPI/formcreator/commit/7bbb9b81))
* **section:** condition rule loss after duplicate / import ([883a1227](https://github.com/pluginsGLPI/formcreator/commit/883a1227))
* **section:** duplicate form may lead to bad question id in condition ([a6f9c41c](https://github.com/pluginsGLPI/formcreator/commit/a6f9c41c))
* **section:** rename section impacts display of inner questions ([c4277d8c](https://github.com/pluginsGLPI/formcreator/commit/c4277d8c))
* **selectfield,multiselectfield:** fix possible encoding problem ([8aaec8ac](https://github.com/pluginsGLPI/formcreator/commit/8aaec8ac))
* **tag:** tag was always deleted ([6201d61d](https://github.com/pluginsGLPI/formcreator/commit/6201d61d))
* **targetchange,targetproblem:** folow method call signature for fields plugin ([016696ab](https://github.com/pluginsGLPI/formcreator/commit/016696ab))
* **textfield:** Unescaped HTML when displaying a form answer ([6ce71f95](https://github.com/pluginsGLPI/formcreator/commit/6ce71f95))
* **textfield:** exception while displaying counters ([0a857d7f](https://github.com/pluginsGLPI/formcreator/commit/0a857d7f))
* **textfield:** target ticket title need html encoding ([1b71d652](https://github.com/pluginsGLPI/formcreator/commit/1b71d652))



<a name="2.13.6"></a>
## [2.13.6](https://github.com/pluginsGLPI/formcreator/compare/2.13.5..2.13.6) (2023-05-26)

Expand Down
19 changes: 17 additions & 2 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,25 @@ public function archiveBuild($release = 'release') {
}

// Add composer dependencies
$this->_exec("composer install --no-dev --working-dir='$archiveWorkdir/$pluginName'");
$success = $this->taskExec('composer')
->arg('install')
->arg('--no-dev')
->arg("--working-dir='$archiveWorkdir/$pluginName'")
->run();
if ($success->getExitCode() != 0) {
throw new RuntimeException("failed to generate PHP resources");
}

// Add JS dependencies
$this->_exec("yarn --cwd '$archiveWorkdir/$pluginName' install --prod");
$success = $this->taskExec('yarn')
->arg('--cwd')
->arg("$archiveWorkdir/$pluginName")
->arg('install')
->arg('--prod')
->run();
if ($success->getExitCode() != 0) {
throw new RuntimeException("failed to generate JS resources");
}

// Create the final archive
$this->taskPack($archiveFile)
Expand Down
16 changes: 9 additions & 7 deletions inc/abstractfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,13 @@ public function getLabel() {

/**
* Gets the available values for the field
* @param array $values values to parse. If null, the values are ised from the instance of the question
* @return array available values
*/
public function getAvailableValues() {
$values = json_decode($this->question->fields['values']);
public function getAvailableValues(array $values = null): array {
if ($values === null) {
$values = json_decode($this->question->fields['values']);
}
$tab_values = [];
foreach ($values as $value) {
$trimmedValue = trim($value);
Expand All @@ -221,13 +224,11 @@ public function isRequired(): bool {
}

/**
* trim values separated by \r\n
* trim and explode values separated by \r\n
* @param string $value a value or default value
* @return string
* @return array
*/
protected function trimValue($value) {
global $DB;

protected function trimValue($value): array {
$value = explode('\r\n', $value);
// input has escpaed single quotes
$value = Toolbox::stripslashes_deep($value);
Expand All @@ -241,6 +242,7 @@ function ($value) {
$value
);

return $value;
return $DB->escape(json_encode($value, JSON_UNESCAPED_UNICODE));
}

Expand Down
31 changes: 20 additions & 11 deletions inc/field/checkboxesfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,24 +250,33 @@ public function isValidValue($value): bool {
}

public function prepareQuestionInputForSave($input) {
if (isset($input['values'])) {
if (strlen($input['values']) === 0) {
global $DB;

if (strlen($input['values'] ?? '') == 0) {
Session::addMessageAfterRedirect(
__('The field value is required.', 'formcreator'),
false,
ERROR
);
return [];
}

$values = $this->trimValue($input['values']);
$defaultValues = $this->trimValue($input['default_values'] ?? '');
if (count($defaultValues) > 0) {
// trim values
$validDefaultValues = array_intersect($this->getAvailableValues($values), $defaultValues);
if (count($validDefaultValues) != (count($defaultValues))) {
Session::addMessageAfterRedirect(
__('The field value is required:', 'formcreator') . ' ' . $input['name'],
__('The default values are not in the list of available values.', 'formcreator'),
false,
ERROR
);
return [];
}

// trim values
$input['values'] = $this->trimValue($input['values']);
}

if (isset($input['default_values'])) {
// trim values
$input['default_values'] = $this->trimValue($input['default_values']);
$input['default_values'] = $DB->escape(json_encode($defaultValues, JSON_UNESCAPED_UNICODE));
}
$input['values'] = $DB->escape(json_encode($values, JSON_UNESCAPED_UNICODE));

return $input;
}
Expand Down
9 changes: 6 additions & 3 deletions inc/field/glpiselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function showForm(array $options): void {
}
$this->question->fields['default_values'] = Html::entities_deep($this->question->fields['default_values']);
$this->deserializeValue($this->question->fields['default_values']);
$this->question->fields['_default_values'] = $this->value;

$parameters = $this->getParameters();
TemplateRenderer::getInstance()->display($template, [
Expand Down Expand Up @@ -106,7 +107,9 @@ public function isValidValue($value): bool {
}

public function prepareQuestionInputForSave($input) {
if (isset($input['itemtype']) && empty($input['itemtype'])) {
global $DB;

if (!isset($input['itemtype']) || strlen($input['itemtype']) === 0) {
Session::addMessageAfterRedirect(
__('The field value is required:', 'formcreator') . ' ' . $input['name'],
false,
Expand Down Expand Up @@ -134,7 +137,7 @@ public function prepareQuestionInputForSave($input) {
unset($input['show_tree_depth']);
unset($input['selectable_tree_root']);

$input['values'] = json_encode($input['values']);
$input['values'] = $DB->escape(json_encode($input['values'], JSON_UNESCAPED_UNICODE));

return $input;
}
Expand All @@ -143,7 +146,7 @@ public static function canRequire(): bool {
return true;
}

public function getAvailableValues(): array {
public function getAvailableValues(array $values = null): array {
return [];
}

Expand Down
41 changes: 29 additions & 12 deletions inc/field/radiosfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function isPrerequisites(): bool {
public function showForm(array $options): void {
$template = '@formcreator/field/' . $this->question->fields['fieldtype'] . 'field.html.twig';

$this->question->fields['values'] = json_decode($this->question->fields['values']);
$this->question->fields['values'] = json_decode($this->question->fields['values']);
$this->question->fields['values'] = is_array($this->question->fields['values']) ? $this->question->fields['values'] : [];
$this->question->fields['values'] = implode("\r\n", $this->question->fields['values']);
$this->deserializeValue($this->question->fields['default_values']);
Expand Down Expand Up @@ -110,24 +110,41 @@ public static function getName(): string {
}

public function prepareQuestionInputForSave($input) {
if (isset($input['values'])) {
if (strlen($input['values']) === 0) {
global $DB;

if (strlen($input['values'] ?? '') === 0) {
Session::addMessageAfterRedirect(
__('The field value is required.', 'formcreator'),
false,
ERROR
);
return [];
}

// trim values (actually there is only one value then no \r\n expected)
$defaultValues = $this->trimValue($input['default_values'] ?? '');
if (count($defaultValues) > 1) {
Session::addMessageAfterRedirect(
__('Only one default value is allowed.', 'formcreator'),
false,
ERROR
);
return [];
}
$values = $this->trimValue($input['values']);
if (count($defaultValues) > 0) {
$validDefaultValues = array_intersect($this->getAvailableValues($values), $defaultValues);
if (count($validDefaultValues) != count($defaultValues)) {
Session::addMessageAfterRedirect(
__('The field value is required:', 'formcreator') . ' ' . $input['name'],
__('The default value is not in the list of available values.', 'formcreator'),
false,
ERROR
);
return [];
}

// trim values
$input['values'] = $this->trimValue($input['values']);
}

if (isset($input['default_values'])) {
// trim values
$input['default_values'] = trim($input['default_values']);
}
$input['values'] = $DB->escape(json_encode($values, JSON_UNESCAPED_UNICODE));
$input['default_values'] = array_pop($defaultValues);

return $input;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/field/requesttypefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function canRequire(): bool {
return true;
}

public function getAvailableValues() {
public function getAvailableValues(array $values = null): array {
return Ticket::getTypes();
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/selectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getRenderedHtml($domain, $canEdit = true): string {
foreach ($values as $value) {
if ((trim($value) != '')) {
$unsanitized = Sanitizer::unsanitize(__($value, $domain));
$translatedValues[$unsanitized] = $unsanitized;
$translatedValues[$value] = $unsanitized;
}
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/urgencyfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static function canRequire(): bool {
return true;
}

public function getAvailableValues() {
public function getAvailableValues(array $values = null): array {
return [
5 => _x('urgency', 'Very high'),
4 => _x('urgency', 'High'),
Expand Down
10 changes: 9 additions & 1 deletion inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,8 @@ public function parseTags(string $content, PluginFormcreatorTargetInterface $tar
$content = Sanitizer::sanitize($content);
}

$content = $this->parseExtraTags($content, $target, $richText);

$hook_data = Plugin::doHookFunction('formcreator_parse_extra_tags', [
'formanswer' => $this,
'content' => $content,
Expand All @@ -1462,6 +1464,12 @@ public function parseTags(string $content, PluginFormcreatorTargetInterface $tar
return $hook_data['content'];
}

protected function parseExtraTags(string $content, PluginFormcreatorTargetInterface $target = null, $richText = false): string {
$content = str_replace('##answer_id##', $this->getField('id'), $content);

return $content;
}

/**
* Validates answers of a form
*
Expand Down Expand Up @@ -1699,7 +1707,7 @@ public function createIssue() {
'items_id' => $ticketId,
'itemtype' => Ticket::class,
'name' => $issueName,
'status' => $ticket->fields['status'],
'status' => PluginFormcreatorCommon::getTicketStatusForIssue($ticket),
'date_creation' => $ticket->fields['date'],
'date_mod' => $ticket->fields['date_mod'],
'entities_id' => $ticket->fields['entities_id'],
Expand Down
4 changes: 2 additions & 2 deletions inc/targetchange.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,6 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM {
return null;
}

$this->saveTags($formanswer, $changeID);

// Add link between Change and FormAnswer
$itemlink = $this->getItem_Item();
$itemlink->add([
Expand All @@ -709,6 +707,8 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM {
'changes_id' => $changeID,
]);

$this->saveTags($formanswer, $changeID);

return $change;
}

Expand Down
4 changes: 2 additions & 2 deletions inc/targetproblem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM {
return null;
}

$this->saveTags($formanswer, $problemID);

// Add link between Problem and FormAnswer
$itemlink = $this->getItem_Item();
$itemlink->add([
Expand All @@ -229,6 +227,8 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM {
'problems_id' => $problemID,
]);

$this->saveTags($formanswer, $problemID);

return $problem;
}

Expand Down
4 changes: 2 additions & 2 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,6 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM {
}
}

$this->saveTags($formanswer, $ticketID);

// Add link between Ticket and FormAnswer
$itemlink = $this->getItem_Item();
$itemlink->add([
Expand All @@ -917,6 +915,8 @@ public function save(PluginFormcreatorFormAnswer $formanswer): ?CommonDBTM {
'tickets_id' => $ticketID,
]);

$this->saveTags($formanswer, $ticketID);

// Attach validation message as first ticket followup if validation is required and
// if is set in ticket target configuration
if ($form->validationRequired() && $this->fields['validation_followup']) {
Expand Down
5 changes: 5 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ Features
<author>Teclib'</author>
</authors>
<versions>
<version>
<num>2.13.7</num>
<compatibility>~10.0</compatibility>
<download_url>https://github.com/pluginsGLPI/formcreator/releases/download/2.13.7/glpi-formcreator-2.13.7.tar.bz2</download_url>
</version>
<version>
<num>2.13.6</num>
<compatibility>~10.0</compatibility>
Expand Down
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
// Schema version of this version (major.minor only)
define('PLUGIN_FORMCREATOR_SCHEMA_VERSION', '2.14');
// is or is not an official release of the plugin
define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', false);
define('PLUGIN_FORMCREATOR_IS_OFFICIAL_RELEASE', true);

// Minimal GLPI version, inclusive
define ('PLUGIN_FORMCREATOR_GLPI_MIN_VERSION', '10.0.5');
Expand Down
2 changes: 1 addition & 1 deletion templates/field/glpiselectfield.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
{{ fields.dropdownField(
item.fields['itemtype'],
'default_values',
default_values,
item.fields['_default_values'],
__('Default values'), {
label_class: 'col-xxl-4',
input_class: 'col-xxl-8',
Expand Down
Loading

0 comments on commit f106f0c

Please sign in to comment.