diff --git a/src/core/apollo/generated/apollo-hooks.ts b/src/core/apollo/generated/apollo-hooks.ts index 5e8d5184e7..1978c0cc84 100644 --- a/src/core/apollo/generated/apollo-hooks.ts +++ b/src/core/apollo/generated/apollo-hooks.ts @@ -2137,6 +2137,16 @@ export const SpaceInfoFragmentDoc = gql` myPrivileges } } + templatesManager { + id + templatesSet { + id + authorization { + id + myPrivileges + } + } + } visibility } ${SpaceDetailsFragmentDoc} diff --git a/src/core/apollo/generated/graphql-schema.ts b/src/core/apollo/generated/graphql-schema.ts index 957920f0f8..6d5e286bdf 100644 --- a/src/core/apollo/generated/graphql-schema.ts +++ b/src/core/apollo/generated/graphql-schema.ts @@ -21086,6 +21086,25 @@ export type SpaceProviderQuery = { | { __typename?: 'Authorization'; id: string; myPrivileges?: Array | undefined } | undefined; }; + templatesManager?: + | { + __typename?: 'TemplatesManager'; + id: string; + templatesSet?: + | { + __typename?: 'TemplatesSet'; + id: string; + authorization?: + | { + __typename?: 'Authorization'; + id: string; + myPrivileges?: Array | undefined; + } + | undefined; + } + | undefined; + } + | undefined; profile: { __typename?: 'Profile'; id: string; @@ -21187,6 +21206,21 @@ export type SpaceInfoFragment = { | { __typename?: 'Authorization'; id: string; myPrivileges?: Array | undefined } | undefined; }; + templatesManager?: + | { + __typename?: 'TemplatesManager'; + id: string; + templatesSet?: + | { + __typename?: 'TemplatesSet'; + id: string; + authorization?: + | { __typename?: 'Authorization'; id: string; myPrivileges?: Array | undefined } + | undefined; + } + | undefined; + } + | undefined; profile: { __typename?: 'Profile'; id: string; diff --git a/src/domain/collaboration/authorization/useCollaborationAuthorization.ts b/src/domain/collaboration/authorization/useCollaborationAuthorization.ts index 4f8d7d717d..336db237b8 100644 --- a/src/domain/collaboration/authorization/useCollaborationAuthorization.ts +++ b/src/domain/collaboration/authorization/useCollaborationAuthorization.ts @@ -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; @@ -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!, @@ -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, diff --git a/src/domain/journey/space/SpaceContext/SpaceContext.tsx b/src/domain/journey/space/SpaceContext/SpaceContext.tsx index dc929989a8..edf4dd73c3 100644 --- a/src/domain/journey/space/SpaceContext/SpaceContext.tsx +++ b/src/domain/journey/space/SpaceContext/SpaceContext.tsx @@ -17,6 +17,7 @@ export interface SpacePermissions { canReadPosts: boolean; canReadSubspaces: boolean; canCreateSubspaces: boolean; + canCreateTemplates: boolean; canCreate: boolean; communityReadAccess: boolean; canReadCollaboration: boolean; @@ -55,6 +56,7 @@ const SpaceContext = React.createContext({ viewerCanUpdate: false, canCreate: false, canCreateSubspaces: false, + canCreateTemplates: false, canReadPosts: false, canReadSubspaces: false, communityReadAccess: false, @@ -109,6 +111,9 @@ const SpaceContextProvider: FC = ({ 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; @@ -119,6 +124,7 @@ const SpaceContextProvider: FC = ({ children }) => { viewerCanUpdate: spacePrivileges.includes(AuthorizationPrivilege.Update), canReadSubspaces, canCreateSubspaces: canCreateSubspaces, + canCreateTemplates, canCreate, communityReadAccess: communityPrivileges.includes(AuthorizationPrivilege.Read), canReadCollaboration: collaborationPrivileges.includes(AuthorizationPrivilege.Read), diff --git a/src/domain/journey/space/SpaceContext/spaceProvider.graphql b/src/domain/journey/space/SpaceContext/spaceProvider.graphql index 1283a0a603..ce99bd2bff 100644 --- a/src/domain/journey/space/SpaceContext/spaceProvider.graphql +++ b/src/domain/journey/space/SpaceContext/spaceProvider.graphql @@ -46,6 +46,16 @@ fragment SpaceInfo on Space { myPrivileges } } + templatesManager { + id + templatesSet{ + id + authorization { + id + myPrivileges + } + } + } visibility }