Fix: Better type checking

This commit is contained in:
Daniel Hougaard
2024-03-12 15:56:01 +01:00
parent 2bd9914373
commit c3a56f469a
7 changed files with 30 additions and 25 deletions

View File

@ -32,7 +32,7 @@ export type TGetSamlCfgDTO =
actor: ActorType;
actorId: string;
actorAuthMethod: ActorAuthMethod;
actorOrgId?: string;
actorOrgId: string | undefined;
}
| {
type: "orgSlug";

View File

@ -5,7 +5,7 @@ export type TOrgPermission = {
actorId: string;
orgId: string;
actorAuthMethod: ActorAuthMethod;
actorOrgId?: string;
actorOrgId: string | undefined;
};
export type TProjectPermission = {
@ -13,7 +13,7 @@ export type TProjectPermission = {
actorId: string;
projectId: string;
actorAuthMethod: AuthMethod | null;
actorOrgId?: string;
actorOrgId: string | undefined;
};
export type RequiredKeys<T> = {

View File

@ -28,7 +28,7 @@ export const orgRoleServiceFactory = ({ orgRoleDAL, permissionService }: TOrgRol
orgId: string,
data: Omit<TOrgRolesInsert, "orgId">,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission } = await permissionService.getUserOrgPermission(userId, orgId, actorAuthMethod, actorOrgId);
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.Role);
@ -48,7 +48,7 @@ export const orgRoleServiceFactory = ({ orgRoleDAL, permissionService }: TOrgRol
roleId: string,
data: Omit<TOrgRolesUpdate, "orgId">,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission } = await permissionService.getUserOrgPermission(userId, orgId, actorAuthMethod, actorOrgId);
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Role);
@ -70,7 +70,7 @@ export const orgRoleServiceFactory = ({ orgRoleDAL, permissionService }: TOrgRol
orgId: string,
roleId: string,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission } = await permissionService.getUserOrgPermission(userId, orgId, actorAuthMethod, actorOrgId);
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Delete, OrgPermissionSubjects.Role);
@ -80,7 +80,12 @@ export const orgRoleServiceFactory = ({ orgRoleDAL, permissionService }: TOrgRol
return deletedRole;
};
const listRoles = async (userId: string, orgId: string, actorAuthMethod: ActorAuthMethod, actorOrgId?: string) => {
const listRoles = async (
userId: string,
orgId: string,
actorAuthMethod: ActorAuthMethod,
actorOrgId: string | undefined
) => {
const { permission } = await permissionService.getUserOrgPermission(userId, orgId, actorAuthMethod, actorOrgId);
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Role);
const customRoles = await orgRoleDAL.find({ orgId });
@ -128,7 +133,7 @@ export const orgRoleServiceFactory = ({ orgRoleDAL, permissionService }: TOrgRol
userId: string,
orgId: string,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission, membership } = await permissionService.getUserOrgPermission(
userId,

View File

@ -82,7 +82,7 @@ export const orgServiceFactory = ({
userId: string,
orgId: string,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
await permissionService.getUserOrgPermission(userId, orgId, actorAuthMethod, actorOrgId);
const org = await orgDAL.findOrgById(orgId);
@ -103,7 +103,7 @@ export const orgServiceFactory = ({
userId: string,
orgId: string,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission } = await permissionService.getUserOrgPermission(userId, orgId, actorAuthMethod, actorOrgId);
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Member);
@ -330,7 +330,7 @@ export const orgServiceFactory = ({
userId: string,
orgId: string,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { membership } = await permissionService.getUserOrgPermission(userId, orgId, actorAuthMethod, actorOrgId);
if ((membership.role as OrgMembershipRole) !== OrgMembershipRole.Admin)
@ -613,7 +613,7 @@ export const orgServiceFactory = ({
userId: string,
orgId: string,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission } = await permissionService.getUserOrgPermission(userId, orgId, actorAuthMethod, actorOrgId);
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.IncidentAccount);
@ -626,7 +626,7 @@ export const orgServiceFactory = ({
orgId: string,
email: string,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission } = await permissionService.getUserOrgPermission(userId, orgId, actorAuthMethod, actorOrgId);
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.IncidentAccount);
@ -647,7 +647,7 @@ export const orgServiceFactory = ({
orgId: string,
id: string,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission } = await permissionService.getUserOrgPermission(userId, orgId, actorAuthMethod, actorOrgId);
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Delete, OrgPermissionSubjects.IncidentAccount);

View File

@ -7,7 +7,7 @@ export type TUpdateOrgMembershipDTO = {
orgId: string;
membershipId: string;
role: string;
actorOrgId?: string;
actorOrgId: string | undefined;
actorAuthMethod: ActorAuthMethod;
};
@ -15,14 +15,14 @@ export type TDeleteOrgMembershipDTO = {
userId: string;
orgId: string;
membershipId: string;
actorOrgId?: string;
actorOrgId: string | undefined;
actorAuthMethod: ActorAuthMethod;
};
export type TInviteUserToOrgDTO = {
userId: string;
orgId: string;
actorOrgId?: string;
actorOrgId: string | undefined;
actorAuthMethod: ActorAuthMethod;
inviteeEmail: string;
};
@ -45,7 +45,7 @@ export type TFindOrgMembersByEmailDTO = {
export type TFindAllWorkspacesDTO = {
actor: ActorType;
actorId: string;
actorOrgId?: string;
actorOrgId: string | undefined;
actorAuthMethod: ActorAuthMethod;
orgId: string;
};

View File

@ -30,7 +30,7 @@ export const projectRoleServiceFactory = ({ projectRoleDAL, permissionService }:
projectId: string,
data: Omit<TProjectRolesInsert, "projectId">,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission } = await permissionService.getProjectPermission(
actor,
@ -57,7 +57,7 @@ export const projectRoleServiceFactory = ({ projectRoleDAL, permissionService }:
roleId: string,
data: Omit<TOrgRolesUpdate, "orgId">,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission } = await permissionService.getProjectPermission(
actor,
@ -86,7 +86,7 @@ export const projectRoleServiceFactory = ({ projectRoleDAL, permissionService }:
projectId: string,
roleId: string,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission } = await permissionService.getProjectPermission(
actor,
@ -107,7 +107,7 @@ export const projectRoleServiceFactory = ({ projectRoleDAL, permissionService }:
actorId: string,
projectId: string,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission } = await permissionService.getProjectPermission(
actor,
@ -172,7 +172,7 @@ export const projectRoleServiceFactory = ({ projectRoleDAL, permissionService }:
userId: string,
projectId: string,
actorAuthMethod: ActorAuthMethod,
actorOrgId?: string
actorOrgId: string | undefined
) => {
const { permission, membership } = await permissionService.getUserProjectPermission(
userId,

View File

@ -33,7 +33,7 @@ export type TDeleteProjectBySlugDTO = {
slug: string;
actor: ActorType;
actorId: string;
actorOrgId?: string;
actorOrgId: string | undefined;
};
export type TGetProjectDTO = {
@ -60,7 +60,7 @@ export type TDeleteProjectDTO = {
filter: Filter;
actor: ActorType;
actorId: string;
actorOrgId?: string;
actorOrgId: string | undefined;
} & Omit<TProjectPermission, "projectId">;
export type TUpgradeProjectDTO = {