-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create data model and transformers for Organization type (#9152)
* create initial data model * finish implementing transformers * fix typing * remove dead code * switch back to LegacyUserRole and change organization.role to organization.isAdmin * remove dead code; use UserRole * remove the lifted value from Organzation * rename OrganizationMembers -> OrganizationMemberships * member -> membership
- Loading branch information
1 parent
4652b33
commit 21e6b4e
Showing
27 changed files
with
410 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (C) 2024 PixieBrix, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { | ||
transformOrganizationMembershipResponse, | ||
type OrganizationMembership, | ||
} from "@/data/model/OrganizationMemberships"; | ||
import { | ||
transformOrganizationThemeResponse, | ||
type OrganizationTheme, | ||
} from "@/data/model/OrganizationTheme"; | ||
import { | ||
type UserRoleType, | ||
transformUserRoleResponse, | ||
} from "@/data/model/UserRole"; | ||
import { validateUUID } from "@/types/helpers"; | ||
import { type Timestamp, type UUID } from "@/types/stringTypes"; | ||
import { type components } from "@/types/swagger"; | ||
|
||
export type Organization = { | ||
/** | ||
* The organization's ID. | ||
*/ | ||
organizationId: UUID; | ||
/** | ||
* The organization's name. | ||
*/ | ||
organizationName: string; | ||
/** | ||
* The organization's memberships. | ||
*/ | ||
memberships: OrganizationMembership[] | null; | ||
/** | ||
* The organization's scope. | ||
*/ | ||
scope: string | null; | ||
/** | ||
* The organization's default role. | ||
*/ | ||
defaultRole: UserRoleType | null; | ||
/** | ||
* The organization's partner. | ||
*/ | ||
partner: string | null; | ||
/** | ||
* The organization's enforce update millis. | ||
*/ | ||
enforceUpdateMillis: number | null; | ||
/** | ||
* The organization's UI theme. | ||
*/ | ||
theme: OrganizationTheme | null; | ||
|
||
trialEndTimestamp: Timestamp | null; | ||
}; | ||
|
||
export function transformOrganizationResponse( | ||
baseQueryReturnValue: Array<components["schemas"]["Organization"]>, | ||
): Organization[] { | ||
return baseQueryReturnValue.map((apiOrganization) => ({ | ||
organizationId: validateUUID(apiOrganization.id), | ||
organizationName: apiOrganization.name, | ||
memberships: transformOrganizationMembershipResponse( | ||
apiOrganization.members, | ||
), | ||
scope: apiOrganization.scope ?? null, | ||
defaultRole: apiOrganization.default_role | ||
? transformUserRoleResponse(apiOrganization.default_role) | ||
: null, | ||
partner: apiOrganization.partner ?? null, | ||
enforceUpdateMillis: apiOrganization.enforce_update_millis ?? null, | ||
theme: apiOrganization.theme | ||
? transformOrganizationThemeResponse(apiOrganization.theme) | ||
: null, | ||
trialEndTimestamp: apiOrganization.trial_end_timestamp ?? null, | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2024 PixieBrix, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { type UUID } from "@/types/stringTypes"; | ||
import { type components } from "@/types/swagger"; | ||
import { type SetRequired } from "type-fest"; | ||
|
||
export type OrganizationMembershipGroup = { | ||
groupId: UUID; | ||
groupName: string; | ||
}; | ||
|
||
type Memberships = SetRequired< | ||
components["schemas"]["Organization"], | ||
"members" | ||
>["members"]; | ||
|
||
export function transformOrganizationMemberGroupsResponse( | ||
groups: Memberships[number]["groups"], | ||
): OrganizationMembershipGroup[] | undefined { | ||
return groups?.map((group) => ({ | ||
groupId: group.id, | ||
groupName: group.name, | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2024 PixieBrix, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { validateUUID } from "@/types/helpers"; | ||
import { type Timestamp, type UUID } from "@/types/stringTypes"; | ||
import { type components } from "@/types/swagger"; | ||
import { type SetRequired } from "type-fest"; | ||
|
||
export type OrganizationMembershipUser = { | ||
userId: UUID; | ||
userName?: string; | ||
userEmail?: string; | ||
serviceAccount?: boolean; | ||
deploymentKeyAccount?: boolean; | ||
dateJoined?: Timestamp; | ||
}; | ||
|
||
type Memberships = SetRequired< | ||
components["schemas"]["Organization"], | ||
"members" | ||
>["members"]; | ||
|
||
export function transformOrganizationMemberUserResponse( | ||
user: Memberships[number]["user"], | ||
): OrganizationMembershipUser { | ||
return { | ||
userId: validateUUID(user?.id), | ||
userName: user?.name, | ||
userEmail: user?.email, | ||
serviceAccount: user?.service_account, | ||
deploymentKeyAccount: user?.deployment_key_account, | ||
dateJoined: user?.date_joined, | ||
}; | ||
} |
Oops, something went wrong.