@edgedev/firebase 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -2
- package/edgeFirebase.ts +31 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -257,8 +257,8 @@ interface usersByEmail {
|
|
|
257
257
|
```typescript
|
|
258
258
|
interface user {
|
|
259
259
|
email: string;
|
|
260
|
-
roles:
|
|
261
|
-
specialPermissions:
|
|
260
|
+
roles: role[];
|
|
261
|
+
specialPermissions: specialPermission[];
|
|
262
262
|
userId: string;
|
|
263
263
|
docId: string;
|
|
264
264
|
uid: string;
|
|
@@ -266,6 +266,29 @@ interface user {
|
|
|
266
266
|
}
|
|
267
267
|
```
|
|
268
268
|
|
|
269
|
+
```typescript
|
|
270
|
+
interface role {
|
|
271
|
+
collectionPath: "-" | string; // - is root
|
|
272
|
+
role: "admin" | "user";
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
interface specialPermission {
|
|
278
|
+
collectionPath: "-" | string; // - is root
|
|
279
|
+
permissions: permissions;
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
interface permissions {
|
|
285
|
+
assign: boolean;
|
|
286
|
+
read: boolean;
|
|
287
|
+
write: boolean;
|
|
288
|
+
delete: boolean;
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
269
292
|
|
|
270
293
|
|
|
271
294
|
### List Collections with Assign Access
|
package/edgeFirebase.ts
CHANGED
|
@@ -103,8 +103,8 @@ interface newUser {
|
|
|
103
103
|
|
|
104
104
|
interface user {
|
|
105
105
|
email: string;
|
|
106
|
-
roles:
|
|
107
|
-
specialPermissions:
|
|
106
|
+
roles: role[];
|
|
107
|
+
specialPermissions: specialPermission[];
|
|
108
108
|
userId: string;
|
|
109
109
|
docId: string;
|
|
110
110
|
uid: string;
|
|
@@ -438,19 +438,28 @@ export const EdgeFirebase = class {
|
|
|
438
438
|
newUser.specialPermissions
|
|
439
439
|
);
|
|
440
440
|
if (canAssignRole.canDo && canAssignSpecialPermissions.canDo) {
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
441
|
+
const userRef = doc(this.db, "users", newUser.email);
|
|
442
|
+
const userSnap = await getDoc(userRef);
|
|
443
|
+
if (!userSnap.exists()) {
|
|
444
|
+
const userMeta: userMeta = {
|
|
445
|
+
docId: newUser.email,
|
|
446
|
+
userId: "",
|
|
447
|
+
email: newUser.email,
|
|
448
|
+
roles: newUser.roles,
|
|
449
|
+
specialPermissions: newUser.specialPermissions,
|
|
450
|
+
meta: newUser.meta
|
|
451
|
+
};
|
|
452
|
+
this.generateUserMeta(userMeta);
|
|
453
|
+
return this.sendResponse({
|
|
454
|
+
success: true,
|
|
455
|
+
message: ""
|
|
456
|
+
});
|
|
457
|
+
} else {
|
|
458
|
+
return this.sendResponse({
|
|
459
|
+
success: false,
|
|
460
|
+
message: "User already exists"
|
|
461
|
+
});
|
|
462
|
+
}
|
|
454
463
|
} else {
|
|
455
464
|
return this.sendResponse({
|
|
456
465
|
success: false,
|
|
@@ -1064,15 +1073,15 @@ export const EdgeFirebase = class {
|
|
|
1064
1073
|
userList[user.email] = {
|
|
1065
1074
|
docId: user.docId,
|
|
1066
1075
|
email: user.email,
|
|
1067
|
-
roles: {
|
|
1068
|
-
specialPermissions:
|
|
1076
|
+
roles: [{collectionPath, role: user.roles[collectionPath].role }],
|
|
1077
|
+
specialPermissions: [],
|
|
1069
1078
|
meta: user.meta,
|
|
1070
1079
|
last_updated: user.last_updated,
|
|
1071
1080
|
userId: user.userId,
|
|
1072
1081
|
uid: user.uid
|
|
1073
1082
|
}
|
|
1074
1083
|
} else {
|
|
1075
|
-
userList[user.email].roles
|
|
1084
|
+
userList[user.email].roles.push({ collectionPath, role: user.roles[collectionPath].role })
|
|
1076
1085
|
}
|
|
1077
1086
|
});
|
|
1078
1087
|
const specialPermissionsUsers = await getDocs(
|
|
@@ -1091,15 +1100,15 @@ export const EdgeFirebase = class {
|
|
|
1091
1100
|
userList[user.email] = {
|
|
1092
1101
|
docId: user.docId,
|
|
1093
1102
|
email: user.email,
|
|
1094
|
-
role:
|
|
1095
|
-
specialPermissions: {
|
|
1103
|
+
role: [],
|
|
1104
|
+
specialPermissions: [{ collectionPath, permissions: user.specialPermissions[collectionPath].permissions }],
|
|
1096
1105
|
meta: user.meta,
|
|
1097
1106
|
last_updated: user.last_updated,
|
|
1098
1107
|
userId: user.userId,
|
|
1099
1108
|
uid: user.uid
|
|
1100
1109
|
}
|
|
1101
1110
|
} else {
|
|
1102
|
-
userList[user.email].specialPermissions
|
|
1111
|
+
userList[user.email].specialPermissions.push({ collectionPath, permissions: user.specialPermissions[collectionPath].permissions })
|
|
1103
1112
|
}
|
|
1104
1113
|
});
|
|
1105
1114
|
}
|
|
@@ -1186,7 +1195,7 @@ export const EdgeFirebase = class {
|
|
|
1186
1195
|
}
|
|
1187
1196
|
};
|
|
1188
1197
|
|
|
1189
|
-
|
|
1198
|
+
private storeUserRoles = async (
|
|
1190
1199
|
email: string,
|
|
1191
1200
|
collectionPath: string,
|
|
1192
1201
|
role: "admin" | "user"
|