Skip to content

Commit

Permalink
Handle missing privileges for add VC to community. (#7470)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbykolev authored Jan 21, 2025
1 parent 432dfd1 commit 8c2b845
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/core/apollo/generated/apollo-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3744,6 +3744,10 @@ export const SpaceProfileCommunityDetailsFragmentDoc = gql`
id
roleSet {
id
authorization {
id
myPrivileges
}
}
}
}
Expand Down
76 changes: 71 additions & 5 deletions src/core/apollo/generated/graphql-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31592,7 +31592,21 @@ export type NewVirtualContributorMySpacesQuery = {
}
| undefined;
profile: { __typename?: 'Profile'; id: string; displayName: string; url: string };
community: { __typename?: 'Community'; id: string; roleSet: { __typename?: 'RoleSet'; id: string } };
community: {
__typename?: 'Community';
id: string;
roleSet: {
__typename?: 'RoleSet';
id: string;
authorization?:
| {
__typename?: 'Authorization';
id: string;
myPrivileges?: Array<AuthorizationPrivilege> | undefined;
}
| undefined;
};
};
}>;
}
| undefined;
Expand Down Expand Up @@ -31623,13 +31637,55 @@ export type AccountSpacesQuery = {
__typename?: 'Space';
id: string;
profile: { __typename?: 'Profile'; id: string; displayName: string; url: string };
community: { __typename?: 'Community'; id: string; roleSet: { __typename?: 'RoleSet'; id: string } };
community: {
__typename?: 'Community';
id: string;
roleSet: {
__typename?: 'RoleSet';
id: string;
authorization?:
| {
__typename?: 'Authorization';
id: string;
myPrivileges?: Array<AuthorizationPrivilege> | undefined;
}
| undefined;
};
};
}>;
profile: { __typename?: 'Profile'; id: string; displayName: string; url: string };
community: { __typename?: 'Community'; id: string; roleSet: { __typename?: 'RoleSet'; id: string } };
community: {
__typename?: 'Community';
id: string;
roleSet: {
__typename?: 'RoleSet';
id: string;
authorization?:
| {
__typename?: 'Authorization';
id: string;
myPrivileges?: Array<AuthorizationPrivilege> | undefined;
}
| undefined;
};
};
}>;
profile: { __typename?: 'Profile'; id: string; displayName: string; url: string };
community: { __typename?: 'Community'; id: string; roleSet: { __typename?: 'RoleSet'; id: string } };
community: {
__typename?: 'Community';
id: string;
roleSet: {
__typename?: 'RoleSet';
id: string;
authorization?:
| {
__typename?: 'Authorization';
id: string;
myPrivileges?: Array<AuthorizationPrivilege> | undefined;
}
| undefined;
};
};
}>;
}
| undefined;
Expand All @@ -31640,7 +31696,17 @@ export type SpaceProfileCommunityDetailsFragment = {
__typename?: 'Space';
id: string;
profile: { __typename?: 'Profile'; id: string; displayName: string; url: string };
community: { __typename?: 'Community'; id: string; roleSet: { __typename?: 'RoleSet'; id: string } };
community: {
__typename?: 'Community';
id: string;
roleSet: {
__typename?: 'RoleSet';
id: string;
authorization?:
| { __typename?: 'Authorization'; id: string; myPrivileges?: Array<AuthorizationPrivilege> | undefined }
| undefined;
};
};
};

export type RecentSpacesQueryVariables = Exact<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ fragment spaceProfileCommunityDetails on Space {
id
roleSet {
id
authorization {
id
myPrivileges
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@/core/apollo/generated/apollo-hooks';
import {
AiPersonaBodyOfKnowledgeType,
AuthorizationPrivilege,
CommunityRoleType,
CreateCalloutInput,
CreateVirtualContributorOnAccountMutationVariables,
Expand Down Expand Up @@ -65,6 +66,9 @@ export type SelectableSpace = {
community: {
roleSet: {
id: string;
authorization?: {
myPrivileges?: AuthorizationPrivilege[];
};
};
};
subspaces?: SelectableSpace[];
Expand Down Expand Up @@ -113,12 +117,19 @@ const useNewVirtualContributorWizard = (): useNewVirtualContributorWizardProvide
fetchPolicy: 'cache-and-network',
});

const { myAccountId, accountSpaces } = useMemo(() => {
const hasCommunityPrivilege = (space: SelectableSpace) => {
return space.community.roleSet?.authorization?.myPrivileges?.includes(
AuthorizationPrivilege.CommunityAddMemberVcFromAccount
);
};

const { myAccountId, allAccountSpaces, availableSpaces } = useMemo(() => {
const account = targetAccount ?? data?.me.user?.account; // contextual or self by default

return {
myAccountId: account?.id,
accountSpaces: account?.spaces ?? [],
allAccountSpaces: account?.spaces ?? [],
availableSpaces: account?.spaces?.filter(hasCommunityPrivilege) ?? [],
};
}, [data, user, targetAccount]);

Expand All @@ -137,7 +148,7 @@ const useNewVirtualContributorWizard = (): useNewVirtualContributorWizardProvide
);

// get plans data todo: make lazy, usePlanAvailability is temp
const skipPlansQueries = Boolean(accountSpaces.length);
const skipPlansQueries = Boolean(allAccountSpaces.length);
const { data: plansData } = usePlansTableQuery({ skip: skipPlansQueries });
const { isPlanAvailable } = usePlanAvailability({ skip: skipPlansQueries });

Expand Down Expand Up @@ -434,7 +445,7 @@ const useNewVirtualContributorWizard = (): useNewVirtualContributorWizardProvide
// Refresh explicitly the ingestion after callouts creation
refreshIngestion(createdVC.id);

setStep(steps.chooseCommunity);
setChooseCommunityStep();
};

// ###STEP 'chooseCommunityStep' - Choose Community
Expand All @@ -460,6 +471,17 @@ const useNewVirtualContributorWizard = (): useNewVirtualContributorWizardProvide
}
};

// If there are spaces under the account, but there are no spaces with the privilege to add a VC
// navigate to the try info VC step
// otherwise, navigate to the choose community step
const setChooseCommunityStep = () => {
if (allAccountSpaces.length > 0 && availableSpaces.length === 0) {
setStep(steps.tryVcInfo);
} else {
setStep(steps.chooseCommunity);
}
};

// ###STEP 'existingKnowledge' - Existing Knowledge
const handleCreateVCWithExistingKnowledge = async (selectedKnowledge: SelectableKnowledgeSpace) => {
if (selectedKnowledge && virtualContributorInput && myAccountId) {
Expand Down Expand Up @@ -543,7 +565,7 @@ const useNewVirtualContributorWizard = (): useNewVirtualContributorWizardProvide
<ChooseCommunity
onClose={handleCloseChooseCommunity}
vcName={virtualContributorInput?.name}
spaces={accountSpaces}
spaces={availableSpaces}
onSubmit={onChooseCommunity}
loading={loading || availableSpacesLoading}
/>
Expand Down

0 comments on commit 8c2b845

Please sign in to comment.