Split entities/security.ts into smaller files

Jens Pelzetter 2020-07-31 17:22:41 +02:00
parent 5741a04ac5
commit e01f10c2aa
5 changed files with 305 additions and 290 deletions

View File

@ -0,0 +1,71 @@
import { assertProperties } from "@libreccm/ccm-apiclient-commons";
import {
PartyId,
PartyRoleMembership,
buildPartyRoleMembershipFromRecord,
} from "./party";
export interface Group {
partyId: number;
uuid: string;
name: string;
memberships: GroupUserMembership[];
roleMemberships: PartyRoleMembership[];
}
export interface GroupUserMembership {
membershipId: number;
uuid: string;
user: PartyId;
}
export function buildGroupFromRecord(record: Record<string, unknown>): Group {
assertProperties(record, [
"partyId",
"uuid",
"name",
"memberships",
"roleMemberships",
]);
const membershipRecords = record.memberships as Record<string, unknown>[];
const roleMembershipRecords = record.roleMemberships as Record<
string,
unknown
>[];
return {
partyId: record.partyId as number,
uuid: record.uuid as string,
name: record.name as string,
memberships: membershipRecords.map((r) =>
buildGroupUserMembershipFromRecord(r)
),
roleMemberships: roleMembershipRecords.map((r) =>
buildPartyRoleMembershipFromRecord(r)
),
};
}
export function buildGroupUserMembershipFromRecord(
record: Record<string, unknown>
): GroupUserMembership {
assertProperties(record, ["membershipId", "uuid", "user"]);
return {
membershipId: record.membershipId as number,
uuid: record.uuid as string,
user: buildPartyIdFromRecord(record.user as Record<string, unknown>),
};
}
function buildPartyIdFromRecord(record: Record<string, unknown>): PartyId {
assertProperties(record, ["partyId", "uuid", "name"]);
return {
partyId: record.partyId as number,
uuid: record.uuid as string,
name: record.name as string,
};
}

View File

@ -0,0 +1,29 @@
import {
assertProperties
} from "@libreccm/ccm-apiclient-commons";
import { RoleId, buildRoleIdFromRecord } from "./role";
export interface PartyId {
partyId: number;
uuid: string;
name: string;
}
export interface PartyRoleMembership {
membershipId: number;
uuid: string;
role: RoleId;
}
export function buildPartyRoleMembershipFromRecord(
record: Record<string, unknown>
): PartyRoleMembership {
assertProperties(record, ["membershipId", "uuid", "role"]);
return {
membershipId: record.membershipId as number,
uuid: record.uuid as string,
role: buildRoleIdFromRecord(record.role as Record<string, unknown>),
};
}

View File

@ -0,0 +1,117 @@
import {
assertProperties,
LocalizedString,
} from "@libreccm/ccm-apiclient-commons";
import { CcmObjectId } from "./core";
import { TaskId } from "./workflow";
import { PartyId } from "./party";
export interface RoleAssignedTask {
taskAssignmentId: number;
uuid: string;
task: TaskId;
}
export interface Role {
roleId: number;
uuid: string;
name: string;
description: LocalizedString;
permissions: RolePermission[];
}
export interface RoleId {
roleId: number;
uuid: string;
name: string;
}
export interface RolePartyMembership {
membershipId: number;
uuid: string;
party: PartyId;
}
export interface RolePermission {
permissionId: number;
uuid: string;
grantedPrivilege: string;
inherited: boolean;
object: CcmObjectId;
creationUser: PartyId;
creationDate: Date;
creationIp: string;
inheritedFrom: CcmObjectId;
}
export function buildRoleFromRecord(record: Record<string, unknown>): Role {
assertProperties(record, [
"roleId",
"uuid",
"name",
"description",
"permissions",
]);
const permissionRecords = record.permissions as Record<string, unknown>[];
return {
roleId: record.roleId as number,
uuid: record.uuid as string,
name: record.name as string,
description: record.description as LocalizedString,
permissions: permissionRecords.map((r) =>
buildRolePermissionFromRecord(r)
),
};
}
export function buildRoleIdFromRecord(record: Record<string, unknown>): RoleId {
assertProperties(record, ["roleId", "uuid", "name"]);
return {
roleId: record.roleId as number,
uuid: record.uuid as string,
name: record.name as string,
};
}
export function buildRolePartyMembershipFromRecord(
record: Record<string, unknown>
): RolePartyMembership {
assertProperties(record, ["membershipId", "uuid", "party"]);
return {
membershipId: record.membershipId as number,
uuid: record.uuid as string,
party: record.party as PartyId,
};
}
export function buildRolePermissionFromRecord(
record: Record<string, unknown>
): RolePermission {
assertProperties(record, [
"permissionId",
"uuid",
"grantedPrivilege",
"inherited",
"object",
"creationUser",
"creationIp",
"inheritedFrom",
]);
return {
permissionId: record.permissionId as number,
uuid: record.uuid as string,
grantedPrivilege: record.grantedPrivilege as string,
inherited: record.inherited as boolean,
object: record.object as CcmObjectId,
creationUser: record.creationUser as PartyId,
creationDate: record.creationDate as Date,
creationIp: record.creationIp as string,
inheritedFrom: record.inheritedFrom as CcmObjectId,
};
}

View File

@ -1,290 +0,0 @@
import {
assertProperties,
LocalizedString,
} from "@libreccm/ccm-apiclient-commons";
import { CcmObjectId } from "./core";
import { TaskId } from "./workflow";
export interface EmailAddressData {
address: string;
bouncing: boolean;
verified: boolean;
}
export interface GroupData {
partyId: number;
uuid: string;
name: string;
memberships: GroupUserMembership[];
roleMemberships: PartyRoleMembership[];
}
export interface GroupUserMembership {
membershipId: number;
uuid: string;
user: PartyId;
}
export interface PartyId {
partyId: number;
uuid: string;
name: string;
}
export interface PartyRoleMembership {
membershipId: number;
uuid: string;
role: RoleId;
}
export interface RoleAssignedTask {
taskAssignmentId: number;
uuid: string;
task: TaskId;
}
export interface RoleData {
roleId: number;
uuid: string;
name: string;
description: LocalizedString;
permissions: RolePermission[];
}
export interface RoleId {
roleId: number;
uuid: string;
name: string;
}
export interface RolePartyMembership {
membershipId: number;
uuid: string;
party: PartyId;
}
export interface RolePermission {
permissionId: number;
uuid: string;
grantedPrivilege: string;
inherited: boolean;
object: CcmObjectId;
creationUser: PartyId;
creationDate: Date;
creationIp: string;
inheritedFrom: CcmObjectId;
}
export interface UserData {
partyId: number;
uuid: string;
name: string;
givenName: string;
familyName: string;
primaryEmailAddress: EmailAddressData;
emailAddresses: EmailAddressData[];
banned: boolean;
passwordResetRequired: boolean;
groupMemberships: UserGroupMembership[];
roleMemberships: PartyRoleMembership[];
}
export interface UserGroupMembership {
membershipId: number;
uuid: string;
group: PartyId;
}
export function buildGroupDataFromRecord(
record: Record<string, unknown>
): GroupData {
assertProperties(record, [
"partyId",
"uuid",
"name",
"memberships",
"roleMemberships",
]);
const membershipRecords = record.memberships as Record<string, unknown>[];
const roleMembershipRecords = record.roleMemberships as Record<
string,
unknown
>[];
return {
partyId: record.partyId as number,
uuid: record.uuid as string,
name: record.name as string,
memberships: membershipRecords.map((r) =>
buildGroupUserMembershipFromRecord(r)
),
roleMemberships: roleMembershipRecords.map((r) =>
buildPartyRoleMembershipFromRecord(r)
),
};
}
export function buildGroupUserMembershipFromRecord(
record: Record<string, unknown>
): GroupUserMembership {
assertProperties(record, ["membershipId", "uuid", "user"]);
return {
membershipId: record.membershipId as number,
uuid: record.uuid as string,
user: buildPartyIdFromRecord(record.user as Record<string, unknown>),
};
}
function buildPartyIdFromRecord(record: Record<string, unknown>): PartyId {
assertProperties(record, ["partyId", "uuid", "name"]);
return {
partyId: record.partyId as number,
uuid: record.uuid as string,
name: record.name as string,
};
}
export function buildPartyRoleMembershipFromRecord(
record: Record<string, unknown>
): PartyRoleMembership {
assertProperties(record, ["membershipId", "uuid", "role"]);
return {
membershipId: record.membershipId as number,
uuid: record.uuid as string,
role: buildRoleIdFromRecord(record.role as Record<string, unknown>),
};
}
export function buildRoleDataFromRecord(
record: Record<string, unknown>
): RoleData {
assertProperties(record, [
"roleId",
"uuid",
"name",
"description",
"permissions",
]);
const permissionRecords = record.permissions as Record<string, unknown>[];
return {
roleId: record.roleId as number,
uuid: record.uuid as string,
name: record.name as string,
description: record.description as LocalizedString,
permissions: permissionRecords.map((r) =>
buildRolePermissionFromRecord(r)
),
};
}
function buildRoleIdFromRecord(record: Record<string, unknown>): RoleId {
assertProperties(record, ["roleId", "uuid", "name"]);
return {
roleId: record.roleId as number,
uuid: record.uuid as string,
name: record.name as string,
};
}
export function buildRolePartyMembershipFromRecord(
record: Record<string, unknown>
): RolePartyMembership {
assertProperties(record, ["membershipId", "uuid", "party"]);
return {
membershipId: record.membershipId as number,
uuid: record.uuid as string,
party: record.party as PartyId,
};
}
export function buildRolePermissionFromRecord(
record: Record<string, unknown>
): RolePermission {
assertProperties(record, [
"permissionId",
"uuid",
"grantedPrivilege",
"inherited",
"object",
"creationUser",
"creationIp",
"inheritedFrom",
]);
return {
permissionId: record.permissionId as number,
uuid: record.uuid as string,
grantedPrivilege: record.grantedPrivilege as string,
inherited: record.inherited as boolean,
object: record.object as CcmObjectId,
creationUser: record.creationUser as PartyId,
creationDate: record.creationDate as Date,
creationIp: record.creationIp as string,
inheritedFrom: record.inheritedFrom as CcmObjectId,
};
}
export function buildUserDataFromRecord(
record: Record<string, unknown>
): UserData {
assertProperties(record, [
"partyId",
"uuid",
"name",
"givenName",
"familyName",
"primaryEmailAddress",
"emailAddresses",
"banned",
"passwordResetRequired",
"groupMemberships",
"roleMemberships",
]);
const groupMembershipRecords = record.groupMemberships as Record<
string,
unknown
>[];
const roleMembershipRecords = record.roleMemberships as Record<
string,
unknown
>[];
return {
partyId: record.partyId as number,
uuid: record.uuid as string,
name: record.name as string,
givenName: record.givenName as string,
familyName: record.familyName as string,
primaryEmailAddress: record.primaryEmailAddress as EmailAddressData,
emailAddresses: record.emailAddresses as EmailAddressData[],
banned: record.banned as boolean,
passwordResetRequired: record.passwordResetRequired as boolean,
groupMemberships: groupMembershipRecords.map((r) =>
buildUserGroupMembershipFromRecord(r)
),
roleMemberships: roleMembershipRecords.map((r) =>
buildPartyRoleMembershipFromRecord(r)
),
};
}
export function buildUserGroupMembershipFromRecord(
record: Record<string, unknown>
): UserGroupMembership {
assertProperties(record, ["membershipId", "uuid", "group"]);
return {
membershipId: record.membershipId as number,
uuid: record.uuid as string,
group: record.party as PartyId,
};
}

View File

@ -0,0 +1,88 @@
import { assertProperties } from "@libreccm/ccm-apiclient-commons";
import {
PartyId,
PartyRoleMembership,
buildPartyRoleMembershipFromRecord,
} from "./party";
export interface EmailAddress {
address: string;
bouncing: boolean;
verified: boolean;
}
export interface User {
partyId: number;
uuid: string;
name: string;
givenName: string;
familyName: string;
primaryEmailAddress: EmailAddress;
emailAddresses: EmailAddress[];
banned: boolean;
passwordResetRequired: boolean;
groupMemberships: UserGroupMembership[];
roleMemberships: PartyRoleMembership[];
}
export interface UserGroupMembership {
membershipId: number;
uuid: string;
group: PartyId;
}
export function buildUserFromRecord(record: Record<string, unknown>): User {
assertProperties(record, [
"partyId",
"uuid",
"name",
"givenName",
"familyName",
"primaryEmailAddress",
"emailAddresses",
"banned",
"passwordResetRequired",
"groupMemberships",
"roleMemberships",
]);
const groupMembershipRecords = record.groupMemberships as Record<
string,
unknown
>[];
const roleMembershipRecords = record.roleMemberships as Record<
string,
unknown
>[];
return {
partyId: record.partyId as number,
uuid: record.uuid as string,
name: record.name as string,
givenName: record.givenName as string,
familyName: record.familyName as string,
primaryEmailAddress: record.primaryEmailAddress as EmailAddress,
emailAddresses: record.emailAddresses as EmailAddress[],
banned: record.banned as boolean,
passwordResetRequired: record.passwordResetRequired as boolean,
groupMemberships: groupMembershipRecords.map((r) =>
buildUserGroupMembershipFromRecord(r)
),
roleMemberships: roleMembershipRecords.map((r) =>
buildPartyRoleMembershipFromRecord(r)
),
};
}
export function buildUserGroupMembershipFromRecord(
record: Record<string, unknown>
): UserGroupMembership {
assertProperties(record, ["membershipId", "uuid", "group"]);
return {
membershipId: record.membershipId as number,
uuid: record.uuid as string,
group: record.party as PartyId,
};
}