mirror of
https://github.com/bleackstorm/satiea.git
synced 2026-12-03 07:41:56 +01:00
build: initialize project structure
Set up Android project configuration, Gradle build scripts, typography, and default resource assets.
This commit is contained in:
1 parent
0a595f619a
commit
f13d46f778
65 files changed
+6056
-11
No files matched your search
+109
@@ -0,0 +1,109 @@
|
||||
rules_version = '2';
|
||||
service cloud.firestore {
|
||||
match /databases/{database}/documents {
|
||||
|
||||
// Default deny all access
|
||||
match /{document=**} {
|
||||
allow read, write: if false;
|
||||
}
|
||||
|
||||
function isSignedIn() {
|
||||
return request.auth != null;
|
||||
}
|
||||
|
||||
function isOwner(userId) {
|
||||
return isSignedIn() && request.auth.uid == userId;
|
||||
}
|
||||
|
||||
function incoming() {
|
||||
return request.resource.data;
|
||||
}
|
||||
|
||||
function existing() {
|
||||
return resource.data;
|
||||
}
|
||||
|
||||
function isValidId(id) {
|
||||
return id is string && id.size() >= 1 && id.size() <= 128 && id.matches('^[a-zA-Z0-9_\\-]+$');
|
||||
}
|
||||
|
||||
function isValidMealEntry(data) {
|
||||
return data.userId is string &&
|
||||
data.userId == request.auth.uid &&
|
||||
data.mealType in ['BREAKFAST', 'LUNCH', 'SNACK', 'DINNER'] &&
|
||||
data.mealTimestamp is int && data.mealTimestamp > 0 &&
|
||||
data.hungerBefore is int && data.hungerBefore >= 1 && data.hungerBefore <= 10 &&
|
||||
data.satietyAfter is int && data.satietyAfter >= 1 && data.satietyAfter <= 10 &&
|
||||
(!('note' in data) || data.note == null || (data.note is string && data.note.size() <= 1000)) &&
|
||||
(!('foodItemsSerialized' in data) || data.foodItemsSerialized == null || (data.foodItemsSerialized is list && data.foodItemsSerialized.size() <= 30 && (data.foodItemsSerialized.size() == 0 || data.foodItemsSerialized[0] is string))) &&
|
||||
(!('photosBase64' in data) || data.photosBase64 == null || (data.photosBase64 is list && data.photosBase64.size() <= 6 && (data.photosBase64.size() == 0 || data.photosBase64[0] is string))) &&
|
||||
(!('updatedAt' in data) || data.updatedAt == null || (data.updatedAt is timestamp && data.updatedAt <= request.time));
|
||||
}
|
||||
|
||||
function isValidCustomFood(data) {
|
||||
return data.userId is string &&
|
||||
data.userId == request.auth.uid &&
|
||||
data.name is string && data.name.size() >= 1 && data.name.size() <= 100 &&
|
||||
data.defaultUnit in ['g', 'ml', 'portion'] &&
|
||||
(!('updatedAt' in data) || data.updatedAt == null || (data.updatedAt is timestamp && data.updatedAt <= request.time));
|
||||
}
|
||||
|
||||
match /users/{userId} {
|
||||
allow get: if isOwner(userId);
|
||||
|
||||
match /meals/{mealId} {
|
||||
allow get, list: if isOwner(userId);
|
||||
|
||||
allow create: if isOwner(userId) &&
|
||||
isValidId(mealId) &&
|
||||
incoming().keys().hasAll(['userId', 'mealType', 'mealTimestamp', 'hungerBefore', 'satietyAfter', 'createdAt']) &&
|
||||
incoming().keys().hasOnly(['userId', 'mealType', 'mealTimestamp', 'hungerBefore', 'satietyAfter', 'note', 'foodItemsSerialized', 'photosBase64', 'createdAt', 'updatedAt']) &&
|
||||
incoming().createdAt is timestamp &&
|
||||
incoming().createdAt <= request.time &&
|
||||
isValidMealEntry(incoming());
|
||||
|
||||
allow update: if isOwner(userId) &&
|
||||
isValidId(mealId) &&
|
||||
incoming().userId == existing().userId &&
|
||||
incoming().createdAt == existing().createdAt &&
|
||||
isValidMealEntry(incoming()) &&
|
||||
incoming().diff(existing()).affectedKeys().hasOnly(['mealType', 'mealTimestamp', 'hungerBefore', 'satietyAfter', 'note', 'foodItemsSerialized', 'photosBase64', 'updatedAt']);
|
||||
|
||||
allow delete: if isOwner(userId) && isValidId(mealId);
|
||||
}
|
||||
|
||||
match /custom_foods/{foodId} {
|
||||
allow get, list: if isOwner(userId);
|
||||
|
||||
allow create: if isOwner(userId) &&
|
||||
isValidId(foodId) &&
|
||||
incoming().keys().hasAll(['userId', 'name', 'defaultUnit', 'createdAt']) &&
|
||||
incoming().keys().hasOnly(['userId', 'name', 'defaultUnit', 'createdAt', 'updatedAt']) &&
|
||||
incoming().createdAt is timestamp &&
|
||||
incoming().createdAt <= request.time &&
|
||||
isValidCustomFood(incoming());
|
||||
|
||||
allow update: if isOwner(userId) &&
|
||||
isValidId(foodId) &&
|
||||
incoming().userId == existing().userId &&
|
||||
incoming().createdAt == existing().createdAt &&
|
||||
isValidCustomFood(incoming()) &&
|
||||
incoming().diff(existing()).affectedKeys().hasOnly(['name', 'defaultUnit', 'updatedAt']);
|
||||
|
||||
allow delete: if isOwner(userId) && isValidId(foodId);
|
||||
}
|
||||
|
||||
match /settings/{settingId} {
|
||||
allow get, list: if isOwner(userId);
|
||||
|
||||
allow create, update: if isOwner(userId) &&
|
||||
isValidId(settingId) &&
|
||||
incoming().userId == request.auth.uid &&
|
||||
incoming().themeMode in ['DARK', 'LIGHT', 'SYSTEM'] &&
|
||||
(!('updatedAt' in incoming()) || incoming().updatedAt is timestamp);
|
||||
|
||||
allow delete: if isOwner(userId) && isValidId(settingId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user