I set the constraint of one of my tetfields to DECIMAL, the problem is that VBK shows other unnecessary characters such as: & # - " ' etc
because it's impossible to remove VBK in touch devices i decided to check the string for these characters:
if (txtCAmount.getText().indexOf("#")==-1 && txtCAmount.getText().indexOf("&")==-1 &&
txtCAmount.getText().indexOf("$")==-1 && txtCAmount.getText().indexOf(";")==-1 &&
txtCAmount.getText().indexOf("(")==-1 && txtCAmount.getText().indexOf(")")==-1 &&
txtCAmount.getText().indexOf("/")==-1 && txtCAmount.getText().indexOf(":")==-1 &&
txtCAmount.getText().indexOf("-")==-1 && txtCAmount.getText().indexOf(",")==-1 &&
txtCAmount.getText().indexOf("!")==-1 && txtCAmount.getText().indexOf("?")==-1 &&
txtCAmount.getText().indexOf("'")==-1 && txtCAmount.getText().indexOf('"')==-1)
But the last problem is . because user can enter as many as dots he wants.
I recently saw in the docs that you can use a bitwise OR for textfield constraints, so you can better tailor the out come, also setting the input order and mode may be of help.
Related
I've looked around for a while for an answer but no one has one and everyone keeps saying it's how it's supposed to work.
I need to render an & (ampersand) as plain javascript code. Not as a string.
if (#(Model.Month == null ? "now.getMonth() == tooltipItems[0].index" : "now.getMonth() == tooltipItems[0].index && now.getDay() == tooltipItems[0].index") && now.getFullYear() == $('#DistinctYears').val()) {
//
} else {
//
}
I need this section:
"now.getMonth() == tooltipItems[0].index && now.getDay() == tooltipItems[0].index"
To render as plain javascript code but when it renders, the ampersands automatically get converted to &&
Surround the entire ternary expression with Html.Raw():
#Html.Raw(Model.Month == null ? "now.getMonth() == tooltipItems[0].index" : "now.getMonth() == " + (Model.Month - 1) + " && now.getDate() == (tooltipItems[0].index + 1)")
This article stated that "[writeFields] is now deprecated".
Additionally, I cannot find any documentation for writeFields, it is not even listed as part of Request in the documentation anymore.
Problem
The problem I am facing with Cloud Firestore Security Rules is that verifying that only particular fields are modified requires massive amounts of conditions.
For example, if I want to verify that the only modified value of a document is cakes, I have to write the following rule:
allow update: if request.resource.data.size() == 20
&& request.resource.data.likes == resource.data.likes
&& request.resource.data.name == resource.data.name
&& request.resource.data.date == resource.data.date
&& request.resource.data.body == resource.data.body
&& request.resource.data.title == resource.data.title
&& request.resource.data.tags == resource.data.tags
&& request.resource.data.comments == resource.data.comments
&& request.resource.data.answers == resource.data.answers
&& request.resource.data.awards == resource.data.awards
&& request.resource.data.image == resource.data.image
&& request.resource.data.link == resource.data.link
&& request.resource.data.format == resource.data.format
&& request.resource.data.type == resource.data.type
&& request.resource.data.user == resource.data.user
&& request.resource.data.views == resource.data.views
&& request.resource.data.reports == resource.data.reports
&& request.resource.data.roles == resource.data.roles
&& request.resource.data.category == resource.data.category
&& request.resource.data.votes == resource.data.votes
&& request.resource.data.cakes is int;
Using writeFields, the exact same rule would have looked like this:
allow update: if request.writeFields.hasOnly(['cakes']) && request.resource.data.cakes is int;
What can I do to decrease the code size of my rules / what is the alternative to writeFields?
Limits
There are two limits mentioned in the documentation that make this problem even worse:
Maximum number of expressions evaluated per request: 1,000
Maximum size of a ruleset: 64 KB
I expect to reach both of these at some point with this limitation.
Yes! There is now a replacement called "Map Diffs". Check this syntax out:
allow update: if request.resource.data.diff(resource.data).affectedKeys().hasOnly(['cakes'])
&& request.resource.data.cakes is int;
Unfortunately, what you're doing right now is currently your best option.
The Firebase rules team is working on a language improvement to make it easier to compare/diff map type objects, which will drastically cut down on the number of expressions it takes to do this sort of thing, but there is no timeline for that right now. Please stay tuned.
I end up writing these helper function:
// returns true if all the fields changed are contained in the array parameter
function onlyAllowedFields(fieldsArray) {
return fieldsArray.toSet().hasAll(request.resource.data.diff(resource.data).affectedKeys());
}
// returns true if none of the fields are changed
function noneOfDisallowedFields(fieldsArray) {
return request.resource.data.diff(resource.data).affectedKeys().hasAny(fieldsArray.toSet()) == false
}
I found more helpful this way instead of using hasOnly() that would require that all fields that could be changed must have been changed.
I have these Firestore Security Rules. I need to check if the 3 amounts "redAmount", "greenAmount" and "blackAmount" added together exceed the user's balance. If so, the update should be rejected.
function checkSums() {
return futureDocument().redAmount + futureDocument().blackAmount +
futureDocument().blackAmount <= getUserDoc().amount;
}
But this functions fails if one of the amounts is undefined => not set, which I want to be 0, but I can't. Any ideas on how to fix this?
This problem is not solved by referencing to the "How to validate that a field is undefined" question.
Fixed this with a really insane long workaround (instead of using functions, use or's)
return checkMinusAmount('redAmount') && checkMinusAmount('blackAmount')
&& checkMinusAmount('greenAmount') && (
(futureDocument().redAmount + futureDocument().blackAmount + futureDocument().greenAmount <= getUserDoc().amount)
(futureDocument().redAmount + futureDocument().blackAmount <= getUserDoc().amount !has('greenAmount'))
(futureDocument().redAmount + futureDocument().greenAmount <= getUserDoc().amount !has('blackAmount'))
(futureDocument().greenAmount + futureDocument().blackAmount <= getUserDoc().amount !has('redAmount'))
(futureDocument().greenAmount <= getUserDoc().amount (!has('redAmount') && !has('blackAmount')))
(futureDocument().blackAmount <= getUserDoc().amount (!has('redAmount') && !has('greenAmount')))
(futureDocument().redAmount <= getUserDoc().amount (!has('blackAmount') && !has('greenAmount')))
)
}
I ended up not using it and just creating the document with a cloud function and not giving an user the rights to delete it.
I'm having a bit of trouble trying to find if my url parameters exist or not.
I have tried the following:
// doesn't work
(Request.QueryString["showTop"] != "" && Request.QueryString["showTop"] != null)
// doesn't work
(Request.Params["showTop"] != "" && Request.Params["showTop"] != null)
I am trying to find the correct value. The full statement looks like:
showTop = (Request.QueryString["showTop"] != "" &&
Request.QueryString["showTop"] != null) ?
Request.QueryString["showTop"] : (10).ToString();
Which works fine, if showTop exists with a value.
This is being done within the view.
Try the following:
showTop = string.IsNullOrEmpty(Request["showTop"]) ? "10" : Request["showTop"];
Assuming you want "showTop"to default to "10".
First check whether QueryString has keys or not by calling this method.
bool qKeys = Request.QueryString.HasKeys();
I have a page with filters and accordingly to what the user selects, it has to generate a query. I'm using this code:
var riskitem = (from risk in context.RisksList
where risk.ProjectCode == sProjectCode &&
(
(search == "" && status == "" && ispublic == TriState.NA) ||
(search != "" && (
(!String.IsNullOrEmpty(risk.Description) && risk.Description.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0) ||
(!String.IsNullOrEmpty(risk.Title) && risk.Title.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0) ||
(risk.Probability.HasValue && risk.Probability.Value.ToString().IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0) ||
(!String.IsNullOrEmpty(risk.Mitigation) && risk.Mitigation.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0) ||
(!String.IsNullOrEmpty(risk.Observations) && risk.Observations.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0)
)) ||
(
(status != "" && risk.Status.Value.ToString() == status) ||
(status == "" && search != "" && risk.Status.Value.ToString().IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0)
) ||
(
(ispublic != TriState.NA && ((risk.IsPublic.Value && ispublic == TriState.True) || (!risk.IsPublic.Value && ispublic == TriState.False))) ||
(ispublic == TriState.NA && search != "" && risk.IsPublic.HasValue && risk.IsPublic.Value.ToString().IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0)
)
)
select risk).Take((pagesize * (pageindex + 1)) + 1);
However Linq-To-Sharepoint doesn't convert most of this to CAML and the list I'm querying has more than 50000 items. It takes about 4-8 seconds to retrieve the items which is not acceptable.
I've been trying to generate a dynamic query but so far I haven't been able to get it to work.
With AND and OR operations to generate the query I could put all those conditions on code and increase performance.
If someone could help I would be appreciated.
I've scrapped using linq to sharepoint for large lists with complex predicate filters. I've had far better performance using unions and/or merging the data from the splistitemcollection results of an SPQuery results.
It looks as though you are duplicating the work of the sharepoint search engine, have you considered if it is possible to replace with something like the keyword or fulltext query classes?
Also, you should be able to eliminate the need to do duplicate evaluation such as checking for empty string AND indexof. i.e... just simply something like
Risk.IsPublic.Value.ToString().IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1
What is the datatype for IsPublic ? If this is a boolean field you can save yourself some time as well without having to additional conversions.