Skip to content

Commit

Permalink
feat(form): rename anonymous form to public form
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Feb 15, 2022
1 parent 9e86780 commit 538aebd
Show file tree
Hide file tree
Showing 46 changed files with 71 additions and 71 deletions.
6 changes: 3 additions & 3 deletions front/formdisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
// If user is not authenticated, create temporary user
if (!isset($_SESSION['glpiname'])) {
$_SESSION['formcreator_forms_id'] = $form->getID();
$_SESSION['formcreator_anonymous'] = true;
$_SESSION['formcreator_public'] = true;
$_SESSION['glpiname'] = 'formcreator_temp_user';
$_SESSION['valid_id'] = session_id();
$_SESSION['glpiactiveentities'] = [$form->fields['entities_id']];
Expand All @@ -75,9 +75,9 @@
$form->displayUserForm();

// If user was not authenticated, remove temporary user
if (isset($_SESSION['formcreator_anonymous'])) {
if (isset($_SESSION['formcreator_public'])) {
unset($_SESSION['glpiname']);
unset($_SESSION['formcreator_anonymous']);
unset($_SESSION['formcreator_public']);
session_write_close();
}
} else if (isset($_GET['answer_saved'])) {
Expand Down
2 changes: 1 addition & 1 deletion inc/abstracttarget.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
* Adds an user to the given actor role (requester, observer assigned or supplier)
*
* @param string $role role of the user
* @param string $user user ID or email address for anonymous users
* @param string $user user ID or email address for accountless users
* @param bool $notify true to enable notification for the actor
* @return boolean true on success, false on error
*/
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 @@ -401,7 +401,7 @@ public function regex($value): bool {
return (preg_grep($value, $this->value)) ? true : false;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/checkboxesfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public function regex($value): bool {
return (preg_grep($value, $this->value)) ? true : false;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/datefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function parseAnswerValues($input, $nonDestructive = false): bool {
return true;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/datetimefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function parseAnswerValues($input, $nonDestructive = false): bool {
return true;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/descriptionfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function parseAnswerValues($input, $nonDestructive = false): bool {
return true;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ public function parseAnswerValues($input, $nonDestructive = false): bool {
return true;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/emailfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function regex($value): bool {
return (preg_grep($value, $this->value)) ? true : false;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/filefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function regex($value): bool {
throw new ComparisonException('Meaningless comparison');
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/floatfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function regex($value): bool {
return (preg_grep($value, $this->value)) ? true : false;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/glpiselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function regex($value): bool {
return (preg_grep($value, $this->value)) ? true : false;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return false;
}

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 @@ -163,7 +163,7 @@ public function regex($value): bool {
return (preg_grep($value, $this->value)) ? true : false;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/hostnamefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function regex($value): bool {
return (preg_grep($value, $this->value)) ? true : false;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/ipfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function regex($value): bool {
return (preg_grep($value, $this->value)) ? true : false;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/ldapselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public function regex($value): bool {
return (preg_grep($value, $this->value)) ? true : false;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/radiosfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function regex($value): bool {
return preg_match($value, $this->value) ? true : false;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

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 @@ -223,7 +223,7 @@ public function regex($value): bool {
throw new ComparisonException('Meaningless comparison');
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/tagfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function regex($value): bool {
throw new ComparisonException('Meaningless comparison');
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/textareafield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function regex($value): bool {
return (preg_grep($value, $this->value)) ? true : false;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/textfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function regex($value): bool {
return preg_match($value, Toolbox::stripslashes_deep($this->value)) ? true : false;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/timefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function parseAnswerValues($input, $nonDestructive = false): bool {
return true;
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

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 @@ -227,7 +227,7 @@ public function regex($value): bool {
throw new ComparisonException('Meaningless comparison');
}

public function isAnonymousFormCompatible(): bool {
public function isPublicFormCompatible(): bool {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions inc/fieldinterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ public function regex($value) : bool;
/**
* Is the field compatible with anonymous form ?
*
* @return boolean true if the field can work with anonymous forms
* @return boolean true if the field can work with public forms
*/
public function isAnonymousFormCompatible() : bool;
public function isPublicFormCompatible() : bool;

/**
* Gets HTML code for the icon of a field
Expand Down
10 changes: 5 additions & 5 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ public function displayUserForm() : void {
'options' => [
'columns' => PluginFormcreatorSection::COLUMNS,
'domain' => $domain, // For translation
'anonymous'=> isset($_SESSION['formcreator_anonymous']),
'public' => isset($_SESSION['formcreator_public']),
'use_captcha' => ($this->fields['access_rights'] == PluginFormcreatorForm::ACCESS_PUBLIC
&& $this->fields['is_captcha_enabled'] != '0'),
]
Expand Down Expand Up @@ -1277,7 +1277,7 @@ protected function checkAccessRight(array $input): bool {
$fields = $this->getFields();
$incompatibleQuestion = false;
foreach ($fields as $field) {
if (!$field->isAnonymousFormCompatible()) {
if (!$field->isPublicFormCompatible()) {
$incompatibleQuestion = true;
$message = __('The question %s is not compatible with public forms', 'formcreator');
Session::addMessageAfterRedirect(sprintf($message, $field->getLabel()), false, ERROR);
Expand Down Expand Up @@ -2032,8 +2032,8 @@ public function showForCentral() {
}

/**
* Is the form accessible anonymously (without being logged in) ?
* @return boolean true if the form is accessible anonymously
* Is the form accessible publicly (without being logged in) ?
* @return boolean true if the form is accessible publicly
*/
public function isPublicAccess() : bool {
if ($this->isNewItem()) {
Expand Down Expand Up @@ -2480,7 +2480,7 @@ public function setTranslations(string $language, array $translations) : bool {
}

/**
* Choose the best language for anonymous form
* Choose the best language for publicly form
*
* @return string the best language for this form and session context
*/
Expand Down
2 changes: 1 addition & 1 deletion inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private function checkBeforeSave($input) : array {
$form = PluginFormcreatorCommon::getForm();
$section = PluginFormcreatorSection::getById($input[PluginFormcreatorSection::getForeignKeyField()]);
$form = PluginFormcreatorForm::getByItem($section);
if ($form->isPublicAccess() && !$this->field->isAnonymousFormCompatible()) {
if ($form->isPublicAccess() && !$this->field->isPublicFormCompatible()) {
Session::addMessageAfterRedirect(__('This type of question is not compatible with public forms.', 'formcreator'), false, ERROR);
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion templates/pages/userform.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
{% endif %}
{% endif %}
{% endif %}
{% if not options.anonymous or question.getSubField().isAnonymousFormCompatible() %}
{% if not options.public or question.getSubField().isPublicFormCompatible() %}
{% set sessionData = session('formcreator') %}
{{ question.getRenderedHtml(domain, true, sessionData.data)|raw }}
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions tests/3-unit/GlpiPlugin/Formcreator/Field/ActorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ function() {
)->isInstanceOf(ComparisonException::class);
}

public function testIsAnonymousFormCompatible() {
public function testisPublicFormCompatible() {
$instance = $this->newTestedInstance($this->getQuestion());
$output = $instance->isAnonymousFormCompatible();
$output = $instance->isPublicFormCompatible();
$this->boolean($output)->isFalse();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/3-unit/GlpiPlugin/Formcreator/Field/CheckboxesField.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ public function testGetEmptyParameters() {
->isInstanceOf(\PluginFormcreatorQuestionRange::class);
}

public function testIsAnonymousFormCompatible() {
public function testisPublicFormCompatible() {
$instance = $this->newTestedInstance($this->getQuestion());
$output = $instance->isAnonymousFormCompatible();
$output = $instance->isPublicFormCompatible();
$this->boolean($output)->isTrue();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/3-unit/GlpiPlugin/Formcreator/Field/DateField.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public function testGetName() {
$this->string($output)->isEqualTo('Date');
}

public function testIsAnonymousFormCompatible() {
public function testisPublicFormCompatible() {
$instance = $this->newTestedInstance($this->getQuestion());
$output = $instance->isAnonymousFormCompatible();
$output = $instance->isPublicFormCompatible();
$this->boolean($output)->isTrue();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/3-unit/GlpiPlugin/Formcreator/Field/DatetimeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ public function testNotEquals($value, $answer, $expected) {
$this->boolean($instance->notEquals($value))->isEqualTo($expected);
}

public function testIsAnonymousFormCompatible() {
public function testisPublicFormCompatible() {
$instance = $this->newTestedInstance($this->getQuestion());
$output = $instance->isAnonymousFormCompatible();
$output = $instance->isPublicFormCompatible();
$this->boolean($output)->isTrue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public function testPrepareQuestionInputForSave($input, $expected, $message) {
}
}

public function testIsAnonymousFormCompatible() {
public function testisPublicFormCompatible() {
$instance = $this->newTestedInstance($this->getQuestion());
$output = $instance->isAnonymousFormCompatible();
$output = $instance->isPublicFormCompatible();
$this->boolean($output)->isTrue();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/3-unit/GlpiPlugin/Formcreator/Field/DropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public function testPrepareQuestionInputForSave($input, $expected) {
}
}

public function testIsAnonymousFormCompatible() {
public function testisPublicFormCompatible() {
$instance = $this->newTestedInstance($this->getQuestion());
$output = $instance->isAnonymousFormCompatible();
$output = $instance->isPublicFormCompatible();
$this->boolean($output)->isFalse();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/3-unit/GlpiPlugin/Formcreator/Field/EmailField.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public function testSerializeValue($value, $expected) {
$this->string($output)->isEqualTo($expected ? $value : '');
}

public function testIsAnonymousFormCompatible() {
public function testisPublicFormCompatible() {
$question = $this->getQuestion();
$instance = $this->newTestedInstance($question);
$output = $instance->isAnonymousFormCompatible();
$output = $instance->isPublicFormCompatible();
$this->boolean($output)->isEqualTo(true);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/3-unit/GlpiPlugin/Formcreator/Field/FloatField.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ public function testGetEmptyParameters() {
->isInstanceOf(\PluginFormcreatorQuestionRegex::class);
}

public function testIsAnonymousFormCompatible() {
public function testisPublicFormCompatible() {
$instance = $this->newTestedInstance($this->getQuestion());
$output = $instance->isAnonymousFormCompatible();
$output = $instance->isPublicFormCompatible();
$this->boolean($output)->isTrue();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/3-unit/GlpiPlugin/Formcreator/Field/GlpiSelectField.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ public function testIsValid($fields, $expectedValue, $expectedValidity) {
$this->boolean($output)->isEqualTo($expectedValidity);
}

public function testIsAnonymousFormCompatible() {
public function testisPublicFormCompatible() {
$instance = $this->newTestedInstance($this->getQuestion());
$output = $instance->isAnonymousFormCompatible();
$output = $instance->isPublicFormCompatible();
$this->boolean($output)->isFalse();
}

Expand Down
Loading

0 comments on commit 538aebd

Please sign in to comment.