-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create data model and transformers for Organization type #9152
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ed4e1d7
create initial data model
grahamlangford 98388f8
finish implementing transformers
grahamlangford e788989
Merge branch 'main' of github.com:pixiebrix/pixiebrix-extension into …
grahamlangford fa7d239
fix typing
grahamlangford 6ff1774
remove dead code
grahamlangford b24e4d3
switch back to LegacyUserRole and change organization.role to organiz…
grahamlangford f787bd3
remove dead code; use UserRole
grahamlangford df3a73e
remove the lifted value from Organzation
grahamlangford 1ea36b4
rename OrganizationMembers -> OrganizationMemberships
grahamlangford 5c9c4e2
member -> membership
grahamlangford File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,89 @@ | ||
/* | ||
* 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 members. | ||
*/ | ||
members: 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, | ||
members: 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removes the need for the lifted role. See: https://github.com/pixiebrix/pixiebrix-extension/pull/9152/files#r1759350434