ServiceStack Validation and Input fields Repopulation - servicestack

When Using FluentValidation through ServiceStack, what is the technique for retrieving previous form values when validation fails?
I need this data so that I can repopulate the fields that passed validation. As it stands now, if a user types in one thing wrong, everything on the form is gone and they must re-type everything over again.
Any help would be greatly appreciated.
Thank you.

Related

ModifiedBy field in SharePoint Document library is always my name instead of the one who triggered the flow

I have a flow, that gets triggered when a file is created in the Documents. The flow will add a column to the document library. The problem is that the modified by field in the Document library always contains the value as my name, instead of showing the user who triggered the flow.
I have already followed this article and seems like that is not working on my end.
After doing those changes, my flow runs fine without any error and giving an output as proceeding.
{
  "d": {
    "ValidateUpdateListItem": {
      "__metadata": {
        "type": "Collection(SP.ListItemFormUpdateValue)"
      },
      "results": [
        {
          "ErrorMessage": null,
          "FieldName": "Editor",
          "FieldValue": "[{\"Key\":\"i:0#.f|membership|nk#fdgfsgfs.de\"}]",
          "HasException": false,
          "ItemId": 1
        }
      ]
    }
  }
}
But there are no changes in the Document library, it still shows my name in the modified by column as I created the Flow. Even if this worked, I have another question that how can I dynamically find out and add who is triggering the Fow instead of giving a static editor claim in the first Compose step in the above image?
Anyone else faced this issue? Any help is really appreciated.
I do not think it is possible at the moment to dynamically find the current logged in user. you can check out this post
https://powerusers.microsoft.com/t5/Building-Flows/Flow-to-SharePoint-list-item-change-quot-Created-By-quot/td-p/93668
I could solve this issue by using the REST API in the flow itself. This is what I did,
Get the user who called the flow
Update the Modify field by using the REST API in the flow itself
This blog post will help.

Xpages - blank fields overwritten with value saved in document if validation fails

Im making an Xpages application which needs to have server-side validation.
In my form, when a field is cleared and the form submitted - if there is another field which causes the validation to fail - it will be repopulated with the last successfully saved value in the document.
This is not what should happen. The field should stay blank until the page is either refreshed, or the user enters another value.
Does anyone have any idea about what is causing this to happen?
Thanks,
Paul
This depends on your execId and refreshId.
For what happens during partial refresh, read these blog posts, particularly part three http://www.intec.co.uk/tag/partial-refresh/.
If validation (or conversion) fails server-side, the server-side map of the XPage is not updated because the data is not deemed complete enough for server-side processing.
So the partial refresh skips to Render Response, which posts back what HTML should be displayed to the page. That includes values in fields - you're replacing HTML, so it has to.
If you're save button is refreshing the form area, you'll be replacing the HTML there, so overwriting the values entered by the user with the last valid values.
The recommended approach will depend on your page architecture and what you're saving. One is to move validation to the save() function, by which time the values will have been updated in the DominoDocument (the front-end wrapper for the Document on the server). Another is to only refresh the validation area and, if validation was successful, call context.reloadPage() or context.redirectToPage() to effectively skip the partial refresh.
Thanks for the help. As far as I can tell, it was simply due to the way the default converter included with xpages handles the object and/or string. Writing a java custom converter sorted everything out.

Binding computed xpage fields to a form field

There is a lot of questions about binding data to forms. This is very simple. I have a form that uses several computed fields that pull data using an #DbLookup to populate the fields based on a pulldown menu the user selects. The problem is; none of the computed fields save any of the values into the form that it is bound to. The only data that saves on the form is the data that is manually selected (in the case of the pulldown menu) or manually entered. When I use an edit box and don't make it "Read Only" the data saves fine. Why is this so difficult?
Mark -
Couple approaches here I think... but let's walk though something.
Read Only on the edit box is preventing the save. It makes sense. XPages should not try to save something marked "read only".
As Steve says, you're better off here with a computed field. Set the values however and if their bound to the document then I think they will save fine.
Another approach is is to work with scoped variables. When you get your data points... you can put that into scoped variables like:
viewScope.put("myField", myValue)
then you're computed field could be bound to the viewScope variable "myValue".
however this will of course not save back to the document as it's not bound to the document. So what you do if you want that approach is in the document save event... you then use SSJS to assign the values to the doc then. something like:
document1.replaceItemValue("myfield", viewScope.get("myField");
Since xpages basically has the same document events as notes client. This may seem familiar to you.
Hope this helps.
Dave -
NotesIn9.com
Disclamer: I'm answering this from a plane after a trip to Las Vegas. So please factor that into the quality of my answer. :)
You will want to put the data you receive from the #DbLookup in an edit box field(s). A computed field is like a "Computed for display" field in traditional Notes development. You can choose whether to allow the user to change the values or not by the read-only property.
Also see this question if you want the values read-only which it sounds like you do: ReadOnly field in Xpage not submitted
As usual, Dave steered me to something that worked. Being in the larval stages of JavaScript experience, I'm sure there is a better way to do this. I'm just happy it works. Her is the code I put into the QuerySave event of my Xpage.
var cost1 = getComponent('ItemCost1').getValue();
var uom1 = getComponent('UOM1').getValue();
var Num1 = getComponent('ItemNum1').getValue();
var tot1 = getComponent('Total1').getValue();
docuent1.replaceItemValue("ItemCost_1", cost1),
document1.replaceItemValue("ItemUOM_1", uom1),
document1.replaceItemValue("ItemNum_1", Num1),
document1.replaceItemValue("CostTotal_1", tot1)
I have 30 iterations of this so it probably works kind of clunky but the operative word is WORKS. If anyone has a better way to get the same results, please post it so I can learn something. Thanks for everyone's help.

Does CakePHP automatically deal with mass assignment vulnerabilities when saving modified data?

Edit:
After receiving more information from DCoder, the phrase I was searching for here is a "mass assignment vulnerability." That is to say, taking advantage of the convenience of methods that would save all valid fields to the database, regardless of their presence on the initial form (making them vulnerable to manipulated POST data containing more [possibly more critical] fields than the intended ones).
The two common responses are then appropriately named whitelisting and blacklisting; whitelisting fields intended for modification, or blacklisting fields that should not be modified.
My question then follows: does CakePHP automatically whitelist only those fields in the submitting form, or is it necessary for me (and other Cake fans) to be careful that we are whitelisting or blacklisting appropriately?
Original Question:
Cake offers a lot of great ways to generate forms and handle them nearly automatically. As I was thinking about security, I got to wondering: is Cake aware of what fields existed in a form submitted, or will it simply accept any valid field? Take the following senario if I'm not making sense (and someone is welcome to edit my question to be better worded if they can think of a better way to express it):
Let's say I allow my users to edit their profile. I create a form which has fields for username, e-mail, and password, under the action edit.
A clever user wants to come in and change their is_admin field from false to true, so they use an app like firebug to submit custom post data to the edit action, which includes the field is_admin set to true.
The question is, would Cake realize on it's own that is_admin was not in the original form, or do I need to be careful to explicitly specify the only fields which fields a given action can modify? Is there an easier way?
Thank you!
James
You have to load the SecurityComponent in your controller(s) and CakePHP will prevent form tampering for you, see http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#form-tampering-prevention
CakePHP has built in validation option available. The Form automatically generate the fields and do validation based on the validation criteria you have mentioned in the model. This validation will be called automatically before the Save method.
Also if you want to add some custom validation, you can add that in the model.
With your specific query you can remove the is_admin field from the edit form so that it won't be editable to the user. If you want to add more security and make sure that the is_admin field has false value you can edit its value in the controllers edit method.
In the edit method you can add the following code before calling the Save action.
$this->request->data['ModelName']['is_admin] = false;

Change markup field tekst during validation

I have a webform with a custom calidator function. in the form is a markup field. How can I change the markup text in my validation hook if there is an error ?
Thanks in advance
I haven't tested this so you will have to test it yourself but...
If validation fails, then the form is typically displayed again with an error message added. In which case, hook_form_alter will be called again after the validation.
Try setting a flag in the $form_state during your validation that you can check in your hook_form_alter to determine whether or not you should change the markup.
Ok When going trough the flow, I found out somehere the variables are not passed as references, so you lose the information, I changed the this too be references, now it works

Resources