-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
firestore.rules
100 lines (88 loc) · 4.75 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Security Functions
function isSignedIn() {
return request.auth != null;
}
function isSignedInWithUser(userId) {
return request.auth.uid == userId;
}
function hasRole(role) {
return request.auth.token.role == role;
}
function hasAnyRole(roles) {
return request.auth.token.role in roles;
}
function hasPermission(permission) {
return hasRole('custom') && permission in request.auth.token.permissions;
}
function hasAnyPermission(permissions) {
return hasRole('custom') && request.auth.token.permissions.hasAny(permissions);
}
// Spaces
match /spaces/{spaceId} {
allow read: if isSignedIn() && hasAnyRole(['custom','admin']);
allow write: if isSignedIn() && (hasRole('admin') || hasPermission('SPACE_MANAGEMENT'));
// Translations
match /translations/{translationId} {
allow read: if isSignedIn() && (hasRole('admin') || hasPermission('TRANSLATION_READ'));
allow create: if isSignedIn() && (hasRole('admin') || hasPermission('TRANSLATION_CREATE'));
allow update: if isSignedIn() && (hasRole('admin') || hasPermission('TRANSLATION_UPDATE'));
allow delete: if isSignedIn() && (hasRole('admin') || hasPermission('TRANSLATION_DELETE'));
}
// Schemas
match /schemas/{schemaId} {
allow read: if isSignedIn() && (hasRole('admin') || hasAnyPermission(['SCHEMA_READ','CONTENT_READ']));
allow create: if isSignedIn() && (hasRole('admin') || hasPermission('SCHEMA_CREATE'));
allow update: if isSignedIn() && (hasRole('admin') || hasPermission('SCHEMA_UPDATE'));
allow delete: if isSignedIn() && (hasRole('admin') || hasPermission('SCHEMA_DELETE'));
}
// Content
match /contents/{contentId} {
allow read: if isSignedIn() && (hasRole('admin') || hasPermission('CONTENT_READ'));
allow create: if isSignedIn() && (hasRole('admin') || hasPermission('CONTENT_CREATE'));
allow update: if isSignedIn() && (hasRole('admin') || hasPermission('CONTENT_UPDATE'));
allow delete: if isSignedIn() && (hasRole('admin') || hasPermission('CONTENT_DELETE'));
}
// Assets
match /assets/{assetId} {
allow read: if isSignedIn() && (hasRole('admin') || hasAnyPermission(['ASSET_READ','CONTENT_READ']));
allow create: if isSignedIn() && (hasRole('admin') || hasPermission('ASSET_CREATE'));
allow update: if isSignedIn() && (hasRole('admin') || hasPermission('ASSET_UPDATE'));
allow delete: if isSignedIn() && (hasRole('admin') || hasPermission('ASSET_DELETE'));
}
// Tasks
match /tasks/{taskId} {
allow read: if isSignedIn() && (hasRole('admin') || hasAnyPermission(['ASSET_IMPORT','ASSET_EXPORT','CONTENT_IMPORT','CONTENT_EXPORT','SCHEMA_IMPORT','SCHEMA_EXPORT','TRANSLATION_IMPORT','TRANSLATION_EXPORT']));
allow create: if isSignedIn() && (hasRole('admin') || hasAnyPermission(['ASSET_IMPORT','ASSET_EXPORT','CONTENT_IMPORT','CONTENT_EXPORT','SCHEMA_IMPORT','SCHEMA_EXPORT','TRANSLATION_IMPORT','TRANSLATION_EXPORT']));
allow update: if isSignedIn() && (hasRole('admin') || hasAnyPermission(['ASSET_IMPORT','ASSET_EXPORT','CONTENT_IMPORT','CONTENT_EXPORT','SCHEMA_IMPORT','SCHEMA_EXPORT','TRANSLATION_IMPORT','TRANSLATION_EXPORT']));
allow delete: if isSignedIn() && (hasRole('admin') || hasAnyPermission(['ASSET_IMPORT','ASSET_EXPORT','CONTENT_IMPORT','CONTENT_EXPORT','SCHEMA_IMPORT','SCHEMA_EXPORT','TRANSLATION_IMPORT','TRANSLATION_EXPORT']));
}
// Tokens
match /tokens/{tokenId} {
allow read: if isSignedIn() && (hasRole('admin') || hasPermission('SPACE_MANAGEMENT'));
allow write: if isSignedIn() && (hasRole('admin') || hasPermission('SPACE_MANAGEMENT'));
}
// Plugins
match /plugins/{pluginId} {
allow read: if isSignedIn() && (hasRole('admin') || hasPermission('SPACE_MANAGEMENT'));
allow write: if isSignedIn() && (hasRole('admin') || hasPermission('SPACE_MANAGEMENT'));
}
}
// Users
match /users/{userId} {
allow read: if isSignedIn() && ( isSignedInWithUser(userId) || (hasRole('admin') || hasPermission('USER_MANAGEMENT')));
allow write: if isSignedIn() && (hasRole('admin') || hasPermission('USER_MANAGEMENT'));
}
// Configs
match /configs/{configId} {
allow read: if isSignedIn() && (hasRole('admin') || hasPermission('SETTINGS_MANAGEMENT'));
allow write: if isSignedIn() && (hasRole('admin') || hasPermission('SETTINGS_MANAGEMENT'));
}
match /{document=**} {
allow read: if isSignedIn() && hasAnyRole(['custom','admin']);
allow write: if isSignedIn() && hasRole('admin');
}
}
}