Symfony-2 gives more than one validation error message - validation

My validation.yml is given:
task:
- Email:
message: The email "{{ value }}" is not a valid email.
- MinLength: { limit: 50, message: You must be 50 or under to enter. }
My issue is that if I give "wrong-email" in the task-field it gives two error messages:
The email "wrong-email" is not a valid email.
You must be 50 or under to enter.
Actually, I want to show only one error-message at a time.
That means it should check for the validation "MinLength" only if it is a valid email.

Validation sequencing can be done using group sequences. I fixed group sequences for the YAML driver only today, so you might need to wait for the next release of the 2.0 or master branch.
MyEntity:
group_sequence: [MyEntity, Extra]
properties:
task:
- Email: { message: ... }
- MinLength { limit: 50, message: ..., groups: Extra }
Now the constraints in group "Extra" will only be validated if all constraints in group "MyEntity" (i.e. the default group) succeed.

Related

Saltstack user.present does not set uid while creating the user

My goal is to have a user with a given uid. I try to have a simple user created with the very basic state:
Add Student:
user.present:
- name: Student
- uid: 333123123123
- allow_uid_change: True
333123123123 is just some dummy value. I'd like something more meanigful later, but this is what I use for testing.
This creates the user perfectly fine, but with generated uid:
ID: Add Student
Function: user.present
Name: Student
Result: True
Comment: New user Student created
Started: 19:47:33.543457
Duration: 203.157 ms
Changes:
----------
account_disabled:
False
account_locked:
False
active:
True
comment:
description:
disallow_change_password:
False
expiration_date:
2106-02-07 07:28:15
expired:
True
failed_logon_attempts:
0
fullname:
Student
gid:
groups:
home:
homedrive:
last_logon:
Never
logonscript:
name:
Student
passwd:
None
password_changed:
2022-02-21 19:47:33
password_never_expires:
False
profile:
None
successful_logon_attempts:
0
uid:
S-1-5-21-3207633127-2685365797-3805984769-1043
Summary
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 203.157 ms
Now, if I try running state.apply again, I get the following message:
ID: Add Student
Function: user.present
Name: Student
Result: False
Comment: Encountered error checking for needed changes. Additional info follows:
- Changing uid (S-1-5-21-3207633127-2685365797-3805984769-1043 -> 333123123123) not permitted, set allow_uid_change to True to force this change. Note that this will not change file ownership.
Started: 19:47:45.503643
Duration: 7000.025 ms
Changes:
Summary
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 7.000 s
So it IS being considered, checked and verified - but not working while creating the user. The syntax seems to be confirmed. Why is it not getting applied upon creating the user?
It is possible to change a user's SID, but it requires unsupported registry hacking. Creating a new user with a specific SID would be even harder. Salt won't do that.
If you need to know the SID of a Windows user, you have to create it first and then query it. If you need it in a following state in the same run, then you can use slots.

How does the formActions works?

I do not understand how the slot mapping does to know which "utterance" to answer the user to get the "entity" requested.
example of my form class:
class RestaurantForm(FormAction):
"""Example of a custom form action"""
def name(self):
# type: () -> Text
"""Unique identifier of the form"""
return "formaejemplo"
#staticmethod
def required_slots(tracker):
# type: () -> List[Text]
"""A list of required slots that the form has to fill"""
return ["valor1","valor2","valor3"]
def slot_mappings(self):
return {"valor1": self.from_entity(entity="valor1",intent="getvalor1"),
"valor2": self.from_entity(entity="valor2",intent="getvalor2"),
"valor3": self.from_entity(entity="valor3",intent="getvalor3")}
def submit(self, dispatcher, tracker, domain):
dispatcher.utter_template('utter_listo', tracker)
return []
domain.yml:
intents:
- peticion_habitacion:
use_entities: false
- getvalor1
- getvalor2
- getvalor3
entities:
- valor1
- valor2
- valor3
slots:
valor1:
type: unfeaturized
auto_fill: false
valor2:
type: unfeaturized
auto_fill: false
valor3:
type: unfeaturized
auto_fill: false
actions:
- utter_prueba
- utter_completo
templates:
utter_completo:
- text: "listo:\nvalor 1 {valor1} \nvalor 2 {valor2} \nvalor 3 {valor3}"
utter_prueba:
- text: "iniciando prueba:\n"
utter_valor1:
- text: "dame el valor 1 no enteros"
utter_valor2:
- text: "dame el valor 2 no enteros"
utter_valor3:
- text: "dame el valor 3 no enteros"
utter_listo:
- text: "prueba completa"
forms:
- formaejemplo
in the section where you get the value1, value2 etc ... it is according to the Rasa documentation: "valor1": self.from_entity (entity = "valor1", intent = "getvalor1" "the "valor 1" will be obtained from the intent getvalor1."
my question is, at what time or in what part or what file, the action form is told that it will have to send the "utterance" "utter_valor1" or "utter_valor2", because to several Internet examples plus the same examples of bots of rasa, I see that these send the utterance and then recover the value, but I can not get to understand how they send the utterance and then get the value
I assume you mean how the action sdk determines which template it should use to ask for a requested slot, right?
This logic is actually hardcoded here: https://github.com/RasaHQ/rasa_core_sdk/blob/cfffaac0013606f7614ab0f213bc39623ee8b53c/rasa_core_sdk/forms.py#L374
What it does is simply dispatches an utterance which is utter_ask_{the name of slot which should be requested}.
If the user then sends back his answer, the form action is triggered again and the slot value can be extracted.

How to use symfony callback constraint with validation group in yaml?

I'm using Symfony 2.6 and I'm following these tutorials how to use the validation callback constraint:
http://symfony.com/blog/new-in-symfony-2-4-a-better-callback-constraint
http://symfony.com/doc/current/reference/constraints/Callback.html#external-callbacks-and-closures
To invoke an external validation call I'm trying to use following yaml configuration:
App\APIBundle\Entity\Order:
properties:
id:
- Type:
type: integer
message: "Der Wert {{ value }} ist kein gültiger {{ type }}."
amount:
- Type:
type: integer
message: "Der Wert {{ value }} ist kein gültiger {{ type }}."
groups: [ "AppOrder", "AppOrderbasket" ]
- Callback: [App\APIBundle\Validator\Validator, validate]
groups: [ "AppOrder", "AppOrderbasket" ]
I run into following problems when trying to validate the amount property with an external callback validation class:
The function "validate" within the validation class App\APIBundle\Validator\Validator doesn't get invoked at all. I've tried to add validation groups by adding the "groups" property to the callback constraint. This seems not to be valid as i get this warning (Warning: trim() expects parameter 1 to be string, array given);
If I remove the "groups" property the warning dissapears but the validator is still not invoked.
Any ideas?
Thanks in advance
ninsky
You are now mixing the default option syntax with the normal syntax. That doesn't work.
If you only need to specify the default option (which is the callback option in case of the Callback constraint), you can use Callback: [App\APIBundle\Validator\Validator, validate]. However, if you have to define 2 options (in your case callback and groups), you have to use the normal syntax:
- Callback:
callback: [App\APIBundle\Validator\Validator, validate]
groups: [AppOrder, AppOrderbasket]

How to pass parameter to translated validation error message

In Symfony2, you can translate your validation error messages:
Validation File
# src/Acme/BlogBundle/Resources/config/validation.yml
Acme\BlogBundle\Entity\Author:
properties:
name:
- NotBlank: { message: "author.name.not_blank" }
Translation File
# validators.en.yml
author.name.not_blank: Please enter an author name.
But how can I pass a parameter to the translation file, if e.g. I want to pass the required min or max length?
author.name.min_length: "Required length: %limit% characters."
What about,
Acme\BlogBundle\Entity\Author:
properties:
name:
- NotBlank: { message: "author.name.not_blank" }
- Length:
min: 3
minMessage: "author.name.min_length"
While your translation file should contain,
# validators.en.yml
author.name.not_blank: Please enter an author name.
author.name.min_length: "Required length: {{ limit }} characters."
The {{ limit }} placeholder here will then fit the min pamarater of the length constraint.

How to get HTTP StatusCodes in ember-data

When I invoke
App.store.createRecord(App.User, { name: this.get("name") });
App.store.commit();
how do I know if its successful and how to wait for the asyn message?
Very limited error handling was recently added to DS.RESTAdapter in ember-data master.
When creating or updating records (with bulk commit disabled) and a status code between 400 and 599 is returned, the following will happen:
A 422 Unprocessable Entity will transition the record to the "invalid" state and will add any errors returned from the server to the record's errors property.
The adapter assumes the server will respond with JSON in the following format:
{
errors: {
name: ["can't be blank"],
password: ["must be at least 8 characters", "must contain a number"]
{
}
(The error messages themselves could be arrays of strings or just strings. ember-data doesn't currently care which.)
To detect this state:
record.get('isValid') === false
All other status codes will transition the record to the "error" state.
To detect this state, use:
record.get('isError') === true
More cases may eventually be handled by ember-data out of the box, but for the moment if you need something specific, you'll have to extend DS.RESTAdapter, customizing its didError function to add it in yourself.

Resources