Skip to content

Commit ab0eaa0

Browse files
committed
Fix bypass when customer role is deleted, and warn
1 parent b059f3b commit ab0eaa0

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

OpenFlow/src/DatabaseConnection.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,8 +1417,12 @@ export class DatabaseConnection extends events.EventEmitter {
14171417
if (!NoderedUtil.IsNullEmpty(user2.customerid)) {
14181418
// TODO: Check user has permission to this customer
14191419
const custusers: Role = Role.assign(await this.getbyid<Role>(customer.users, "users", jwt, true, span));
1420-
custusers.AddMember(item);
1421-
await DBHelper.Save(custusers, Crypt.rootToken(), span);
1420+
if (!NoderedUtil.IsNullUndefinded(custusers)) {
1421+
custusers.AddMember(item);
1422+
await DBHelper.Save(custusers, Crypt.rootToken(), span);
1423+
} else {
1424+
Logger.instanse.debug("[" + user.username + "][" + collectionname + "] Failed finding customer users " + customer.users + " role while updating item " + item._id);
1425+
}
14221426
}
14231427
}
14241428
if (collectionname === "users" && item._type === "role") {
@@ -1781,9 +1785,13 @@ export class DatabaseConnection extends events.EventEmitter {
17811785
}
17821786
if (customer != null && !NoderedUtil.IsNullEmpty(customer.admins)) {
17831787
const custadmins = await this.getbyid<Role>(customer.admins, "users", q.jwt, true, span);
1784-
Base.addRight(q.item, custadmins._id, custadmins.name, [Rights.full_control]);
1785-
if (q.item._id == customer.admins || q.item._id == customer.users) {
1786-
Base.removeRight(q.item, custadmins._id, [Rights.delete]);
1788+
if (!NoderedUtil.IsNullEmpty(custadmins)) {
1789+
Base.addRight(q.item, custadmins._id, custadmins.name, [Rights.full_control]);
1790+
if (q.item._id == customer.admins || q.item._id == customer.users) {
1791+
Base.removeRight(q.item, custadmins._id, [Rights.delete]);
1792+
}
1793+
} else {
1794+
Logger.instanse.warn("[" + user.username + "][" + q.collectionname + "] Failed locating customer admins role " + customer.admins + " while updating " + q.item._id + " in database");
17871795
}
17881796
(q.item as any).company = customer.name;
17891797
q.item = this.ensureResource(q.item, q.collectionname);

0 commit comments

Comments
 (0)