FireVis

Service & Functions
"text-accent font-medium"</span>>rules_version = '2';
"text-accent font-medium"</span>>service cloud.firestore {
match /databases/
"text-accent font-medium"</span>>match /databases/{database}
Service & Functions
/documents {

"text-muted-foreground"</span>>// Global variable for app ID from the "text-accent font-medium"</span>>path.
"text-accent font-medium"</span>>function getAppId("text-accent font-medium"</span>>path) {
"text-accent font-medium"</span>>return "text-accent font-medium"</span>>path[1]; "text-muted-foreground"</span>>// Extracts from /artifacts/{appId}</span>
}

"text-muted-foreground"</span>>// --- User Profiles (artifacts/{appId}/public/data/users/{userId}) ---
match /artifacts/
"text-accent font-medium"</span>>match /artifacts/{appId}
Service & Functions
/public/data/users/{userId} {
"text-muted-foreground"</span>>// Allow "text-primary font-semibold"</span>>read: access to all user profiles "text-accent font-medium"</span>>if authenticated</span>
"text-accent font-medium"</span>>allow "text-primary font-semibold"</span>>read:: "text-accent font-medium"</span>>if "text-accent font-medium"</span>>request.auth != "text-accent font-medium"</span>>null;

"text-muted-foreground"</span>>// Allow a user to "text-primary font-semibold"</span>>create:/class="text-primary font-semibold"</span>>update: their OWN profile IF authenticated</span>
"text-muted-foreground"</span>>// This allows new anonymous users to "text-primary font-semibold"</span>>create: their profile and existing users to "text-primary font-semibold"</span>>update: their username.</span>
"text-accent font-medium"</span>>allow "text-primary font-semibold"</span>>write:: "text-accent font-medium"</span>>if "text-accent font-medium"</span>>request.auth != "text-accent font-medium"</span>>null && "text-accent font-medium"</span>>request.auth.uid == userId;
}

"text-muted-foreground"</span>>// --- Public Chat Messages (artifacts/{appId}/public/data/public_chat_messages/{messageId}) ---
match /artifacts/
"text-accent font-medium"</span>>match /artifacts/{appId}
Service & Functions
/public/data/public_chat_messages/{messageId} {
"text-muted-foreground"</span>>// Allow authenticated users to "text-primary font-semibold"</span>>read: and "text-primary font-semibold"</span>>create: public messages</span>
"text-accent font-medium"</span>>allow "text-primary font-semibold"</span>>read:, "text-primary font-semibold"</span>>create:: "text-accent font-medium"</span>>if "text-accent font-medium"</span>>request.auth != "text-accent font-medium"</span>>null;
"text-muted-foreground"</span>>// Deny updates or deletes to public messages for simplicity</span>
"text-accent font-medium"</span>>allow "text-primary font-semibold"</span>>update:, "text-primary font-semibold"</span>>delete:: "text-accent font-medium"</span>>if "text-accent font-medium"</span>>false;
}

"text-muted-foreground"</span>>// --- Private Chat Rooms (artifacts/{appId}/public/data/chat_rooms/{chatRoomId}) ---
match /artifacts/
"text-accent font-medium"</span>>match /artifacts/{appId}
Service & Functions
/public/data/chat_rooms/{chatRoomId} {
"text-muted-foreground"</span>>// Allow creation of a chat room "text-accent font-medium"</span>>if the user is authenticated and is one of the participants</span>
"text-accent font-medium"</span>>allow "text-primary font-semibold"</span>>create:: "text-accent font-medium"</span>>if "text-accent font-medium"</span>>request.auth != "text-accent font-medium"</span>>null && "text-accent font-medium"</span>>request.auth.uid "text-accent font-medium"</span>>in "text-accent font-medium"</span>>request.class="text-accent font-medium"</span>>resource.data.participants;
"text-muted-foreground"</span>>// Allow "text-primary font-semibold"</span>>read:/class="text-primary font-semibold"</span>>update: to a chat room "text-accent font-medium"</span>>if the user is authenticated and is a participant</span>
"text-accent font-medium"</span>>allow "text-primary font-semibold"</span>>read:, "text-primary font-semibold"</span>>update:: "text-accent font-medium"</span>>if "text-accent font-medium"</span>>request.auth != "text-accent font-medium"</span>>null && "text-accent font-medium"</span>>request.auth.uid "text-accent font-medium"</span>>in "text-accent font-medium"</span>>resource.data.participants;
"text-muted-foreground"</span>>// Deny deletion for simplicity</span>
"text-accent font-medium"</span>>allow "text-primary font-semibold"</span>>delete:: "text-accent font-medium"</span>>if "text-accent font-medium"</span>>false;
}

"text-muted-foreground"</span>>// --- Private Chat Messages (artifacts/{appId}/public/data/chat_messages/{chatRoomId}/messages/{messageId}) ---
match /artifacts/
"text-accent font-medium"</span>>match /artifacts/{appId}
Service & Functions
/public/data/chat_messages/{chatRoomId}/messages/{messageId} {
"text-muted-foreground"</span>>// Allow "text-primary font-semibold"</span>>read:/class="text-primary font-semibold"</span>>write: for messages ONLY "text-accent font-medium"</span>>if the user is authenticated AND a participant of that specific chatRoomId</span>
"text-accent font-medium"</span>>allow "text-primary font-semibold"</span>>read:, "text-primary font-semibold"</span>>write:: "text-accent font-medium"</span>>if "text-accent font-medium"</span>>request.auth != "text-accent font-medium"</span>>null
&& "text-accent font-medium"</span>>request.auth.uid "text-accent font-medium"</span>>in "text-accent font-medium"</span>>get(/databases/$(database)/documents/artifacts/$(appId)/public/data/chat_rooms/$(chatRoomId)).data.participants;
"text-muted-foreground"</span>>// Deny updates or deletes to private messages for simplicity</span>
"text-accent font-medium"</span>>allow "text-primary font-semibold"</span>>update:, "text-primary font-semibold"</span>>delete:: "text-accent font-medium"</span>>if "text-accent font-medium"</span>>false;
}
}
}