How to set specific security rule on a nested array inside of an object? - google-cloud-firestore

I there any way to set a specific security rule on an array inside of a nested object in firebase,
I have the following picture and I want to be able to gain control over the length of the nested array
request.resource.data.Object.nestedArr.size() == // some criteria
the issue however is that what if the array has a different name than nestedArr can there be a certain dynamic rule for this ?

Related

Firestore - saving external links in a document with both url and title

How can I create an array in firestore that can save external links?
I want to save the title and the href so that I can use both values in the read.
I want the links attribute to be an array so that I can save multiple links. Is it possible to do that in a single firebase attribute, or should I create separate link attributes with a href and title for each one (ie firstLinkTitle, firstLinkHref)?
It's not possible to have a number of links, that would be a different array - similar to an array of arrays.
The possibility for the creation of a field of type array for your documents, you can either use the console, where this type is available or via code as the following example:
const data = {
stringExample: 'Example',
arrayExample: ['Title', 'href']
};
const res = await db.collection('data').doc('one').set(data);
With the above example, you should be able to create a field of type array and set the data to it.
Besides that, if you want to update data from your array without uploading all the data again, you can use the function arrayUnion() or use the arrayRemove(), to remove elements from it.
You can get more information on how to work with arrays in Firestore, by checking the below documentation.
Add Data
In case you need something like nested arrays, indeed, you will need to have a "child" collection that will be linked to the father one.
Let me know if the information helped you!

Filtering a datasource using multi select wild character

Does anyone know if there is a wildcard character in AppMaker that can be used for all possible values for a field in a query?
I currently have a datasource that is being filtered based on the status using a multi-select widget. What I would like to accomplish is when all values have been de-selected I want to load all the records of that datasource without clearing the entire query in case other filters have been applied. I have it working in-a-sense that I have to explicitly construct my query as such:
widget.datasource.query.filters.Status._in = ['Status Value 1','Status Value 2','Status Value 3']
My current solution is loading the correct data when a value is selected and it correctly shows the union of the query as the values are modified. However, it selects all of the values in my multi-select; which I know is how it is supposed to work.
I tried using widget.datasource.query.filters.Status._contains = ''; and changing the assignment value to no avail. I even tried the opposite approach using _notContains
The intended outcome is to have a filtering dashboard appear much like any website where when no filtering is selected all records are displayed. I was hoping to find a wildcard character that would load all of the records. Just trying to find a way to mimic other website filters with all records when none are selected.
Thanks for the time!
So the easiest solution here is to set up your Multiselect as follows:
Options binding:
#models.YourModel.fields.Status.possibleValues
or if you don't have the possible Status values in your model then set your options binding to:
['Status Value 1','Status Value 2','Status Value 3']
Values binding:
#datasource.query.filters.Status._in
Now anytime you select any choices in the multiselect, the query will only include records that include the selected choices. And if you deselect all choices the query will ignore that filter or treat it as an empty array of values, therefore returning all records unless you applied other filters.

Validating arrays using Firestore rules

In my HTML page I have a group of five checkboxes. Their values are 1,2,3,4,5.
In the object to which those checkboxes belong I save them as an array. So if user selects options 2,4,5 I store it as [2,4,5].
I'm stuck at the spot when I try to validate that array in Firebase rules. Is there any way of doing validation like this?
I want to make sure an array like [5,6,7] does not go through the Firestore rules but something like [1,3,4,5] does.
Array type fields in Firestore documents show up as List type objects in security rules. You can use its hasOnly method to determine if the List contains only certain elements.
request.resource.data.arrayField.hasOnly([1,2,3,4,5)

Modify / Update element in ArrayList in working memory in rule Drools

We are working on a rule that is structured as follows:
We have a list that contains validated and non-validated elements. The difference between validated and non-validated is done by giving a different status to the elements.
We obtain the non-validated elements from the list.
Each non-validated element is compared to the validated elements in the same list.
After comparison a non-validated element would become a validated element that needs to be considered when validating the non-validated elements.
The problem arises when we want to update the original ArrayList of elements. We need to be able to update the non-validated element that has just become validated in its original ArrayList in the working memory so the loop can take the "refreshed" ArrayList into account.
Three questions:
First of all, what is the exact difference between using modify and update in Drools. According to Drools documentation:
"On the right hand side of a rule the modifystatement is recommended,
as it makes the changes and notifies the engine in a single
statement."
So the difference between one and other would be just simple semantics like:
modify( $sprinkler ) { setOn( true ) };
and
$sprinkler.setOn(true);
update($sprinkler);
Is this assumption correct?
Secondly, is it possible to update or modify a specific element within the ArrayList in the working memory in Drools without using a plain Java iterator (a "for"). In our case each element is identified with a unique ID we obtain from the list so we will have a valid reference for updating its status (validated or non-validated).
Finally, we are aware that updating the working memory would cause the rule to fire again. Let's say we have an ArrayList with two non-validated items. If we were to obtain all non-validated items to validate them, I would create a rule "first" that fires twice, for each non-validated item once:
rule "first"
when
$listOfElements : java.util.ArrayList ( )
$itemsToValidate : Element ( status == "not validated" ) from $listOfElements
then
//do something or not
end
If in a second rule I would validate certain items and wish to change the status of the non-validated element to validated in the working memory like this:
rule "second" extends "first"
when
//we validate attributes of the non-validated element against attributes of the validated elements
then
//my second question is if something like this is actually possible (solution without Java iterator)
$itemsToValidate.setStatus("validated")
modify ($listOfElements) { $itemsToValidate };
end
How would this affect the whole process? The actualisation of the working memory will provoke the first rule to be reevaluated. This rule would already be launched twice because we had encountered two non-validated elements. Will the remaining element be evaluated only once or more than once?
The answer to your first question is that there is no difference between the two snippets. (Statements inserted between the two of the second one would influence my answer.)
The scenario for the second question doesn't use an update in the same form. Inserting a List as a fact but operating on list elements is usually considered as bad. Insert the list elements. The container may or may not be useful as a container holding the list elements to one transaction or whatever.

Filtering a list lookup in Nintex Forms using an inline function

I am building a list form for SharePoint 2010 using Nintex Forms 2010.
The user must select an item from a different list, so I have added a List Lookup control. But the user can only select among items that starts with a specific string.
For example, the lookup list could contain items with titles 'foo1','foo2','bar1','bar2'. I only want the user to be able to select 'foo1' or 'foo2'.
In the filtering section of the List Lookup control I have specified the following:
Filter available selections = By a specific value
Where field = fn-Substring("Title",0,3)
Filtered by value = foo
Unfortunately this does not result in any options for the user to select - just an empty control.
If I change the filter to:
Where feild = Title
Filtered by value = foo1
Then I get the foo1 option - and only that one. Trying something like
Filtered by value = foo*
does not work either.
So how should I define the filter to get it to work. Or is what I am trying not possible in Nintex Forms?
The inline function won't work in your case, because it is a client side function, and your parameter is a server side object.
There two alternative ways can help with your request in server side.
1.Add a calculated value column to your list, use LEFT function to cut the search key for yourself:LEFT([Title],3). In nintex form, you can use this column to filter the list items.
Filter the list items in a view instead of nintex form. Suppose you have already known the [source view] property in List Lookup control.