-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
139 lines (120 loc) · 4.24 KB
/
Copy pathfirestore.rules
File metadata and controls
139 lines (120 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// ===============================================================
// Assumed Data Model
// ===============================================================
//
// Collection: projects
// Document ID: projectId
// Fields:
// - name: string (required)
// - createdAt: timestamp (required)
// - updatedAt: timestamp
// - scriptRaw: string
// - globalStylePrompt: string
// - styleReferenceId: string
//
// Collection: projects/{projectId}/frames
// Document ID: frameId
// Fields:
// - projectId: string (required)
// - frameNumber: string (required)
// - originalDescription: string
// - narratedText: string
// - visualIntent: string
// - category: string (enum)
// - status: string (enum: pending, selected, generated, skipped)
// - generatedImageUrl: string
// - generationPrompt: string
// - preferred: bool
// - activeGenerationId: string (optional)
//
// Collection: projects/{projectId}/frames/{frameId}/generations
// Document ID: generationId
// Fields:
// - storagePath: string
// - downloadUrl: string
// - createdAt: timestamp
// - generationPrompt: string (optional)
// - quality: string (optional)
//
// Collection: styleReferences
// Document ID: refId
// Fields:
// - name: string (required)
// - stylePrompt: string
// - category: string
// - description: string
// - projectId: string (optional)
//
// Collection: styleReferences/{refId}/images
// Document ID: imageId
// Fields:
// - url: string (required, base64)
// - createdAt: timestamp
//
// ===============================================================
// ===============================================================
// Helper Functions
// ===============================================================
function isAuthenticated() {
return request.auth != null;
}
function isOwner(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
function isAdmin() {
return isAuthenticated() &&
(get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'admin' ||
(request.auth.token.email == "lmazalan@mazalancomunicaciones.com" && request.auth.token.email_verified == true));
}
function isValidProject(data) {
return data.name is string && data.name.size() > 0 && data.name.size() < 200 &&
(!('styleReferenceId' in data) || data.styleReferenceId is string);
}
function isValidFrame(data) {
return data.projectId is string &&
data.frameNumber is string &&
data.status in ['pending', 'selected', 'generated', 'skipped'];
}
function isValidStyleRef(data) {
return data.name is string && data.name.size() > 0 && data.name.size() < 200 &&
(!('stylePrompt' in data) || (data.stylePrompt is string && data.stylePrompt.size() < 5000));
}
function isValidStyleImage(data) {
return data.url is string && data.url.size() < 1048576; // Max Firestore doc size
}
// ===============================================================
// Rules
// ===============================================================
match /users/{userId} {
allow read: if isOwner(userId) || isAdmin();
allow write: if isOwner(userId) || isAdmin();
}
match /styleReferences/{refId} {
allow read, write: if isAuthenticated();
match /images/{imageId} {
allow read, write: if isAuthenticated();
}
}
match /projects/{projectId} {
allow read, write: if isAuthenticated();
match /frames/{frameId} {
allow read, write: if isAuthenticated();
match /chunks/{chunkId} {
allow read, write: if isAuthenticated();
}
match /generations/{generationId} {
allow read, write: if isAuthenticated();
}
}
}
match /activity_logs/{logId} {
allow read, write: if isAuthenticated();
}
match /{path=**} {
allow read, write: if false;
}
}
}