[AC-2431] New collection dialog bug (#8648)

* [AC-2431] Add null check for convertToPermission helper

* [AC-2431] Only attempt to convertToPermission if collectionId has a value
This commit is contained in:
Shane Melton 2024-04-12 08:51:20 -07:00 committed by GitHub
parent 5f97f4c4a8
commit 2e8d1a2061
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 6 deletions

View File

@ -101,7 +101,12 @@ export const getPermissionList = (flexibleCollectionsEnabled: boolean): Permissi
* for the dropdown in the AccessSelectorComponent * for the dropdown in the AccessSelectorComponent
* @param value * @param value
*/ */
export const convertToPermission = (value: CollectionAccessSelectionView) => { export const convertToPermission = (
value: CollectionAccessSelectionView | undefined,
): CollectionPermission | undefined => {
if (value == null) {
return undefined;
}
if (value.manage) { if (value.manage) {
return CollectionPermission.Manage; return CollectionPermission.Manage;
} else if (value.readOnly) { } else if (value.readOnly) {

View File

@ -29,9 +29,9 @@ import { CollectionView } from "@bitwarden/common/vault/models/view/collection.v
import { BitValidators, DialogService } from "@bitwarden/components"; import { BitValidators, DialogService } from "@bitwarden/components";
import { import {
CollectionAccessSelectionView,
GroupService, GroupService,
GroupView, GroupView,
CollectionAccessSelectionView,
} from "../../../admin-console/organizations/core"; } from "../../../admin-console/organizations/core";
import { PermissionMode } from "../../../admin-console/organizations/shared/components/access-selector/access-selector.component"; import { PermissionMode } from "../../../admin-console/organizations/shared/components/access-selector/access-selector.component";
import { import {
@ -432,7 +432,10 @@ function mapGroupToAccessItemView(group: GroupView, collectionId: string): Acces
labelName: group.name, labelName: group.name,
accessAllItems: group.accessAll, accessAllItems: group.accessAll,
readonly: group.accessAll, readonly: group.accessAll,
readonlyPermission: convertToPermission(group.collections.find((gc) => gc.id == collectionId)), readonlyPermission:
collectionId != null
? convertToPermission(group.collections.find((gc) => gc.id == collectionId))
: undefined,
}; };
} }
@ -456,9 +459,12 @@ function mapUserToAccessItemView(
status: user.status, status: user.status,
accessAllItems: user.accessAll, accessAllItems: user.accessAll,
readonly: user.accessAll, readonly: user.accessAll,
readonlyPermission: convertToPermission( readonlyPermission:
collectionId != null
? convertToPermission(
new CollectionAccessSelectionView(user.collections.find((uc) => uc.id == collectionId)), new CollectionAccessSelectionView(user.collections.find((uc) => uc.id == collectionId)),
), )
: undefined,
}; };
} }