Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 9 additions & 10 deletions client/cli/generate-permissions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import * as fs from 'fs';
import * as yaml from 'js-yaml';
import * as path from 'path';
import dedent from 'ts-dedent';

import { overloadJsFunctions } from 'src/app/infrastructure/utils/overload-js-functions';
import dedent from 'ts-dedent';

overloadJsFunctions();

const SOURCE = path.resolve(path.join(__dirname, '../meta/permission.yml'));
const SOURCE = path.resolve(path.join(__dirname, '../../meta/permission.yml'));

const BASE_PATH = path.resolve(path.join(__dirname, `..`));
const DOMAIN_DEFINITIONS_PATH = `src/app/domain/definitions`;
Expand All @@ -33,21 +32,21 @@ const FILE_TEMPLATE_PERMISSION_RELATIONS = dedent`
import { PermissionsMap } from './permission.config';
`;

const permissionMap: { [permission: string]: PermissionNode } = {};
const permissionMap: Record<string, PermissionNode> = {};

/**
* Helper class to generate the permission graph. Holds information about its permission as well as
* its parents and children.
*/
class PermissionNode {
parents: PermissionNode[] = [];
children: PermissionNode[] = [];
permission: string;
enumKey: string;
public parents: PermissionNode[] = [];
public children: PermissionNode[] = [];
public permission: string;
public enumKey: string;

public constructor(permission: string) {
this.permission = permission;
this.enumKey = permission.replace(/[_\.]([a-z])/g, (_, c) => c.toUpperCase());
this.enumKey = permission.replace(/[_.]([a-z])/g, (_, c) => c.toUpperCase());
}
}

Expand Down Expand Up @@ -137,7 +136,7 @@ function writePermissionRelations(nodes: PermissionNode[]): void {
* @returns a set of all relatives of the given node in the given direction
*/
function getPermissionRelatives(node: PermissionNode, field: PermissionNodeRelativesField): Set<PermissionNode> {
let relatives = new Set<PermissionNode>();
const relatives = new Set<PermissionNode>();
for (const relative of node[field]) {
relatives.add(relative);
relatives.update(getPermissionRelatives(relative, field));
Expand Down
260 changes: 260 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading