Skip to content

Commit

Permalink
Merge pull request #239 from skadefro/master
Browse files Browse the repository at this point in the history
close 1.4.17
  • Loading branch information
skadefro authored Jul 6, 2022
2 parents c9638ae + c2ec36c commit 9feaae8
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 21 deletions.
7 changes: 7 additions & 0 deletions OpenFlow/src/DatabaseConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3696,6 +3696,13 @@ export class DatabaseConnection extends events.EventEmitter {
// await this.createIndex(collection.name, "_acl", { "_acl._id": 1, "_acl.rights": 1, "_acl.deny": 1 }, null, span)
// }
break;
case "workitems":
if (indexnames.indexOf("_type_1_state_1_wiqid_1_priority_1") === -1) {
await this.createIndex(collection.name, "timestamp_1", { "_type": 1, "state": 1, "wiqid": 1, "priority": 1 }, null, span)
}
if (indexnames.indexOf("_type_1_state_1_wiq_1_lastrun_-1") === -1) {
await this.createIndex(collection.name, "timestamp_1", { "_type": 1, "state": 1, "wiq": 1, "lastrun": -1 }, null, span)
}
default:
// if (indexnames.indexOf("_type_1") === -1) {
// await this.createIndex(collection.name, "_type_1", { "_type": 1 }, null, span)
Expand Down
72 changes: 66 additions & 6 deletions OpenFlow/src/Messages/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { Config } from "../Config";
import { Audit, tokenType } from "../Audit";
import { LoginProvider } from "../LoginProvider";
import { Readable, Stream } from "stream";
import { GridFSBucket, ObjectID, Cursor } from "mongodb";
import { GridFSBucket, ObjectID, Cursor, Binary } from "mongodb";
import * as path from "path";
import { DatabaseConnection } from "../DatabaseConnection";
import { StripeMessage, NoderedUtil, QueuedMessage, RegisterQueueMessage, QueueMessage, CloseQueueMessage, ListCollectionsMessage, DropCollectionMessage, QueryMessage, AggregateMessage, InsertOneMessage, UpdateOneMessage, Base, UpdateManyMessage, InsertOrUpdateOneMessage, DeleteOneMessage, MapReduceMessage, SigninMessage, TokenUser, User, Rights, EnsureNoderedInstanceMessage, DeleteNoderedInstanceMessage, DeleteNoderedPodMessage, RestartNoderedInstanceMessage, GetNoderedInstanceMessage, GetNoderedInstanceLogMessage, SaveFileMessage, WellknownIds, GetFileMessage, UpdateFileMessage, NoderedUser, WatchMessage, GetDocumentVersionMessage, DeleteManyMessage, InsertManyMessage, RegisterExchangeMessage, EnsureCustomerMessage, Customer, stripe_tax_id, Role, SelectCustomerMessage, Rolemember, ResourceUsage, Resource, ResourceVariant, stripe_subscription, GetNextInvoiceMessage, stripe_invoice, stripe_price, stripe_plan, stripe_invoice_line, GetKubeNodeLabelsMessage, CreateWorkflowInstanceMessage, WorkitemFile, InsertOrUpdateManyMessage } from "@openiap/openflow-api";
import { StripeMessage, NoderedUtil, QueuedMessage, RegisterQueueMessage, QueueMessage, CloseQueueMessage, ListCollectionsMessage, DropCollectionMessage, QueryMessage, AggregateMessage, InsertOneMessage, UpdateOneMessage, Base, UpdateManyMessage, InsertOrUpdateOneMessage, DeleteOneMessage, MapReduceMessage, SigninMessage, TokenUser, User, Rights, EnsureNoderedInstanceMessage, DeleteNoderedInstanceMessage, DeleteNoderedPodMessage, RestartNoderedInstanceMessage, GetNoderedInstanceMessage, GetNoderedInstanceLogMessage, SaveFileMessage, WellknownIds, GetFileMessage, UpdateFileMessage, NoderedUser, WatchMessage, GetDocumentVersionMessage, DeleteManyMessage, InsertManyMessage, RegisterExchangeMessage, EnsureCustomerMessage, Customer, stripe_tax_id, Role, SelectCustomerMessage, Rolemember, ResourceUsage, Resource, ResourceVariant, stripe_subscription, GetNextInvoiceMessage, stripe_invoice, stripe_price, stripe_plan, stripe_invoice_line, GetKubeNodeLabelsMessage, CreateWorkflowInstanceMessage, WorkitemFile, InsertOrUpdateManyMessage, Ace } from "@openiap/openflow-api";
import { stripe_customer, stripe_list, StripeAddPlanMessage, StripeCancelPlanMessage, stripe_subscription_item, stripe_coupon } from "@openiap/openflow-api";
import { amqpwrapper, QueueMessageOptions } from "../amqpwrapper";
import { WebSocketServerClient } from "../WebSocketServerClient";
Expand Down Expand Up @@ -3713,6 +3713,48 @@ export class Message {
}
} catch (error) {
}

// if (Config.NODE_ENV != "production") {
// let ui: number = 0;
// let updatecount: number = 0;
// try {
// let cursor: Cursor<any>;
// cursor = Config.db.db.collection("dbusage").find({})
// for await (const u of cursor) {
// ui++;
// var item: Base = u;
// var needsupdate: boolean = false;

// // @ts-ignore
// var exists = item._acl.filter(x => x._id == item.userid);
// if (exists.length == 0) {
// // @ts-ignore
// Base.addRight(item, item.userid, item.name, [Rights.read]);
// }
// for (let i = item._acl.length - 1; i >= 0; i--) {
// {
// const ace = item._acl[i];
// if (typeof ace.rights === "string") {
// const b = new Binary(Buffer.from(ace.rights, "base64"), 0);
// (ace.rights as any) = b;
// needsupdate = true;
// }
// }
// }
// if (needsupdate) {
// updatecount++;
// await Config.db.db.collection("dbusage").updateOne({ _id: item._id },
// { $set: { "_acl": item._acl } });
// }
// if ((ui % 500 == 0)) {
// Logger.instanse.info("Housekeeping", "_Housekeeping", "Processed " + ui + " items so far, and updated " + updatecount + " items.");
// }
// }
// } catch (error) {
// Logger.instanse.error("Housekeeping", "_Housekeeping", error);
// span?.recordException(error);
// }
// }
try {
await Config.db.ensureindexes(span);
} catch (error) {
Expand Down Expand Up @@ -3957,6 +3999,15 @@ export class Message {
item = Config.db.ensureResource(item, "dbusage");
item = await Config.db.CleanACL(item, tuser, "dbusage", span);
Base.addRight(item, item.userid, item.name, [Rights.read]);
for (let i = item._acl.length - 1; i >= 0; i--) {
{
const ace = item._acl[i];
if (typeof ace.rights === "string") {
const b = new Binary(Buffer.from(ace.rights, "base64"), 0);
(ace.rights as any) = b;
}
}
}
delete item._id;
item.username = item.name;
item.name = item.name + " / " + col.name + " / " + this.formatBytes(item.size);
Expand Down Expand Up @@ -4473,21 +4524,30 @@ export class Message {
wi.wiqid = _wiq._id;
wi.nextrun = new Date(new Date().toISOString());
wi.nextrun.setSeconds(wi.nextrun.getSeconds() + _wiq.initialdelay);
for (let i = _wiq._acl.length - 1; i >= 0; i--) {
const ace = _wiq._acl[i];
let bits = [];
if (ace.rights == "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8=") {
bits = [-1];
} else {
for (let y = 0; y < ace.ace_right_bits; y++) {
if (Ace.isBitSet(ace, y)) bits.push(y);
}
}
Base.addRight(wi, ace._id, ace.name, bits);
}
for (var i = 0; i < wi.files.length; i++) {
var _f = wi.files[i];
var file = await this._GetFile(_f._id, false);

const metadata = new Base();
(metadata as any).wi = wi._id;
(metadata as any).wiq = _wiq.name;
(metadata as any).wiqid = _wiq._id;

metadata._acl = _wiq._acl;
metadata._acl = wi._acl;
metadata.name = path.basename(_f.filename);
(metadata as any).filename = _f.filename;
(metadata as any).path = path.dirname(_f.filename);
if ((metadata as any).path == ".") (metadata as any).path = "";

_f._id = await this._addFile(file, _f.filename, null, metadata, false, jwt);
}
wi = await Config.db.InsertOne(wi, "workitems", 1, true, jwt, parent);
Expand Down
24 changes: 17 additions & 7 deletions OpenFlow/src/public/Controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4279,7 +4279,7 @@ export class HistoryCtrl extends entitiesCtrl<Base> {
});
this.models = await NoderedUtil.Query({
collectionname: this.collection + "_hist", query: { id: this.id },
projection: { name: 1, _createdby: 1, _modified: 1, _deleted: 1, _version: 1, _type: 1 }, orderby: this.orderby
projection: { name: 1, _createdby: 1, _modified: 1, _deleted: 1, _deletedby: 1, _version: 1, _type: 1 }, orderby: this.orderby
});
if (!this.$scope.$$phase) { this.$scope.$apply(); }
}
Expand Down Expand Up @@ -5632,7 +5632,7 @@ export class DeletedCtrl extends entitiesCtrl<Base> {
this.autorefresh = true;
this.basequery = {};
this.collection = $routeParams.collection;
this.baseprojection = { _type: 1, type: 1, name: 1, _created: 1, _createdby: 1, _modified: 1, _deleted: 1 };
this.baseprojection = { _type: 1, type: 1, name: 1, _created: 1, _createdby: 1, _modified: 1, _deleted: 1, _deletedby: 1 };
this.orderby = { "_deleted": -1 }
this.postloadData = this.processdata;
if (this.userdata.data.DeletedCtrl) {
Expand Down Expand Up @@ -5693,11 +5693,20 @@ export class DeletedCtrl extends entitiesCtrl<Base> {
}

}
this.models = await NoderedUtil.Query({
collectionname: this.collection + "_hist",
query, projection: { name: 1, _type: 1, _createdby: 1, _created: 1, _modified: 1, _deleted: 1, _version: 1, id: 1 },
orderby: this.orderby
});
if (this.page == 0) {
this.models = await NoderedUtil.Query({
collectionname: this.collection + "_hist",
query, projection: { name: 1, _type: 1, _createdby: 1, _created: 1, _modified: 1, _deleted: 1, _deletedby: 1, _version: 1, id: 1 },
orderby: this.orderby
});
} else {
var temp = await NoderedUtil.Query({
collectionname: this.collection + "_hist",
query, projection: { name: 1, _type: 1, _createdby: 1, _created: 1, _modified: 1, _deleted: 1, _deletedby: 1, _version: 1, id: 1, skip: this.pagesize * this.page },
orderby: this.orderby
});
this.models = this.models.concat(temp);
}
this.loading = false;
this.processdata();
}
Expand Down Expand Up @@ -5737,6 +5746,7 @@ export class CustomersCtrl extends entitiesCtrl<Provider> {
this.basequery = { _type: "customer" };
this.collection = "users";
this.skipcustomerfilter = true;
this.baseprojection = { _type: 1, type: 1, name: 1, _created: 1, _createdby: 1, _modified: 1, dbusage: 1 };
WebSocketClientService.onSignedin((user: TokenUser) => {
this.loadData();
});
Expand Down
14 changes: 13 additions & 1 deletion OpenFlow/src/public/Customers.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<style type="text/css">
.dbusage {
/* width: 80px; */
white-space:nowrap
}
</style>
<div class="row">
<h1 translate lib="web">customers</h1>
</div>
Expand All @@ -9,10 +15,11 @@ <h1 translate lib="web">customers</h1>
</div>
<div ng-show="ctrl.errormessage != ''" class=" alert alert-danger" role="alert">{{ctrl.errormessage}}</div>
<table id="table1" class="table table-striped" when-scrolled="ctrl.more()" style="width: 100%;">
<caption>Customers</caption>
<caption></caption>
<thead class="thead-dark">
<tr>
<th ng-click="ctrl.ToggleOrder('name')" scope="col"><strong translate lib="web">name</strong></th>
<th ng-click="ctrl.ToggleOrder('dbusage')" class="dbusage"><b translate lib="web">dbusage</b></th>
<th class="w-150" ng-click="ctrl.ToggleOrder('_created')" scope="col"><strong translate lib="web">created</strong>
</th>
<th class="w-150" scope="col"></th>
Expand All @@ -21,6 +28,11 @@ <h1 translate lib="web">customers</h1>
<tbody>
<tr ng-repeat="model in ctrl.models">
<td><a style="color: inherit; text-decoration: inherit;" ng-href="#/Customer/{{model._id}}">{{model.name}}</a></td>
<td class="dbusage">
<div >
<format-bytes ng-model="model.dbusage" />
</div>
</td>
<td>
<timesince ng-model="model._created" />
</td>
Expand Down
10 changes: 7 additions & 3 deletions OpenFlow/src/public/Deleted.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ <h1 translate lib="web">deleted entities</h1>
<th scope="col" ng-click="ctrl.ToggleOrder('name')"><b translate lib="web">name</b></th>
<th scope="col" ng-click="ctrl.ToggleOrder('_type')"><b translate lib="web">type</b></th>
<!-- <th scope="col" ng-click="ctrl.ToggleOrder('_createdby')"><b translate lib="web">createdby</b></th> -->
<th scope="col" ng-click="ctrl.ToggleOrder('_created')"><b translate lib="web">deleted</b></th>
<th scope="col" ng-click="ctrl.ToggleOrder('_created')"><b translate lib="web">created</b></th>
<th scope="col" ng-click="ctrl.ToggleOrder('_deleted')"><b translate lib="web">deleted</b></th>
<th scope="col" ng-click="ctrl.ToggleOrder('_deletedby')"><b translate lib="web">by</b></th>
<!-- <th scope="col" ng-click="ctrl.ToggleOrder('_created')"><b translate lib="web">created</b></th> -->
<th scope="col" ng-click="ctrl.ToggleOrder('_modified')"><b translate lib="web">updated</b></th>
<th></th>
</tr>
Expand All @@ -44,8 +45,11 @@ <h1 translate lib="web">deleted entities</h1>
<timesince ng-model="model._deleted" />
</td>
<td>
<timesince ng-model="model._created" />
{{ model._deletedby }}
</td>
<!-- <td>
<timesince ng-model="model._created" />
</td> -->
<td>
<timesince ng-model="model._modified" />
</td>
Expand Down
2 changes: 1 addition & 1 deletion OpenFlowNodeRED/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openiap/nodered",
"version": "1.4.16",
"version": "1.4.17",
"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)",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion OpenFlowNodeRED/src/nodered/nodes/googleauth.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
});
});
$('#node-config-input-setcode').click(() => {
$.getJSON('googleauth-set-code', { code: $('#node-config-input-code').val() }, function (data) {
$.getJSON('/googleauth-set-code', { code: $('#node-config-input-code').val() }, function (data) {
$('#code').hide();
$('#tokens').show();
$('#node-config-input-tokens').val(JSON.stringify(data.tokens));
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.16
1.4.17
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openiap/openflow",
"version": "1.4.16",
"version": "1.4.17",
"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)",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 9feaae8

Please sign in to comment.