A user should only be created if he has the correct children with correct initial values.
The following code works but it prevents me to change the values like health after the user was created.
How can I check only for the initial child values?
{
"rules": {
".read": true,
".write": false,
"users": {
// Only allow writes in users
".write": true,
"$user": {
// Check if new user has the correct children
".validate": "newData.hasChildren(['userID', 'deviceModel', 'health', 'age', 'playername', 'score', 'clickedby', 'timestamp'])
// Check if new user has a health of 10
&& newData.child('health').val() == '10'
// Check if new user has an age of 0
&& newData.child('age').val() == '0'
// Check if new user has a score of 0
&& newData.child('score').val() == '0'
// Check if new user has a timestamp which is not a future value
&& newData.child('timestamp').val() <= now"
}
}
}
}
Update: The rules of Frank van Puffelen work perfectly
Here are my updated rules:
{
"rules": {
".read": true,
".write": false,
"users": {
// Only allow writes in users
".write": true,
"$user": {
// Check if new user has the correct children
".validate": "data.exists() || (
newData.hasChildren(['userID', 'deviceModel', 'health', 'age', 'playername', 'score', 'clickedby', 'timestamp'])
// Check if new user has a health of 10
&& newData.child('health').val() == 10
// Check if new user has an age of 0
&& newData.child('age').val() == 0
// Check if new user has a score of 0
&& newData.child('score').val() == 0
// Check if new user has a timestamp which is not a future value
&& newData.child('timestamp').val() <= now) "
}
}
}
}
If you only want to check for new data, you can use data.exist(). For example:
".validate": "data.exists() || (
newData.hasChildren(['userID', 'deviceModel', 'health', 'age', 'playername', 'score', 'clickedby', 'timestamp'])
// Check if new user has a health of 10
&& newData.child('health').val() == '10'
// Check if new user has an age of 0
&& newData.child('age').val() == '0'
// Check if new user has a score of 0
&& newData.child('score').val() == '0'
// Check if new user has a timestamp which is not a future value
&& newData.child('timestamp').val() <= now
)"
Unrelated: I'd consider storing numeric values in numbers, instead of in string values as you do now. So that'd be newData.child('health').val() == 10, etc.
Btw: kudos on writing such beautiful security rules early on in development. 👍
Related
I have created a function to audit all Chats that were entered using WebApp. WebApp is created using ASP.Net MVC.
The functions works great, and does present a random Chat entered in WebApp last week.
However, the issue I can see is that if an Auditor opens a Chat, but by refreshing the page the previous Chat Audit gets replaced with a new One.
How can I ensure Auditor refreshing or doing any action the same Chat Audit Form stays or gets presented to auditor, and he cannot proceed unless he completes the Audit.
This is my Action Created
public ActionResult Feedback()
{
var mostRecentMonday = DateTime.Now.AddDays(-7).StartOfWeek(DayOfWeek.Monday);
var weekEnd = mostRecentMonday.AddDays(7).AddSeconds(-1); //will return the end of the day on Sunday
using (Db db = new Db())
{
var uName = User.Identity.Name;
//int total = db.Chats.Where(x => x.ChatCreateDateTime >= mostRecentMonday && x.ChatCreateDateTime <= weekEnd && x.Feedback == null).ToArray().ToList().Count();
var result = db.Chats.Where(x => x.ChatCreateDateTime >= mostRecentMonday && x.ChatCreateDateTime <= weekEnd && x.Feedback == null && x.Username != uName).OrderBy(x => Guid.NewGuid()).FirstOrDefault();
result.Scenarios = new SelectList(db.Scenarios.ToList(), "ScenarioId", "ScenarioList");
return View(result);
}
}
Help is very much appreciated
I have the following code and trying to implement a bad word filtering system but the break is not executing. I thought that break means to stop executing further if statements but it is still progressing through to adding the information to the database..
for (int i = 0; i < badWords.size(); i++) {
String badWord = badWords.get(i);
if (txt_name.toLowerCase().contains(badWord) || txt_address.toLowerCase().contains(badWord) || txt_suburb.toLowerCase().contains(badWord) || txt_state.toLowerCase().contains(badWord) || postcode2.toLowerCase().contains(badWord) || txt_doctor.toLowerCase().contains(badWord)) {
// txt_review = txt_review.replace(badWord, "*****");
Toast.makeText(MainActivity.this, "Make sure that it does not contain any rude words", Toast.LENGTH_SHORT).show();
break;
} else if (clinic_name.equals(txt_name) || clinic_name2.equals(txt_name)) {
Toast.makeText(MainActivity.this, "Medical Clinic already exists in the database!", Toast.LENGTH_SHORT).show();
break;
} else if (txt_name.isEmpty() || txt_address.isEmpty() || phone.isEmpty() || txt_suburb.isEmpty() || txt_state.isEmpty() || postcode2.isEmpty() || txt_doctor.isEmpty()) {
Toast.makeText(MainActivity.this, "Make sure you have completed all fields and also make sure they are bulk billing clinics!!", Toast.LENGTH_SHORT).show();
break;
} else {
You can try to run this code in a function and use return instead of break.
Currently I have been tasked with reviewing a BPM created by Epicor that is not functioning as expected. Currently with the BPM based on the code below its purpose is to reference orders in the system and when its time to ship the orders if there is a price change the order/part will reflect a new price. It seems that the code is causing incorrect price lists to be retrieved from customers not expected. For example a price list is attached to customer #1242 but its updating the price based on customer #1269. (Guessing they share a common part # and the code retrieves the latest value)
Now my problem is I don't have experience in writing code, I have reviewed code before but to a small extent and from what I listed above that was provided to me. Now what I thought may be an easier practice for me to understand is create a BAQ and reference that in the BPM and utilize the BAQ as a reference for the BPM to update prices.
With researching a few forums and Epicors training material I haven't found a definitive answer on how to link a BAQ in a BPM.
(Also if my description makes sense and the code reflects the issue feel free take a guess)
BPM Code:
var ttShipHead_xRow = (from ttShipHead_Row in ttShipHead
where ttShipHead_Row.ReadyToInvoice == true
select ttShipHead_Row).FirstOrDefault();
if (ttShipHead_xRow != null)
{
foreach (var ShipDtl_iterator in (from ShipDtl_Row in Db.ShipDtl
where ttShipHead_xRow.PackNum == ShipDtl_Row.PackNum
&& ttShipHead_xRow.Company == ShipDtl_Row.Company
select ShipDtl_Row))
{
var ShipDtl_xRow = ShipDtl_iterator;
//ShipDtl_xRow.UnitPrice = 1;
var today = DateTime.Today;
var PriceList_xRow = (from PriceLst_Row in Db.PriceLst
from PriceLstParts_Row in Db.PriceLstParts
where ShipDtl_xRow.PartNum == PriceLstParts_Row.PartNum
&& PriceLst_Row.ListCode == PriceLstParts_Row.ListCode
&& PriceLst_Row.Company == PriceLstParts_Row.Company
&& PriceLst_Row.Company == ShipDtl_xRow.Company
&& PriceLst_Row.EndDate >= today
select PriceLstParts_Row).FirstOrDefault();
if (PriceList_xRow != null)
{
var OrderDtl_xRow = (from OrderDtl_Row in Db.OrderDtl
where ShipDtl_xRow.OrderLine == OrderDtl_Row.OrderLine
&& ShipDtl_xRow.PartNum == OrderDtl_Row.PartNum
&& ShipDtl_xRow.OrderNum == OrderDtl_Row.OrderNum
&& ShipDtl_xRow.Company == OrderDtl_Row.Company
select OrderDtl_Row).FirstOrDefault();
{
if (OrderDtl_xRow != null)
{
if (ShipDtl_xRow.UnitPrice != PriceList_xRow.BasePrice)
{
ShipDtl_xRow.UnitPrice = PriceList_xRow.BasePrice;
}
if (ShipDtl_xRow.UnitPrice != OrderDtl_xRow.UnitPrice)
{
OrderDtl_xRow.DocUnitPrice = PriceList_xRow.BasePrice;
OrderDtl_xRow.UnitPrice = PriceList_xRow.BasePrice;
}
}
}
}
}
}
I resolved the code but still could not determine a valid method to link a BAQ in the BPM
The problem was the following code was missing:
&& ttShipHead_xRow.CustNum == ShipDtl_Row. CustNum
to the first foreach statement.
I need to create a findAll criteria in Grails, but I have 4 fields to search. I just need to search by those fields if a specific variable is not null.
For example, if all variables are not null, I'll search by all the fields like the following:
list = MyObject.findAll {
'in'("job", jobList)
'in'("businessUnit", businessUnitList)
'in'("company", companyList)
eq("regularTime", params.regularTime)
}
What I want to do is something like this:
regularTimeList = RegularTime.findAll {
if(params.job != null) 'in'("job", jobList)
if(params.businessUnit != null) 'in'("businessUnit", businessUnitList)
if(params.company != null) 'in'("company", companyList)
if(params.regularTime != null) eq("regularTime", params.domainClassSearchFilters.regularTime)
}
It's not working so I'd like to know if there is a way to do that because right now I had to create a lot of ifs to verify them... I need one if to each scenario... Like:
If job is not null and company is not null, one findAll. If company is not null and regularTime is not null, another findAll.
You can do something like this:
regularTimeList = RegularTime.findAll {
if (params.job != null) params.job in jobList
if (params.businessUnit != null) params.businessUnit in businessUnitList
if (params.company != null) params.company in companyList
if (params.regularTime != null) regularTime == params.domainClass
}
I don't know what happened, but the way Above didn't work for me...
I solved it using criteria.
list= MyObject.createCriteria().list {
if(params.job != null && "" != params.domainClassSearchFilters.job )
'in'("job", jobList)
if(params.businessUnit != null && "" != params.businessUnit)
'in'("businessUnit", businessUnitList)
if(params.company != null && "" != params.company)
'in'("company", companyList)
if(params.regularTime != null && "" != params.regularTime && params.regularTime.isDouble())
eq("regularTime", Double.parseDouble(params.regularTime))
}
I need to go through a series of steps one by one. In all, I have three steps to go through which are inside of a while loop. Once the three tests are completed, then and only then should the user be exited from the while loop. The catch is that these steps need to be done sequentially, and require the user to do each test in order, if they pass, then move on to the next step.
Here is the relevant code:
int passCount = 0;
BOOL flatPass = FALSE;
BOOL landscapePass = FALSE;
BOOL portraitPass = FALSE;
while (passCount < 3) {
if (flatPass == FALSE) {
if (device.orientation == UIDeviceOrientationFaceUp || device.orientation == UIDeviceOrientationFaceDown) {
[self pushSound];
}
}
else if (landscapePass == FALSE) {
if (device.orientation == UIDeviceOrientationLandscapeLeft || device.orientation == UIDeviceOrientationLandscapeRight) {
[self pushSound];
}
}
else if (portraitPass == FALSE) {
if (device.orientation == UIDeviceOrientationPortrait || device.orientation == UIDeviceOrientationPortraitUpsideDown) {
[self pushSound];
}
}
}
I need the user to position the iOS device in each position, and a beep sound is played to indicate a successful test. Once ALL of the three tests have been completed in order, I want the user to be exited from the loop. I figure each time a test has been cleared, I would increment the passCount counter by 1, until we reach 3 which would exit me from the loop. My issue though is how to go through each test, and in order.
Assuming this isn't running on the main UI thread, remove the while loop, replace each if and else if with a while condition, set the appropriate boolean flags to true when a test passes and you're done.
You could implement that in
deviceDidRotate()
you need a object variable for saving the current progress, or you use an enum like you have done:
int step;
then in deviceDidRotate you check:
if (step == 0 && device.orientation == UIDeviceOrientationFaceUp ) {
step = 1;
} else if (step == 1 && device.orientation == UIDeviceOrientationLandscapeLeft) {
step = 2;
} else if (step == 2 && device.orientation == UIDeviceOrientationPortrait ) {
// successful!
// now do action, reset step? call method
}