@@ -98,40 +98,61 @@ model.populateDatabase(data);
9898
9999``` json
100100{
101- "rules" : {
102- "courses" : {
103- ".read" : true ,
104- ".write" : " auth != null && (auth.uid === 'adminuid' || auth.uid === 'adminuid')"
105- },
106- "metadata" : {
107- ".read" : true ,
108- ".write" : " auth != null && (auth.uid === 'adminuid' || auth.uid === 'adminuid')"
109- },
110- "departments" : {
111- ".read" : true ,
112- ".write" : " auth != null && (auth.uid === 'adminuid' || auth.uid === 'adminuid')"
113- },
114- "locations" : {
115- ".read" : true ,
116- ".write" : " auth != null && (auth.uid === 'adminuid' || auth.uid === 'adminuid')"
117- },
118- "reviews" : {
119- ".read" : true ,
120- "$courseCode" : {
121- "$userID" : {
122- ".write" : " auth != null && (auth.uid === $userID || data.child('uid').val() === auth.uid || !data.exists())" ,
123- ".validate" : " newData.hasChildren(['text', 'timestamp']) && newData.child('text').isString() && newData.child('timestamp').isNumber()"
101+ "rules" : {
102+ // Courses and Metadata
103+ "courses" : {
104+ ".read" : true ,
105+ ".write" : " auth != null && (auth.uid === '6qKa992eL4fRkGKzp3OG5Sjjk983' || auth.uid === 'wa9HoCfWe2Vpw6J7oiq5oCxNYz52')"
106+ },
107+ "metadata" : {
108+ ".read" : true ,
109+ ".write" : " auth != null && (auth.uid === '6qKa992eL4fRkGKzp3OG5Sjjk983' || auth.uid === 'wa9HoCfWe2Vpw6J7oiq5oCxNYz52')"
110+ },
111+ "departments" : {
112+ ".read" : true ,
113+ ".write" : " auth != null && (auth.uid === '6qKa992eL4fRkGKzp3OG5Sjjk983' || auth.uid === 'wa9HoCfWe2Vpw6J7oiq5oCxNYz52')"
114+ },
115+ "locations" : {
116+ ".read" : true ,
117+ ".write" : " auth != null && (auth.uid === '6qKa992eL4fRkGKzp3OG5Sjjk983' || auth.uid === 'wa9HoCfWe2Vpw6J7oiq5oCxNYz52')"
118+ },
119+
120+ // Reviews and Comments
121+ "reviews" : {
122+ ".read" : true ,
123+ "$courseCode" : {
124+ "$reviewUserID" : {
125+ // Only the original author can write the main review
126+ ".write" : " auth != null && (auth.uid === $reviewUserID || data.child('uid').val() === auth.uid || !data.exists())" ,
127+ ".validate" : "newData.hasChildren(['text', 'timestamp']) &&
128+ newData.child('text').isString() &&
129+ newData.child('text').val().length <= 2501 &&
130+ newData.child('timestamp').isNumber()",
131+
132+ // Allow any signed-in user to write comments under the review
133+ "comments" : {
134+ ".write" : " auth != null" ,
135+ "$commentId" : {
136+ ".validate" : "newData.hasChildren(['text', 'userName', 'timestamp']) &&
137+ newData.child('text').isString() &&
138+ newData.child('userName').isString() &&
139+ newData.child('timestamp').isNumber()"
140+ }
124141 }
125142 }
126- },
127- "users" : {
128- "$userID" : {
129- ".read" : " auth != null && auth.uid === $userID" ,
130- ".write" : " auth != null && auth.uid === $userID"
131- }
143+ }
144+ },
145+
146+ // User-specific Data
147+ "users" : {
148+ "$userID" : {
149+ ".read" : " auth != null && auth.uid === $userID" ,
150+ ".write" : " auth != null && auth.uid === $userID"
132151 }
133152 }
153+ }
134154}
155+
135156```
136157</details >
137158
0 commit comments