Skip to content

Commit 98e4e7f

Browse files
committed
add persist_user_impersonation
1 parent 343e06d commit 98e4e7f

6 files changed

Lines changed: 16 additions & 12 deletions

File tree

OpenFlow/src/Config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class Config {
3737
Config.auto_create_users = Config.parseBoolean(Config.getEnv("auto_create_users", "false"));
3838
Config.auto_create_domains = Config.parseArray(Config.getEnv("auto_create_domains", ""));
3939
Config.allow_user_registration = Config.parseBoolean(Config.getEnv("allow_user_registration", "false"));
40+
Config.persist_user_impersonation = Config.parseBoolean(Config.getEnv("persist_user_impersonation", "true"));
4041
Config.allow_personal_nodered = Config.parseBoolean(Config.getEnv("allow_personal_nodered", "false"));
4142
Config.auto_create_personal_nodered_group = Config.parseBoolean(Config.getEnv("auto_create_personal_nodered_group", "false"));
4243
Config.force_add_admins = Config.parseBoolean(Config.getEnv("force_add_admins", "true"));
@@ -140,6 +141,7 @@ export class Config {
140141
public static auto_create_users: boolean = Config.parseBoolean(Config.getEnv("auto_create_users", "false"));
141142
public static auto_create_domains: string[] = Config.parseArray(Config.getEnv("auto_create_domains", ""));
142143
public static allow_user_registration: boolean = Config.parseBoolean(Config.getEnv("allow_user_registration", "false"));
144+
public static persist_user_impersonation: boolean = Config.parseBoolean(Config.getEnv("persist_user_impersonation", "true"));
143145
public static allow_personal_nodered: boolean = Config.parseBoolean(Config.getEnv("allow_personal_nodered", "false"));
144146
public static use_ingress_beta1_syntax: boolean = Config.parseBoolean(Config.getEnv("use_ingress_beta1_syntax", "true"));
145147
public static auto_create_personal_nodered_group: boolean = Config.parseBoolean(Config.getEnv("auto_create_personal_nodered_group", "false"));

OpenFlow/src/DatabaseConnection.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class DatabaseConnection {
5353
name: 'openflow_mongodb_query_seconds',
5454
help: 'Duration for mongodb queries microseconds',
5555
labelNames: ['collection'],
56-
buckets: [0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10]
56+
buckets: [0.01, 0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10, 50]
5757
})
5858
public static mongodb_query_count = new client.Counter({
5959
name: 'openflow_mongodb_query_count',
@@ -64,7 +64,7 @@ export class DatabaseConnection {
6464
name: 'openflow_mongodb_aggregate_seconds',
6565
help: 'Duration for mongodb queries microseconds',
6666
labelNames: ['collection'],
67-
buckets: [0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10]
67+
buckets: [0.01, 0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10, 50]
6868
})
6969
public static mongodb_aggregate_count = new client.Counter({
7070
name: 'openflow_mongodb_aggregate_count',
@@ -75,7 +75,7 @@ export class DatabaseConnection {
7575
name: 'openflow_mongodb_insert_seconds',
7676
help: 'Duration for mongodb inserts microseconds',
7777
labelNames: ['collection'],
78-
buckets: [0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10]
78+
buckets: [0.01, 0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10, 50]
7979
})
8080
public static mongodb_insert_count = new client.Counter({
8181
name: 'openflow_mongodb_insert_count',
@@ -86,7 +86,7 @@ export class DatabaseConnection {
8686
name: 'openflow_mongodb_update_seconds',
8787
help: 'Duration for mongodb updates microseconds',
8888
labelNames: ['collection'],
89-
buckets: [0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10]
89+
buckets: [0.01, 0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10, 50]
9090
})
9191
public static mongodb_update_count = new client.Counter({
9292
name: 'openflow_mongodb_update_count',
@@ -97,7 +97,7 @@ export class DatabaseConnection {
9797
name: 'openflow_mongodb_replace_seconds',
9898
help: 'Duration for mongodb replaces microseconds',
9999
labelNames: ['collection'],
100-
buckets: [0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10]
100+
buckets: [0.01, 0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10, 50]
101101
})
102102
public static mongodb_replace_count = new client.Counter({
103103
name: 'openflow_mongodb_replace_count',
@@ -108,7 +108,7 @@ export class DatabaseConnection {
108108
name: 'openflow_mongodb_delete_seconds',
109109
help: 'Duration for mongodb deletes microseconds',
110110
labelNames: ['collection'],
111-
buckets: [0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10]
111+
buckets: [0.01, 0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10, 50]
112112
})
113113
public static mongodb_delete_count = new client.Counter({
114114
name: 'openflow_mongodb_delete_count',
@@ -119,7 +119,7 @@ export class DatabaseConnection {
119119
name: 'openflow_mongodb_deletemany_seconds',
120120
help: 'Duration for mongodb deletemanys microseconds',
121121
labelNames: ['collection'],
122-
buckets: [0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10]
122+
buckets: [0.01, 0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10, 50]
123123
})
124124
public static mongodb_deletemany_count = new client.Counter({
125125
name: 'openflow_mongodb_deletemany_count',

OpenFlow/src/Messages/Message.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ export class Message {
839839
} else {
840840
if (msg.impersonate == "-1" || msg.impersonate == "false") {
841841
user = await DBHelper.FindById(impostor, Crypt.rootToken());
842-
UpdateDoc.$unset = { "impersonating": "" };
842+
if(Config.persist_user_impersonation) UpdateDoc.$unset = { "impersonating": "" };
843843
user.impersonating = undefined;
844844
if (!NoderedUtil.IsNullEmpty(tuser.impostor)) {
845845
tuser = TokenUser.From(user);
@@ -884,7 +884,9 @@ export class Message {
884884
// Check we have update rights
885885
try {
886886
await DBHelper.Save(user, msg.jwt);
887-
await Config.db._UpdateOne({ _id: tuserimpostor._id }, { "$set": { "impersonating": user._id } } as any, "users", 1, false, msg.jwt);
887+
if(Config.persist_user_impersonation) {
888+
await Config.db._UpdateOne({ _id: tuserimpostor._id }, { "$set": { "impersonating": user._id } } as any, "users", 1, false, msg.jwt);
889+
}
888890
} catch (error) {
889891
const impostors = await Config.db.query<User>({ _id: msg.impersonate }, null, 1, 0, null, "users", Crypt.rootToken());
890892
const impb: User = new User(); impb.name = "unknown"; impb._id = msg.impersonate;

OpenFlowNodeRED/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/nodered",
3-
"version": "1.1.186",
3+
"version": "1.1.188",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.186
1+
1.1.188

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/openflow",
3-
"version": "1.1.186",
3+
"version": "1.1.188",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)