mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-20 14:42:51 +00:00
feat: switched up all dal except policy ones
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
import { ForbiddenError } from "@casl/ability";
|
||||
|
||||
import { AccessScope } from "@app/db/schemas";
|
||||
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
||||
import {
|
||||
orgAdminPermissions,
|
||||
orgMemberPermissions,
|
||||
orgNoAccessPermissions,
|
||||
OrgPermissionActions,
|
||||
OrgPermissionSubjects
|
||||
} from "@app/ee/services/permission/org-permission";
|
||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||
import { BadRequestError } from "@app/lib/errors";
|
||||
|
||||
import { TRoleScopeFactory } from "../role-types";
|
||||
import { isCustomOrgRole } from "@app/services/org/org-role-fns";
|
||||
|
||||
type TOrgRoleScopeFactoryDep = {
|
||||
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
|
||||
@@ -19,6 +26,8 @@ export const newOrgRoleFactory = ({ permissionService }: TOrgRoleScopeFactoryDep
|
||||
throw new BadRequestError({ message: "Invalid scope provided for the factory" });
|
||||
};
|
||||
|
||||
const isCustomRole: TRoleScopeFactory["isCustomRole"] = (role: string) => isCustomOrgRole(role);
|
||||
|
||||
const onCreateRoleGuard: TRoleScopeFactory["onCreateRoleGuard"] = async (dto) => {
|
||||
const { permission } = await permissionService.getOrgPermission(
|
||||
dto.permission.type,
|
||||
@@ -85,6 +94,42 @@ export const newOrgRoleFactory = ({ permissionService }: TOrgRoleScopeFactoryDep
|
||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Role);
|
||||
};
|
||||
|
||||
const getPredefinedRoles: TRoleScopeFactory["getPredefinedRoles"] = async (scopeData) => {
|
||||
const scopeField = getScopeField(scopeData);
|
||||
return [
|
||||
{
|
||||
id: "b11b49a9-09a9-4443-916a-4246f9ff2c69", // dummy userid
|
||||
name: "Admin",
|
||||
slug: "admin",
|
||||
orgId: scopeField.value,
|
||||
description: "Complete administration access over the organization",
|
||||
permissions: orgAdminPermissions,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date()
|
||||
},
|
||||
{
|
||||
id: "b11b49a9-09a9-4443-916a-4246f9ff2c70", // dummy user for zod validation in response
|
||||
name: "Member",
|
||||
slug: "member",
|
||||
orgId: scopeField.value,
|
||||
description: "Non-administrative role in an organization",
|
||||
permissions: orgMemberPermissions,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date()
|
||||
},
|
||||
{
|
||||
id: "b10d49a9-09a9-4443-916a-4246f9ff2c72", // dummy user for zod validation in response
|
||||
name: "No Access",
|
||||
slug: "no-access",
|
||||
orgId: scopeField.value,
|
||||
description: "No access to any resources in the organization",
|
||||
permissions: orgNoAccessPermissions,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date()
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
return {
|
||||
onCreateRoleGuard,
|
||||
onUpdateRoleGuard,
|
||||
@@ -92,6 +137,8 @@ export const newOrgRoleFactory = ({ permissionService }: TOrgRoleScopeFactoryDep
|
||||
onListRoleGuard,
|
||||
onGetRoleByIdGuard,
|
||||
onGetRoleBySlugGuard,
|
||||
getScopeField
|
||||
getScopeField,
|
||||
getPredefinedRoles,
|
||||
isCustomRole
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user