diff --git a/ccm-core-apiclient/src/main/typescript/entities/group.ts b/ccm-core-apiclient/src/main/typescript/entities/group.ts new file mode 100644 index 000000000..5fd2cd8c1 --- /dev/null +++ b/ccm-core-apiclient/src/main/typescript/entities/group.ts @@ -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): Group { + assertProperties(record, [ + "partyId", + "uuid", + "name", + "memberships", + "roleMemberships", + ]); + + const membershipRecords = record.memberships as Record[]; + 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 +): GroupUserMembership { + assertProperties(record, ["membershipId", "uuid", "user"]); + + return { + membershipId: record.membershipId as number, + uuid: record.uuid as string, + user: buildPartyIdFromRecord(record.user as Record), + }; +} + +function buildPartyIdFromRecord(record: Record): PartyId { + assertProperties(record, ["partyId", "uuid", "name"]); + + return { + partyId: record.partyId as number, + uuid: record.uuid as string, + name: record.name as string, + }; +} diff --git a/ccm-core-apiclient/src/main/typescript/entities/party.ts b/ccm-core-apiclient/src/main/typescript/entities/party.ts new file mode 100644 index 000000000..f2524af18 --- /dev/null +++ b/ccm-core-apiclient/src/main/typescript/entities/party.ts @@ -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 +): PartyRoleMembership { + assertProperties(record, ["membershipId", "uuid", "role"]); + + return { + membershipId: record.membershipId as number, + uuid: record.uuid as string, + role: buildRoleIdFromRecord(record.role as Record), + }; +} diff --git a/ccm-core-apiclient/src/main/typescript/entities/role.ts b/ccm-core-apiclient/src/main/typescript/entities/role.ts new file mode 100644 index 000000000..30fdedcf0 --- /dev/null +++ b/ccm-core-apiclient/src/main/typescript/entities/role.ts @@ -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): Role { + assertProperties(record, [ + "roleId", + "uuid", + "name", + "description", + "permissions", + ]); + + const permissionRecords = record.permissions as Record[]; + + 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): 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 +): 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 +): 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, + }; +} diff --git a/ccm-core-apiclient/src/main/typescript/entities/security.ts b/ccm-core-apiclient/src/main/typescript/entities/security.ts deleted file mode 100644 index e304d718e..000000000 --- a/ccm-core-apiclient/src/main/typescript/entities/security.ts +++ /dev/null @@ -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 -): GroupData { - assertProperties(record, [ - "partyId", - "uuid", - "name", - "memberships", - "roleMemberships", - ]); - - const membershipRecords = record.memberships as Record[]; - 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 -): GroupUserMembership { - assertProperties(record, ["membershipId", "uuid", "user"]); - - return { - membershipId: record.membershipId as number, - uuid: record.uuid as string, - user: buildPartyIdFromRecord(record.user as Record), - }; -} - -function buildPartyIdFromRecord(record: Record): 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 -): PartyRoleMembership { - assertProperties(record, ["membershipId", "uuid", "role"]); - - return { - membershipId: record.membershipId as number, - uuid: record.uuid as string, - role: buildRoleIdFromRecord(record.role as Record), - }; -} - -export function buildRoleDataFromRecord( - record: Record -): RoleData { - assertProperties(record, [ - "roleId", - "uuid", - "name", - "description", - "permissions", - ]); - - const permissionRecords = record.permissions as Record[]; - - 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): 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 -): 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 -): 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 -): 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 -): UserGroupMembership { - assertProperties(record, ["membershipId", "uuid", "group"]); - - return { - membershipId: record.membershipId as number, - uuid: record.uuid as string, - group: record.party as PartyId, - }; -} diff --git a/ccm-core-apiclient/src/main/typescript/entities/user.ts b/ccm-core-apiclient/src/main/typescript/entities/user.ts new file mode 100644 index 000000000..b477dab27 --- /dev/null +++ b/ccm-core-apiclient/src/main/typescript/entities/user.ts @@ -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): 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 +): UserGroupMembership { + assertProperties(record, ["membershipId", "uuid", "group"]); + + return { + membershipId: record.membershipId as number, + uuid: record.uuid as string, + group: record.party as PartyId, + }; +}