Skip to content

Commit

Permalink
Fix #7316 Create template permission (#7319)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccanos authored Dec 13, 2024
1 parent 395768d commit 523cdd1
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/core/apollo/generated/apollo-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,16 @@ export const SpaceInfoFragmentDoc = gql`
myPrivileges
}
}
templatesManager {
id
templatesSet {
id
authorization {
id
myPrivileges
}
}
}
visibility
}
${SpaceDetailsFragmentDoc}
Expand Down
34 changes: 34 additions & 0 deletions src/core/apollo/generated/graphql-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21086,6 +21086,25 @@ export type SpaceProviderQuery = {
| { __typename?: 'Authorization'; id: string; myPrivileges?: Array<AuthorizationPrivilege> | undefined }
| undefined;
};
templatesManager?:
| {
__typename?: 'TemplatesManager';
id: string;
templatesSet?:
| {
__typename?: 'TemplatesSet';
id: string;
authorization?:
| {
__typename?: 'Authorization';
id: string;
myPrivileges?: Array<AuthorizationPrivilege> | undefined;
}
| undefined;
}
| undefined;
}
| undefined;
profile: {
__typename?: 'Profile';
id: string;
Expand Down Expand Up @@ -21187,6 +21206,21 @@ export type SpaceInfoFragment = {
| { __typename?: 'Authorization'; id: string; myPrivileges?: Array<AuthorizationPrivilege> | undefined }
| undefined;
};
templatesManager?:
| {
__typename?: 'TemplatesManager';
id: string;
templatesSet?:
| {
__typename?: 'TemplatesSet';
id: string;
authorization?:
| { __typename?: 'Authorization'; id: string; myPrivileges?: Array<AuthorizationPrivilege> | undefined }
| undefined;
}
| undefined;
}
| undefined;
profile: {
__typename?: 'Profile';
id: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCollaborationAuthorizationEntitlementsQuery } from '@/core/apollo/generated/apollo-hooks';
import { AuthorizationPrivilege, LicenseEntitlementType } from '@/core/apollo/generated/graphql-schema';
import { useSpace } from '@/domain/journey/space/SpaceContext/useSpace';

type CollaborationAuthorizationEntitlementsParams = {
collaborationId: string | undefined;
Expand All @@ -17,6 +18,10 @@ type CollaborationAuthorization = {
export const useCollaborationAuthorizationEntitlements = ({
collaborationId,
}: CollaborationAuthorizationEntitlementsParams): CollaborationAuthorization => {
// For now we always save as template to the current space, but in the future we may want to be able to choose an InnovationPack to save a callout to, and this would make no sense.
// Remove this, and the templateSet privileges query from the SpaceProvider query
const { permissions } = useSpace();

const { data: collaborationData, loading: loadingCollaboration } = useCollaborationAuthorizationEntitlementsQuery({
variables: {
collaborationId: collaborationId!,
Expand All @@ -27,12 +32,11 @@ export const useCollaborationAuthorizationEntitlements = ({
const collaborationPrivileges = collaborationData?.lookup.collaboration?.authorization?.myPrivileges ?? [];
const collaborationEntitlements = collaborationData?.lookup.collaboration?.license?.availableEntitlements ?? [];
const canCreateCallout = collaborationPrivileges.includes(AuthorizationPrivilege.CreateCallout);
const canSaveAsTemplate = collaborationEntitlements.includes(LicenseEntitlementType.SpaceFlagSaveAsTemplate);
const canSaveAsTemplate = permissions.canCreateTemplates;
const canReadCallout = collaborationPrivileges.includes(AuthorizationPrivilege.Read);

const license = collaborationData?.lookup.collaboration?.license;
const entitledToSaveAsTemplate =
license?.availableEntitlements?.includes(LicenseEntitlementType.SpaceFlagSaveAsTemplate) ?? false;
collaborationEntitlements?.includes(LicenseEntitlementType.SpaceFlagSaveAsTemplate) ?? false;

return {
collaborationPrivileges,
Expand Down
6 changes: 6 additions & 0 deletions src/domain/journey/space/SpaceContext/SpaceContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface SpacePermissions {
canReadPosts: boolean;
canReadSubspaces: boolean;
canCreateSubspaces: boolean;
canCreateTemplates: boolean;
canCreate: boolean;
communityReadAccess: boolean;
canReadCollaboration: boolean;
Expand Down Expand Up @@ -55,6 +56,7 @@ const SpaceContext = React.createContext<SpaceContextProps>({
viewerCanUpdate: false,
canCreate: false,
canCreateSubspaces: false,
canCreateTemplates: false,
canReadPosts: false,
canReadSubspaces: false,
communityReadAccess: false,
Expand Down Expand Up @@ -109,6 +111,9 @@ const SpaceContextProvider: FC<SpaceProviderProps> = ({ children }) => {

const canReadSubspaces = spacePrivileges.includes(AuthorizationPrivilege.Read);
const canCreateSubspaces = spacePrivileges.includes(AuthorizationPrivilege.CreateSubspace);
const canCreateTemplates =
data?.space.templatesManager?.templatesSet?.authorization?.myPrivileges?.includes(AuthorizationPrivilege.Create) ??
false;
const canCreate = spacePrivileges.includes(AuthorizationPrivilege.Create);

const communityPrivileges = space?.community?.authorization?.myPrivileges ?? NO_PRIVILEGES;
Expand All @@ -119,6 +124,7 @@ const SpaceContextProvider: FC<SpaceProviderProps> = ({ children }) => {
viewerCanUpdate: spacePrivileges.includes(AuthorizationPrivilege.Update),
canReadSubspaces,
canCreateSubspaces: canCreateSubspaces,
canCreateTemplates,
canCreate,
communityReadAccess: communityPrivileges.includes(AuthorizationPrivilege.Read),
canReadCollaboration: collaborationPrivileges.includes(AuthorizationPrivilege.Read),
Expand Down
10 changes: 10 additions & 0 deletions src/domain/journey/space/SpaceContext/spaceProvider.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ fragment SpaceInfo on Space {
myPrivileges
}
}
templatesManager {
id
templatesSet{
id
authorization {
id
myPrivileges
}
}
}

visibility
}
Expand Down

0 comments on commit 523cdd1

Please sign in to comment.