Skip to content

Commit

Permalink
init userroles and permission on dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Chakravarthy7102 committed Oct 16, 2023
1 parent d415dd1 commit cc81759
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/ts/recipe/dashboard/api/userroles/roles/allRoles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { getAllRoles, getPermissionsForRole } from "../../../../userroles";

import { APIFunction, APIInterface, APIOptions } from "../../../types";

type Roles = Array<{ role: string; permissions: string[] }>;

const allRoles: APIFunction = async (
_: APIInterface,
__: string,
___: APIOptions,
userContext: any
): Promise<{
status: "OK";
roles: Roles;
}> => {
const response = await getAllRoles(userContext);

let roles: Roles = [];

for (let i = 0; i < response.roles.length; i++) {
const role = response.roles[i];
try {
const res = await getPermissionsForRole(role);

if (res.status === "OK") {
roles.push({
role,
permissions: res.permissions,
});
}
} catch (_) {}
}

return {
roles,
status: "OK",
};
};

export default allRoles;
2 changes: 2 additions & 0 deletions lib/ts/recipe/dashboard/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ export const SEARCH_TAGS_API = "/api/search/tags";
export const DASHBOARD_ANALYTICS_API = "/api/analytics";
export const TENANTS_LIST_API = "/api/tenants/list";

export const USERROLES_LIST_API = "/api/userroles/roles";

export const UNLINK_USER = "/api/user/unlink";
10 changes: 10 additions & 0 deletions lib/ts/recipe/dashboard/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
USER_SESSIONS_API,
VALIDATE_KEY_API,
UNLINK_USER,
USERROLES_LIST_API,
} from "./constants";
import NormalisedURLPath from "../../normalisedURLPath";
import type { BaseRequest, BaseResponse } from "../../framework";
Expand All @@ -63,6 +64,7 @@ import { getSearchTags } from "./api/search/tagsGet";
import analyticsPost from "./api/analytics";
import listTenants from "./api/listTenants";
import { userUnlink } from "./api/userdetails/userUnlinkGet";
import { getAllRoles } from "../userroles";

export default class Recipe extends RecipeModule {
private static instance: Recipe | undefined = undefined;
Expand Down Expand Up @@ -253,6 +255,12 @@ export default class Recipe extends RecipeModule {
disabled: false,
method: "get",
},
{
id: USERROLES_LIST_API,
pathWithoutApiBasePath: new NormalisedURLPath(getApiPathWithDashboardBase(USERROLES_LIST_API)),
disabled: false,
method: "get",
},
];
};

Expand Down Expand Up @@ -345,6 +353,8 @@ export default class Recipe extends RecipeModule {
apiFunction = listTenants;
} else if (id === UNLINK_USER) {
apiFunction = userUnlink;
} else if (id === USERROLES_LIST_API) {
apiFunction = getAllRoles;
}

// If the id doesnt match any APIs return false
Expand Down

0 comments on commit cc81759

Please sign in to comment.