UNPKG

@backstage-community/plugin-rbac-backend

Version:
55 lines (51 loc) 1.81 kB
'use strict'; var ancestorSearchMemo = require('./ancestor-search-memo.cjs.js'); class AncestorSearchMemoPG extends ancestorSearchMemo.AncestorSearchMemo { constructor(userEntityRef, catalogDBClient, maxDepth) { super(); this.userEntityRef = userEntityRef; this.catalogDBClient = catalogDBClient; this.maxDepth = maxDepth; } async getAllASMGroups() { try { const rows = await this.catalogDBClient("relations").select("source_entity_ref", "target_entity_ref").where("type", "childOf"); return rows; } catch (error) { return []; } } async getUserASMGroups() { try { const rows = await this.catalogDBClient("relations").select("source_entity_ref", "target_entity_ref").where({ type: "memberOf", source_entity_ref: this.userEntityRef }); return rows; } catch (error) { return []; } } traverse(relation, allRelations, current_depth) { if (this.maxDepth !== void 0 && current_depth >= this.maxDepth + 1) { return; } const depth = current_depth + 1; if (!super.hasEntityRef(relation.source_entity_ref)) { super.setNode(relation.source_entity_ref); } super.setEdge(relation.target_entity_ref, relation.source_entity_ref); const parentGroup = allRelations.find( (g) => g.source_entity_ref === relation.target_entity_ref ); if (parentGroup && super.isAcyclic()) { this.traverse(parentGroup, allRelations, depth); } } async buildUserGraph() { const userRelations = await this.getUserASMGroups(); const allRelations = await this.getAllASMGroups(); userRelations.forEach( (group) => this.traverse(group, allRelations, 0) ); } } exports.AncestorSearchMemoPG = AncestorSearchMemoPG; //# sourceMappingURL=ancestor-search-memo-pg.cjs.js.map