Skip to content

Commit 73860a3

Browse files
committed
add queryas to query
1 parent 0d1d2a2 commit 73860a3

7 files changed

Lines changed: 51 additions & 58 deletions

File tree

OpenFlow/src/DatabaseConnection.ts

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export class DatabaseConnection {
188188
* @returns Promise<T[]> Array of results
189189
*/
190190
// tslint:disable-next-line: max-line-length
191-
async query<T extends Base>(query: any, projection: Object, top: number, skip: number, orderby: Object | string, collectionname: string, jwt: string): Promise<T[]> {
191+
async query<T extends Base>(query: any, projection: Object, top: number, skip: number, orderby: Object | string, collectionname: string, jwt: string, queryas: string = null): Promise<T[]> {
192192
var arr: T[] = [];
193193
await this.connect();
194194
var mysort: Object = {};
@@ -236,13 +236,22 @@ export class DatabaseConnection {
236236
var _query: Object = {};
237237
if (collectionname === "files") { collectionname = "fs.files"; }
238238
if (collectionname === "fs.files") {
239-
_query = { $and: [query, this.getbasequery(jwt, "metadata._acl", [Rights.read])] };
239+
if (!Util.IsNullEmpty(queryas)) {
240+
_query = { $and: [query, this.getbasequery(jwt, "metadata._acl", [Rights.read]), await this.getbasequeryuserid(queryas, "metadata._acl", [Rights.read])] };
241+
} else {
242+
_query = { $and: [query, this.getbasequery(jwt, "metadata._acl", [Rights.read])] };
243+
}
240244
projection = null;
241245
} else {
242-
if (!collectionname.endsWith("_hist")) {
243-
_query = { $and: [query, this.getbasequery(jwt, "_acl", [Rights.read])] };
246+
// if (!collectionname.endsWith("_hist")) {
247+
// _query = { $and: [query, this.getbasequery(jwt, "_acl", [Rights.read])] };
248+
// } else {
249+
// // todo: enforcer permissions when fetching _hist ?
250+
// _query = { $and: [query, this.getbasequery(jwt, "_acl", [Rights.read])] };
251+
// }
252+
if (!Util.IsNullEmpty(queryas)) {
253+
_query = { $and: [query, this.getbasequery(jwt, "_acl", [Rights.read]), await this.getbasequeryuserid(queryas, "_acl", [Rights.read])] };
244254
} else {
245-
// todo: enforcer permissions when fetching _hist ?
246255
_query = { $and: [query, this.getbasequery(jwt, "_acl", [Rights.read])] };
247256
}
248257
}
@@ -936,31 +945,13 @@ export class DatabaseConnection {
936945
};
937946
finalor.push(q2);
938947
}
939-
//
940-
// if (bits.length > 0 && (bits[0] + 1) == Rights.read) {
941-
// this._logger.debug("[" + user.username + "] Include isme in base query");
942-
// return { $or: finalor.concat(isme) };
943-
// } else if (bits.length > 0) {
944-
// this._logger.debug("[" + user.username + "] Skip isme in base query, not read (" + bits[0] + ")");
945-
// } else {
946-
// this._logger.debug("[" + user.username + "] Skip isme in base query, bits missing!");
947-
// }
948-
// if(bits.length==1 && (bits[0]+1) == Rights.read)
949-
// {
950-
// for (var i: number = 0; i < user.roles.length; i++) {
951-
// var role = user.roles[i];
952-
// if(role._id!=WellknownIds.admins && role._id!=WellknownIds.robots && role._id!=WellknownIds.nodered_users &&
953-
// role._id!=WellknownIds.nodered_admins && role._id!=WellknownIds.nodered_api_users && role._id!=WellknownIds.filestore_users &&
954-
// role._id!=WellknownIds.filestore_admins && role._id!=WellknownIds.robot_users && role._id!=WellknownIds.robot_admins
955-
// && role._id!=WellknownIds.personal_nodered_users)
956-
// {
957-
958-
// }
959-
// }
960-
961-
// }
962948
return { $or: finalor.concat() };
963949
}
950+
private async getbasequeryuserid(userid: string, field: string, bits: number[]): Promise<Object> {
951+
var user = await User.FindByUsernameOrId(null, userid);
952+
var jwt = Crypt.createToken(user, "5m");
953+
return this.getbasequery(jwt, field, bits);
954+
}
964955
/**
965956
* Ensure _type and _acs on object
966957
* @param {T} item Object to validate

OpenFlow/src/Messages/Message.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export class Message {
342342
try {
343343
msg = QueryMessage.assign(this.data);
344344
if (Util.IsNullEmpty(msg.jwt)) { msg.jwt = cli.jwt; }
345-
msg.result = await Config.db.query(msg.query, msg.projection, msg.top, msg.skip, msg.orderby, msg.collectionname, msg.jwt);
345+
msg.result = await Config.db.query(msg.query, msg.projection, msg.top, msg.skip, msg.orderby, msg.collectionname, msg.jwt, msg.queryas);
346346
} catch (error) {
347347
cli._logger.error(error);
348348
if (Util.IsNullUndefinded(msg)) { (msg as any) = {}; }

OpenFlow/src/Messages/QueryMessage.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import { Base } from "../base";
22

33
export class QueryMessage<T extends Base> implements IReplyMessage {
44
public error: string;
5-
public jwt:any;
5+
public jwt: any;
66

7-
public query:any;
8-
public projection:Object;
9-
public top:number;
10-
public skip:number;
11-
public orderby:Object | string;
12-
public collectionname:string;
13-
public result:T[];
14-
static assign<T extends Base>(o:any):QueryMessage<T> {
7+
public query: any;
8+
public projection: Object;
9+
public top: number;
10+
public skip: number;
11+
public orderby: Object | string;
12+
public collectionname: string;
13+
public result: T[];
14+
public queryas: string;
15+
static assign<T extends Base>(o: any): QueryMessage<T> {
1516
if (typeof o === "string" || o instanceof String) {
1617
return Object.assign(new QueryMessage(), JSON.parse(o.toString()));
1718
}

OpenFlowNodeRED/src/Message.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class QueryMessage {
9393
public orderby: Object | string;
9494
public collectionname: string;
9595
public result: any[];
96+
public queryas: string;
9697
static assign(o: any): QueryMessage {
9798
if (typeof o === "string" || o instanceof String) {
9899
return Object.assign(new QueryMessage(), JSON.parse(o.toString()));

OpenFlowNodeRED/src/nodered/nodes/NoderedUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ export class NoderedUtil {
7474

7575

7676

77-
public static async Query(collection: string, query: any, projection: any, orderby: any, top: number, skip: number, jwt: string): Promise<any[]> {
77+
public static async Query(collection: string, query: any, projection: any, orderby: any, top: number, skip: number, jwt: string, queryas: string = null): Promise<any[]> {
7878
var q: QueryMessage = new QueryMessage(); q.collectionname = collection;
79-
q.orderby = orderby; q.projection = projection;
79+
q.orderby = orderby; q.projection = projection; q.queryas = queryas;
8080
//q.query = query;
8181
q.query = JSON.stringify(query, (key, value) => {
8282
var t = typeof value;

OpenFlowNodeRED/src/nodered/nodes/rpa_nodes.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,25 @@ export async function get_rpa_workflows(req, res) {
220220
var token = await NoderedUtil.GetTokenFromSAML(rawAssertion);
221221
var q: any = { _type: "workflow" };
222222
if (req.query.queue != null && req.query.queue != undefined && req.query.queue != "" && req.query.queue != "none") {
223-
q = {
224-
_type: "workflow",
225-
$or: [
226-
{ _createdbyid: req.query.queue },
227-
{ _modifiedbyid: req.query.queue },
228-
{
229-
_acl: {
230-
$elemMatch: {
231-
rights: { $bitsAllSet: [2] },
232-
deny: false,
233-
_id: req.query.queue
234-
}
235-
}
236-
}
237-
]
238-
};
223+
// q = {
224+
// _type: "workflow",
225+
// $or: [
226+
// { _createdbyid: req.query.queue },
227+
// { _modifiedbyid: req.query.queue },
228+
// {
229+
// _acl: {
230+
// $elemMatch: {
231+
// rights: { $bitsAllSet: [2] },
232+
// deny: false,
233+
// _id: req.query.queue
234+
// }
235+
// }
236+
// }
237+
// ]
238+
// };
239239
}
240240
var result: any[] = await NoderedUtil.Query('openrpa', q,
241-
{ name: 1 }, { name: -1 }, 1000, 0, token.jwt)
241+
{ name: 1 }, { name: -1 }, 1000, 0, token.jwt, req.query.queue)
242242
res.json(result);
243243
} catch (error) {
244244
res.status(500).json(error);

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.401
1+
0.0.402

0 commit comments

Comments
 (0)