@edgedev/firebase 1.4.3 → 1.4.5
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 +4 -13
- package/edgeFirebase.ts +64 -65
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -242,10 +242,10 @@ edgeFirebase.removeUser("user@edgemarketingdesign.com");
|
|
|
242
242
|
|
|
243
243
|
### List Users
|
|
244
244
|
|
|
245
|
-
This will list all users that are members of
|
|
245
|
+
This will list all users that are members of the collection and subcollections passed to the function that the user running the function has assign access for, it will be a listed index by email/user id.
|
|
246
246
|
|
|
247
247
|
```javascript
|
|
248
|
-
const users = await edgeFirebase.listUsers();
|
|
248
|
+
const users = await edgeFirebase.listUsers("myItems");
|
|
249
249
|
```
|
|
250
250
|
|
|
251
251
|
```typescript
|
|
@@ -289,16 +289,6 @@ interface permissions {
|
|
|
289
289
|
}
|
|
290
290
|
```
|
|
291
291
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
### List Collections with Assign Access
|
|
295
|
-
|
|
296
|
-
This function will list all collections that the user running it has assign access for.
|
|
297
|
-
|
|
298
|
-
```javascript
|
|
299
|
-
const collections = await edgeFirebase.listCollectionsCanAssign(); // returns array of strings (collection paths)
|
|
300
|
-
```
|
|
301
|
-
|
|
302
292
|
# Firebase Authentication
|
|
303
293
|
|
|
304
294
|
(currently only sign in with email and password is supported)
|
|
@@ -325,7 +315,8 @@ interface UserDataObject {
|
|
|
325
315
|
logInErrorMessage: string;
|
|
326
316
|
meta: object;
|
|
327
317
|
roles: role[]; //see role below
|
|
328
|
-
specialPermissions: specialPermission[]; //see specialPermission
|
|
318
|
+
specialPermissions: specialPermission[]; //see specialPermission below
|
|
319
|
+
canAssignCollectionPaths: string[]; //an array of collectionPaths that the user has "assign" access to
|
|
329
320
|
}
|
|
330
321
|
|
|
331
322
|
// sub types of UserDataObject:
|
package/edgeFirebase.ts
CHANGED
|
@@ -92,6 +92,7 @@ interface UserDataObject {
|
|
|
92
92
|
meta: object;
|
|
93
93
|
roles: role[];
|
|
94
94
|
specialPermissions: specialPermission[];
|
|
95
|
+
canAssignCollectionPaths: string[];
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
interface newUser {
|
|
@@ -209,6 +210,7 @@ export const EdgeFirebase = class {
|
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
212
|
this.user.specialPermissions = specialPermissions;
|
|
213
|
+
this.listCollectionsCanAssign()
|
|
212
214
|
}
|
|
213
215
|
const metaUnsubscribe = onSnapshot(
|
|
214
216
|
doc(this.db, "users", this.user.email),
|
|
@@ -218,7 +220,7 @@ export const EdgeFirebase = class {
|
|
|
218
220
|
email: this.user.email,
|
|
219
221
|
roles: [],
|
|
220
222
|
specialPermissions: [],
|
|
221
|
-
meta: {}
|
|
223
|
+
meta: {},
|
|
222
224
|
});
|
|
223
225
|
this.user.meta = {};
|
|
224
226
|
} else {
|
|
@@ -245,6 +247,7 @@ export const EdgeFirebase = class {
|
|
|
245
247
|
}
|
|
246
248
|
}
|
|
247
249
|
this.user.specialPermissions = specialPermissions;
|
|
250
|
+
this.listCollectionsCanAssign()
|
|
248
251
|
}
|
|
249
252
|
}
|
|
250
253
|
);
|
|
@@ -724,7 +727,8 @@ export const EdgeFirebase = class {
|
|
|
724
727
|
logInErrorMessage: "",
|
|
725
728
|
meta: {},
|
|
726
729
|
roles: [],
|
|
727
|
-
specialPermissions: []
|
|
730
|
+
specialPermissions: [],
|
|
731
|
+
canAssignCollectionPaths: [],
|
|
728
732
|
});
|
|
729
733
|
|
|
730
734
|
public getDocData = async (
|
|
@@ -997,8 +1001,7 @@ export const EdgeFirebase = class {
|
|
|
997
1001
|
}
|
|
998
1002
|
};
|
|
999
1003
|
|
|
1000
|
-
|
|
1001
|
-
public listCollectionsCanAssign = async (): Promise<string[]> => {
|
|
1004
|
+
private listCollectionsCanAssign = async (): Promise<void> => {
|
|
1002
1005
|
let collectionPaths = [];
|
|
1003
1006
|
for (const role of this.user.roles) {
|
|
1004
1007
|
const canAssign = await this.permissionCheck(
|
|
@@ -1042,75 +1045,71 @@ export const EdgeFirebase = class {
|
|
|
1042
1045
|
}
|
|
1043
1046
|
}
|
|
1044
1047
|
collectionPathList = [...new Set(collectionPathList)];
|
|
1045
|
-
|
|
1048
|
+
this.user.canAssignCollectionPaths = collectionPathList;
|
|
1046
1049
|
};
|
|
1047
1050
|
|
|
1048
|
-
// TODO: finish making this query by collectionPath if passed.. in furture will be used to get users by collectionPath
|
|
1049
|
-
// because having one giant list of users is not scalable
|
|
1050
1051
|
public listUsers = async (collectionPath = ''): Promise<usersByEmail> => {
|
|
1051
1052
|
const userList = {};
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
"roles." + collectionPath + ".collectionPath",
|
|
1065
|
-
"==",
|
|
1066
|
-
collectionPath
|
|
1053
|
+
|
|
1054
|
+
for (const collectionPathCheck of this.user.canAssignCollectionPaths) {
|
|
1055
|
+
|
|
1056
|
+
if (collectionPathCheck.startsWith(collectionPath.replaceAll('/', '-'))) {
|
|
1057
|
+
const roleUsers = await getDocs(
|
|
1058
|
+
query(
|
|
1059
|
+
collection(this.db, "users"),
|
|
1060
|
+
where(
|
|
1061
|
+
"roles." + collectionPathCheck + ".collectionPath",
|
|
1062
|
+
"==",
|
|
1063
|
+
collectionPathCheck
|
|
1064
|
+
)
|
|
1067
1065
|
)
|
|
1068
|
-
)
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1066
|
+
);
|
|
1067
|
+
|
|
1068
|
+
roleUsers.forEach((doc) => {
|
|
1069
|
+
const user = doc.data();
|
|
1070
|
+
if (!Object.prototype.hasOwnProperty.call(userList, user.docId)) {
|
|
1071
|
+
userList[user.email] = {
|
|
1072
|
+
docId: user.docId,
|
|
1073
|
+
email: user.email,
|
|
1074
|
+
roles: [{collectionPath: collectionPathCheck, role: user.roles[collectionPathCheck].role }],
|
|
1075
|
+
specialPermissions: [],
|
|
1076
|
+
meta: user.meta,
|
|
1077
|
+
last_updated: user.last_updated,
|
|
1078
|
+
userId: user.userId,
|
|
1079
|
+
uid: user.uid
|
|
1080
|
+
}
|
|
1081
|
+
} else {
|
|
1082
|
+
userList[user.email].roles.push({ collectionPath: collectionPathCheck, role: user.roles[collectionPathCheck].role })
|
|
1082
1083
|
}
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
"==",
|
|
1093
|
-
collectionPath
|
|
1084
|
+
});
|
|
1085
|
+
const specialPermissionsUsers = await getDocs(
|
|
1086
|
+
query(
|
|
1087
|
+
collection(this.db, "users"),
|
|
1088
|
+
where(
|
|
1089
|
+
"specialPermissions." + collectionPathCheck + ".collectionPath",
|
|
1090
|
+
"==",
|
|
1091
|
+
collectionPathCheck
|
|
1092
|
+
)
|
|
1094
1093
|
)
|
|
1095
|
-
)
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1094
|
+
);
|
|
1095
|
+
specialPermissionsUsers.forEach((doc) => {
|
|
1096
|
+
const user = doc.data();
|
|
1097
|
+
if (!Object.prototype.hasOwnProperty.call(userList, user.docId)) {
|
|
1098
|
+
userList[user.email] = {
|
|
1099
|
+
docId: user.docId,
|
|
1100
|
+
email: user.email,
|
|
1101
|
+
role: [],
|
|
1102
|
+
specialPermissions: [{ collectionPath: collectionPathCheck, permissions: user.specialPermissions[collectionPathCheck].permissions }],
|
|
1103
|
+
meta: user.meta,
|
|
1104
|
+
last_updated: user.last_updated,
|
|
1105
|
+
userId: user.userId,
|
|
1106
|
+
uid: user.uid
|
|
1107
|
+
}
|
|
1108
|
+
} else {
|
|
1109
|
+
userList[user.email].specialPermissions.push({ collectionPath: collectionPathCheck, permissions: user.specialPermissions[collectionPathCheck].permissions })
|
|
1109
1110
|
}
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
}
|
|
1113
|
-
});
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1114
1113
|
}
|
|
1115
1114
|
return userList;
|
|
1116
1115
|
};
|