Skip to content

Commit

Permalink
Merge pull request #195 from skadefro/master
Browse files Browse the repository at this point in the history
1.4.3
  • Loading branch information
skadefro authored Apr 21, 2022
2 parents 1cc697f + 2814762 commit 5a91751
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions OpenFlow/src/DBHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class DBHelper {
const span: Span = Logger.otel.startSubSpan("dbhelper.FindById", parent);
try {
if (NoderedUtil.IsNullEmpty(name)) return null;
let item = await this.memoryCache.wrap("mq" + name, () => {
let item = await this.memoryCache.wrap("queuename_" + name, () => {
if (jwt === null || jwt == undefined || jwt == "") { jwt = Crypt.rootToken(); }
if (Config.log_cache) Logger.instanse.debug("Add queue to cache : " + name);
return Config.db.getbyname<User>(name, "mq", jwt, true, span);
Expand Down Expand Up @@ -188,7 +188,7 @@ export class DBHelper {
const span: Span = Logger.otel.startSubSpan("dbhelper.FindById", parent);
try {
if (NoderedUtil.IsNullEmpty(name)) return null;
let item = await this.memoryCache.wrap("mq" + name, () => {
let item = await this.memoryCache.wrap("exchangename_" + name, () => {
if (jwt === null || jwt == undefined || jwt == "") { jwt = Crypt.rootToken(); }
if (Config.log_cache) Logger.instanse.debug("Add exchange to cache : " + name);
return Config.db.getbyname<User>(name, "mq", jwt, true, span);
Expand Down
44 changes: 20 additions & 24 deletions OpenFlow/src/DatabaseConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ export class DatabaseConnection extends events.EventEmitter {
if (collectionname == "mq") {
// DBHelper.clearCache("watch detected change in " + collectionname + " collection for a " + _type + " " + item.name);
await DBHelper.memoryCache.del("mq" + item._id);
if (_type == "exchange") await DBHelper.memoryCache.del("exchangename_" + item.name);
if (_type == "queue") await DBHelper.memoryCache.del("queuename_" + item.name);
}
if (collectionname == "users" && (_type == "user" || _type == "role" || _type == "customer")) {
// DBHelper.clearCache("watch detected change in " + collectionname + " collection for a " + _type + " " + item.name);
Expand Down Expand Up @@ -1774,31 +1776,25 @@ export class DatabaseConnection extends events.EventEmitter {
if (customer == null) throw new Error("Access denied to customer with id " + user2.customerid + " when updating " + user2._id);
} else if (user.HasRoleName("customer admins") && !NoderedUtil.IsNullEmpty(user.customerid)) {
customer = null;
if (!NoderedUtil.IsNullEmpty(user.selectedcustomerid)) {
customer = await this.getbyid<Customer>(user.selectedcustomerid, "users", q.jwt, true, span);
if (customer != null) user2.customerid = user.selectedcustomerid;
}
if (customer == null) {
if (!user.HasRoleName("admins") && !user.HasRoleName("resellers")) {
user2.customerid = user.customerid;
customer = await this.getbyid<Customer>(user2.customerid, "users", q.jwt, true, span);
if (customer != null) user2.customerid = user.customerid;
if (customer == null) {
throw new Error("Access denied to customer with id " + user2.customerid + " when updating " + user2._id);
}
}
}
// user2.customerid = user.customerid;
// if (!NoderedUtil.IsNullEmpty(user.selectedcustomerid)) user2.customerid = user.selectedcustomerid;
// customer = await this.getbyid<Customer>(user2.customerid, "users", q.jwt, true, span);
// if (!NoderedUtil.IsNullEmpty(user.selectedcustomerid)) {
// customer = await this.getbyid<Customer>(user.selectedcustomerid, "users", q.jwt, true, span);
// if (customer != null) user2.customerid = user.selectedcustomerid;
// }
// if (customer == null) {
// if (!user.HasRoleName("admins") && !user.HasRoleName("resellers")) {
// user2.customerid = user.customerid;
// customer = await this.getbyid<Customer>(user2.customerid, "users", q.jwt, true, span);
// if (customer != null) user2.customerid = user.customerid;
// if (customer == null) {
// throw new Error("Access denied to customer with id " + user2.customerid + " when updating " + user2._id);
// }
// }
// }
} else if (Config.multi_tenant && !user.HasRoleName("admins")) {
// We can update, we just don't want to allow inserts ?
// throw new Error("Access denied (not admin or customer admin)");
// user2.customerid = user.customerid;
if (!NoderedUtil.IsNullEmpty(user.selectedcustomerid)) user2.customerid = user.selectedcustomerid;
if (!NoderedUtil.IsNullEmpty(user2.customerid)) {
customer = await this.getbyid<Customer>(user2.customerid, "users", q.jwt, true, span);
}
// if (!NoderedUtil.IsNullEmpty(user.selectedcustomerid)) user2.customerid = user.selectedcustomerid;
// if (!NoderedUtil.IsNullEmpty(user2.customerid)) {
// customer = await this.getbyid<Customer>(user2.customerid, "users", q.jwt, true, span);
// }
}
if (customer != null && !NoderedUtil.IsNullEmpty(customer.admins)) {
const custadmins = await this.getbyid<Role>(customer.admins, "users", q.jwt, true, span);
Expand Down
4 changes: 4 additions & 0 deletions OpenFlow/src/Messages/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,11 @@ export class Message {
try {
msg = DeleteOneMessage.assign(this.data);
if (NoderedUtil.IsNullEmpty(msg.jwt)) { msg.jwt = this.jwt; }
if (!NoderedUtil.IsNullEmpty((msg as any)._id) && NoderedUtil.IsNullEmpty(msg.id)) {
msg.id = (msg as any)._id
}
if (msg.collectionname == "mq") {
if (NoderedUtil.IsNullEmpty(msg.id)) throw new Error("id is mandatory");
var doc = await Config.db.getbyid(msg.id, "mq", msg.jwt, false, span);
if (doc._type == "workitemqueue") {
throw new Error("Access Denied, you must call DeleteWorkItemQueue to delete");
Expand Down
Loading

0 comments on commit 5a91751

Please sign in to comment.