forked from Bobslegend61/k-w-rebuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore.rules
121 lines (97 loc) · 5.63 KB
/
firestore.rules
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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// get document from DB
function getDoc(collection, docId) {
return get(/databases/$(database)/documents/$(collection)/$(docId))
}
// check if a doc exixts
function docExist(collection, docId) {
return exists(/databases/$(database)/documents/$(collection)/$(docId))
}
match /users/{userId} {
allow read, update: if request.auth.uid == userId || getDoc('users', request.auth.uid).data.role == 'super admin';
allow delete: if false;
allow create: if request.auth.uid != null;
}
match /forum/{forumId} {
allow read: if true;
allow create, delete: if request.auth.uid != null && getDoc('users', request.auth.uid).data.role == 'super admin';
allow update: if request.auth.uid != null && (getDoc('users', request.auth.uid).data.role == 'super admin' || request.resource.data.diff(resource.data).affectedKeys().hasOnly(['commentCount']))
match /comments/{commentId} {
allow read: if true;
allow create: if request.auth.uid != null;
allow delete: if request.auth.uid != null && (request.auth.uid == get(/databases/$(database)/documents/forum/$(forumId)/comments/$(commentId)).data.id || getDoc('users', request.auth.uid).data.role == 'super admin');
allow update: if request.auth.uid != null && (request.auth.uid == get(/databases/$(database)/documents/forum/$(forumId)/comments/$(commentId)).data.id || request.resource.data.diff(resource.data).affectedKeys().hasOnly(['replyCount']))
match /replies/{replyId} {
allow read: if true;
allow create: if request.auth.uid != null;
allow delete: if request.auth.uid != null && (request.auth.uid == get(/databases/$(database)/documents/forum/$(forumId)/comments/$(commentId)/replies/$(replyId)).data.id || getDoc('users', request.auth.uid).data.role == 'super admin' || request.auth.uid == get(/databases/$(database)/documents/forum/$(forumId)/comments/$(commentId)).data.id);
allow update: if request.auth.uid != null && request.auth.uid == get(/databases/$(database)/documents/forum/$(forumId)/comments/$(commentId)/replies/$(replyId)).data.id ;
}
}
}
match /news/{newsId} {
allow read: if true;
allow write: if request.auth.uid != null && getDoc('users', request.auth.uid).data.role == 'super admin';
}
match /premium/{premiumId} {
allow write: if request.auth.uid != null && getDoc('users', request.auth.uid).data.role == 'super admin';
allow read: if getDoc('users', request.auth.uid).data.role == 'super admin' || (getDoc('users', request.auth.uid).data.subscriptions != null && getDoc('users', request.auth.uid).data.subscriptions.premium != null && getDoc('users', request.auth.uid).data.subscriptions.premium.subscribed == true)
}
match /scouts/{scoutId} {
allow read: if true;
allow create: if request.auth.uid != null && !docExist('scouts', request.auth.uid);
allow update: if request.auth.uid != null && (request.auth.uid == scoutId && !request.resource.data.diff(resource.data).affectedKeys().hasAny(['approved']))|| (getDoc('users', request.auth.uid).data.role == 'super admin' && request.resource.data.diff(resource.data).affectedKeys().hasOnly(['approved']));
allow delete: if false;
}
match /leagues/{leagueId} {
allow read: if true;
allow write: if false;
}
match /talents/{talentId} {
allow read: if true;
allow create: if request.auth.uid != null && !docExist('talents', request.auth.uid);
allow delete: if false;
allow update: if request.auth.uid != null && ((request.auth.uid == talentId && !request.resource.data.diff(resource.data).affectedKeys().hasAny(['adminReview', 'scoutComments', 'approved', 'featured'])) || (getDoc('users', request.auth.uid).data.role == 'super admin' && request.resource.data.diff(resource.data).affectedKeys().hasAny(['adminReview','approved', 'featured'])) || (docExist('scouts', request.auth.uid) && getDoc('scouts', request.auth.uid).data.approved == true && request.resource.data.diff(resource.data).affectedKeys().hasOnly(['scoutComments'])))
}
}
}
// rules_version = '2';
// service cloud.firestore {
// match /databases/{database}/documents {
// match /users/{userId} {
// allow read, update, delete: if request.auth.uid == userId || get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role != null
// allow create: if request.auth.uid != null;
// }
// match /forum/{forumId} {
// allow read: if true
// allow update: if true
// allow create, delete: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role != null
// }
// match /news/{newsId} {
// allow read: if true
// allow write: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role != null
// }
// match /premium-post/{premiumPostId} {
// allow read: if true
// allow write: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role != null
// }
// match /premium/{premiumId} {
// allow write: if request.auth.uid == request.resource.data.userId
// allow read: if true
// }
// match /talents/{talentId} {
// allow read: if true
// allow write: if request.auth.uid == request.resource.data.userId || get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role != null
// }
// }
// }
// rules_version = '2';
// service cloud.firestore {
// match /databases/{database}/documents {
// match /{document=**} {
// allow read, write: if request.time < timestamp.date(2021, 12, 4);
// }
// }
// }