Skip to content

Commit

Permalink
Merge branch 'support/2.13.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Mar 13, 2024
2 parents 0936bcf + b4b177e commit 9ca9c2f
Show file tree
Hide file tree
Showing 38 changed files with 900 additions and 372 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
<a name="2.13.9"></a>
## [HEAD](https://github.com/pluginsGLPI/formcreator/compare/2.13.8..2.13.9) (2024-03-13)


### Bug Fixes

* prevent issue when response body has blank characters ([1b141a3fa](https://github.com/pluginsGLPI/formcreator/commit/1b141a3fa))
* **command:** typos ([2681eca61](https://github.com/pluginsGLPI/formcreator/commit/2681eca61))
* **dropdownfield:** ambiguous column in SQL query ([3c0630554](https://github.com/pluginsGLPI/formcreator/commit/3c0630554))
* **dropdownfield:** incomplete group restriction ([eebcc21f1](https://github.com/pluginsGLPI/formcreator/commit/eebcc21f1))
* **formansswer:** keep tickets on delete ([b3cc8d2b9](https://github.com/pluginsGLPI/formcreator/commit/b3cc8d2b9))
* **formanswer:** translate section name for targets ([cb9ce0fb6](https://github.com/pluginsGLPI/formcreator/commit/cb9ce0fb6))
* **hiddenfield:** escaping problem when displaying default value in question designer ([3818383e1](https://github.com/pluginsGLPI/formcreator/commit/3818383e1))
* **install:** dashboard setup with pre 2.13.7 appearance ([08d3871e1](https://github.com/pluginsGLPI/formcreator/commit/08d3871e1))
* **issue:** deduplicate rows whern showing technicians in issues ([8bc96d3dc](https://github.com/pluginsGLPI/formcreator/commit/8bc96d3dc))
* **issue:** prevent list of all issues in search engine ([55530d976](https://github.com/pluginsGLPI/formcreator/commit/55530d976))
* **reminder:** visibility ([826881427](https://github.com/pluginsGLPI/formcreator/commit/826881427))
* **target_actor:** duplicate failure with gours, supliers or users ([d77cde058](https://github.com/pluginsGLPI/formcreator/commit/d77cde058))
* **target_actor:** groups duplication ([dbfcc796b](https://github.com/pluginsGLPI/formcreator/commit/dbfcc796b))
* **targetticket:** set location may fail ([75144be06](https://github.com/pluginsGLPI/formcreator/commit/75144be06))
* **textarea:** support for min/max size and regex ([09682e9b8](https://github.com/pluginsGLPI/formcreator/commit/09682e9b8))


### Features

* **glpiselectfield:** support Cluster itemtype ([e72e2603c](https://github.com/pluginsGLPI/formcreator/commit/e72e2603c))



<a name="2.13.8"></a>
## [2.13.8](https://github.com/pluginsGLPI/formcreator/compare/2.13.7..2.13.8) (2023-111-08)

Expand Down
16 changes: 16 additions & 0 deletions inc/abstracttarget.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ abstract public static function getTargetItemtypeName(): string;
*/
abstract protected function getTaggableFields();

abstract protected function getTemplateItemtypeName();

const DESTINATION_ENTITY_CURRENT = 1;
const DESTINATION_ENTITY_REQUESTER = 2;
const DESTINATION_ENTITY_REQUESTER_DYN_FIRST = 3;
Expand Down Expand Up @@ -561,4 +563,18 @@ public function prepareInputForClone($input) {
unset($input['uuid']);
return $input;
}

protected static function getTemplateByName(string $name): int {
$targetTemplateType = (new static())->getTemplateItemtypeName();
$targetTemplate = new $targetTemplateType();
$targetTemplate->getFromDBByCrit([
'name' => $name,
]);

if ($targetTemplate->isNewItem()) {
return 0;
}

return $targetTemplate->getID();
}
}
6 changes: 3 additions & 3 deletions inc/command/cleanticketscommand.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ protected function fixBadForm_2(InputInterface $input, OutputInterface $output)
];
}
if ($replace === null) {
$message = __("Unable to determine the encoding type of item ID: %1$d", "formcreator");
$message = __('Unable to determine the encoding type of item ID: %1$d', "formcreator");
$output->writeln("<error>" . sprintf($message, $item['id']) . "</error>");
continue;
}
Expand Down Expand Up @@ -282,8 +282,8 @@ protected function fixBadForm_3(InputInterface $input, OutputInterface $output)
];
}
if ($replace === null) {
$message = __("Unable to determine the encoding type of item ID: %1$d", "formcreator");
$output->writeln("<error>" . sprinf($message, $item['id']) . "</error>");
$message = __('Unable to determine the encoding type of item ID: %1$d', "formcreator");
$output->writeln("<error>" . sprintf($message, $item['id']) . "</error>");
continue;
}
$item['content'] = str_replace($pattern, $replace, $item['content']);
Expand Down
1 change: 0 additions & 1 deletion inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,6 @@ public static function hookRedefineMenu($menus) {
'ORDER' => "$reminderTable.name"
];
$criteria = $criteria + Reminder::getVisibilityCriteria();
$criteria['WHERE']["$reminderTable.users_id"] = ['<>', Session::getLoginUserID()];
$iterator = $DB->request($criteria);
$hasReminder = $iterator->count() > 0;

Expand Down
2 changes: 1 addition & 1 deletion inc/field/actorfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getRenderedHtml($domain, $canEdit = true): string {
'display_emptychoice' => false,
'values' => array_keys($value),
'valuesnames' => array_values($value),
'_idor_token' => Session::getNewIDORToken(User::getType()),
'_idor_token' => Session::getNewIDORToken(User::getType(), ['entity_restrict' => -1]),
];
$html .= \PluginFormcreatorCommon::jsAjaxDropdown(
$fieldName . '[]',
Expand Down
15 changes: 12 additions & 3 deletions inc/field/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function buildParams($rand = null) {
],
]);
$tickets_filter[] = [
'id' => $requestersObserversQuery,
Ticket::getTableField('id') => $requestersObserversQuery,
];
}

Expand Down Expand Up @@ -383,7 +383,15 @@ public function getRenderedHtml($domain, $canEdit = true): string {
$dparams = [];
$dparams = $this->buildParams($rand);
$dparams['display'] = false;
$dparams['_idor_token'] = Session::getNewIDORToken($itemtype);

$idor_params = [];
foreach (['condition', 'displaywith', 'entity_restrict', 'right'] as $sensitive_param) {
if (array_key_exists($sensitive_param, $dparams)) {
$idor_params[$sensitive_param] = $dparams[$sensitive_param];
}
}
$dparams['_idor_token'] = Session::getNewIDORToken($itemtype, $idor_params);

$html .= $itemtype::dropdown($dparams);
$html .= PHP_EOL;
$html .= Html::scriptBlock("$(function() {
Expand Down Expand Up @@ -594,8 +602,9 @@ private function getMyGroups($userID) {
if ($result->count() === 0) {
return [];
}
$a_groups = [];
foreach ($result as $data) {
$a_groups = $dbUtil->getAncestorsOf("glpi_groups", $data["groups_id"]);
$a_groups = $a_groups + $dbUtil->getAncestorsOf("glpi_groups", $data["groups_id"]);
$a_groups[$data["groups_id"]] = $data["groups_id"];
}
return $a_groups;
Expand Down
2 changes: 1 addition & 1 deletion inc/field/hiddenfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function isPrerequisites(): bool {
public function showForm(array $options): void {
$template = '@formcreator/field/' . $this->question->fields['fieldtype'] . 'field.html.twig';

$this->question->fields['default_values'] = Html::entities_deep($this->question->fields['default_values']);
// $this->question->fields['default_values'] = Html::entities_deep($this->question->fields['default_values']);
$this->deserializeValue($this->question->fields['default_values']);
TemplateRenderer::getInstance()->display($template, [
'item' => $this->question,
Expand Down
35 changes: 34 additions & 1 deletion inc/field/textareafield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,40 @@ public function isValid(): bool {
return false;
}

// All is OK
return $this->isValidValue($this->value);
}

public function isValidValue($value): bool {
if (strlen($value) == 0) {
return true;
}

$parameters = $this->getParameters();

$stripped = strip_tags($value);

// Check the field matches the format regex
$regex = $parameters['regex']->fields['regex'];
if ($regex !== null && strlen($regex) > 0) {
if (!preg_match($regex, $stripped)) {
Session::addMessageAfterRedirect(sprintf(__('Specific format does not match: %s', 'formcreator'), $this->question->fields['name']), false, ERROR);
return false;
}
}

// Check the field is in the range
$rangeMin = $parameters['range']->fields['range_min'];
$rangeMax = $parameters['range']->fields['range_max'];
if ($rangeMin > 0 && strlen($stripped) < $rangeMin) {
Session::addMessageAfterRedirect(sprintf(__('The text is too short (minimum %d characters): %s', 'formcreator'), $rangeMin, $this->question->fields['name']), false, ERROR);
return false;
}

if ($rangeMax > 0 && strlen($stripped) > $rangeMax) {
Session::addMessageAfterRedirect(sprintf(__('The text is too long (maximum %d characters): %s', 'formcreator'), $rangeMax, $this->question->fields['name']), false, ERROR);
return false;
}

return true;
}

Expand Down
28 changes: 24 additions & 4 deletions inc/form_validator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ public function showForForm(PluginFormcreatorForm $item, $options = []) {
'valuesnames' => array_values($selectedValidatorUsers),
'condition' => Dropdown::addNewCondition($usersCondition),
];
$params['_idor_token'] = Session::getNewIDORToken(User::getType());
$params['_idor_token'] = Session::getNewIDORToken(
User::getType(),
[
'condition' => $params['condition'],
]
);
echo Html::jsAjaxDropdown(
'_validator_users[]',
'_validator_users' . mt_rand(),
Expand Down Expand Up @@ -274,7 +279,12 @@ public function showForForm(PluginFormcreatorForm $item, $options = []) {
'condition' => Dropdown::addNewCondition($groupsCondition),
'display_emptychoice' => false,
];
$params['_idor_token'] = Session::getNewIDORToken(Group::getType());
$params['_idor_token'] = Session::getNewIDORToken(
Group::getType(),
[
'condition' => $params['condition'],
]
);
echo Html::jsAjaxDropdown(
'_validator_groups[]',
'_validator_groups' . mt_rand(),
Expand Down Expand Up @@ -567,8 +577,13 @@ public static function dropdownValidatorUser(): string {
'entity_restrict' => -1,
'itemtype' => User::getType(),
'condition' => Dropdown::addNewCondition($usersCondition),
'_idor_token' => Session::getNewIDORToken(User::getType()),
];
$params['_idor_token'] = Session::getNewIDORToken(
User::getType(),
[
'condition' => $params['condition'],
]
);

return Html::jsAjaxDropdown(
'_validator_users[]',
Expand Down Expand Up @@ -646,8 +661,13 @@ public static function dropdownValidatorGroup(): string {
'itemtype' => Group::getType(),
'condition' => Dropdown::addNewCondition($groupsCondition),
'display_emptychoice' => false,
'_idor_token' => Session::getNewIDORToken(Group::getType()),
];
$params['_idor_token'] = Session::getNewIDORToken(
Group::getType(),
[
'condition' => $params['condition'],
]
);

return Html::jsAjaxDropdown(
'_validator_groups[]',
Expand Down
10 changes: 8 additions & 2 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,12 +940,16 @@ public function prepareInputForUpdate($input) {
* @return boolean true if pre_delete actions succeeded, false if not
*/
public function pre_deleteItem() {
global $CFG_GLPI;

$issue = new PluginFormcreatorIssue();
$issue->deleteByCriteria([
'items_id' => $this->getID(),
'itemtype' => self::getType(),
]);

$CFG_GLPI['keep_tickets_on_delete'] = '1';

return true;
}

Expand Down Expand Up @@ -1112,6 +1116,8 @@ public function getFullForm($richText = false): string {
$formFk = PluginFormcreatorForm::getForeignKeyField();
$fields = $this->getQuestionFields($this->fields[$formFk]);

$domain = PluginFormcreatorForm::getTranslationDomain($this->fields[$formFk]);

$this->deserializeAnswers();

// TODO: code very close to PluginFormcreatorAbstractTarget::parseTags() (factorizable ?)
Expand Down Expand Up @@ -1164,9 +1170,9 @@ public function getFullForm($richText = false): string {
$output .= ($richText ? '<p>&nbsp;</p>' : $eol);
}
if ($richText) {
$output .= '<h2>' . $question_line['section_name'] . '</h2>';
$output .= '<h2>' . __($question_line['section_name'], $domain) . '</h2>';
} else {
$output .= $eol . $question_line['section_name'] . $eol;
$output .= $eol . __($question_line['section_name'], $domain) . $eol;
$output .= '---------------------------------' . $eol;
}
$last_section = $question_line[$sectionFk];
Expand Down
5 changes: 5 additions & 0 deletions inc/issue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ public function rawSearchOptions() {
'field' => 'name',
'name' => __('Name'),
'datatype' => 'itemlink',
'searchtype' => [
'0' => 'contains',
'1' => 'not contains',
],
'massiveaction' => false,
'additionalfields' => [
'0' => 'display_id'
Expand Down Expand Up @@ -727,6 +731,7 @@ public function rawSearchOptions() {
'field' => 'name',
'name' => __('Technician'),
'datatype' => 'dropdown',
'forcegroupby' => true,
'massiveaction' => false,
'nodisplay' => $hide_technician,
'nosearch' => $hide_technician,
Expand Down
1 change: 1 addition & 0 deletions inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ public static function dropdownObjectSubType(string $name, array $options = []):
Line::class => Line::getTypeName($plural),
PassiveDCEquipment::class => PassiveDCEquipment::getTypeName($plural),
PDU::class => PDU::getTypeName($plural),
Cluster::class => Cluster::getTypeName(2),
],
__("Assistance") => [
Ticket::class => Ticket::getTypeName($plural),
Expand Down
Loading

0 comments on commit 9ca9c2f

Please sign in to comment.