Posts

Showing posts from January 16, 2019

Firestore security rules: How to validate that a field is undefined?

Image
0 When a user signs up and they initialise their data in firestore, I want to validate that they aren't attempting to set their role (i.e. so they're not setting it to 'admin' for example). I tried to write this: match /users/{userId} { allow create: if (signedInAs(userId) && !request.resource.data.role) || isAdmin(); ... ...but I just see "Property role is undefined on object." Is there a way to do this safely? Or does this mean I should always be initialising expected fields, even if it's just to the empty string? That doesn't seem to quite fit with the philosophy of NoSQL? firebase google-cloud-firestore firebase-security-rules share | improve this q

Should Inherit package-private field or create private one in all subclasses?

Image
2 I have trouble to understand the inheritance of some class fields. In case of a field that is in all subclasses, but it's different in all of them, how should I code it? Should I code like this: class Product { private String name; double tax; Product(String name) { this.name = name; } } class CarProduct extends Product { CarProduct(String name) { super(name); this.tax = 0.2; } } class PharmacyProduct extends Product { PharmacyProduct(String name) { super(name); this.tax = 0.05; } } Or like this? Which is more correct? class Product { private String name; Product(String name) { this.name = name; } } class CarProduct extends Product { private double tax; CarProduct(Strin