Skip to content

Commit

Permalink
Fix dashboard access (#7360)
Browse files Browse the repository at this point in the history
* Fix dashboard access

* fixed scope

* change polling interval

* fix pr comment

* renamed to useSpaceTemplate*s*ManagerQuery

---------

Co-authored-by: Carlos Cano <carlos@alkem.io>
  • Loading branch information
valentinyanakiev and ccanos authored Dec 20, 2024
1 parent cb503b4 commit 2b6a7d5
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 60 deletions.
80 changes: 70 additions & 10 deletions src/core/apollo/generated/apollo-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2150,16 +2150,6 @@ export const SpaceInfoFragmentDoc = gql`
myPrivileges
}
}
templatesManager {
id
templatesSet {
id
authorization {
id
myPrivileges
}
}
}
visibility
}
${SpaceDetailsFragmentDoc}
Expand Down Expand Up @@ -16362,6 +16352,76 @@ export function refetchSpaceUrlQuery(variables: SchemaTypes.SpaceUrlQueryVariabl
return { query: SpaceUrlDocument, variables: variables };
}

export const SpaceTemplatesManagerDocument = gql`
query SpaceTemplatesManager($spaceNameId: UUID_NAMEID!) {
space(ID: $spaceNameId) {
id
templatesManager {
id
templatesSet {
id
authorization {
id
myPrivileges
}
}
}
}
}
`;

/**
* __useSpaceTemplatesManagerQuery__
*
* To run a query within a React component, call `useSpaceTemplatesManagerQuery` and pass it any options that fit your needs.
* When your component renders, `useSpaceTemplatesManagerQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useSpaceTemplatesManagerQuery({
* variables: {
* spaceNameId: // value for 'spaceNameId'
* },
* });
*/
export function useSpaceTemplatesManagerQuery(
baseOptions: Apollo.QueryHookOptions<
SchemaTypes.SpaceTemplatesManagerQuery,
SchemaTypes.SpaceTemplatesManagerQueryVariables
>
) {
const options = { ...defaultOptions, ...baseOptions };
return Apollo.useQuery<SchemaTypes.SpaceTemplatesManagerQuery, SchemaTypes.SpaceTemplatesManagerQueryVariables>(
SpaceTemplatesManagerDocument,
options
);
}

export function useSpaceTemplatesManagerLazyQuery(
baseOptions?: Apollo.LazyQueryHookOptions<
SchemaTypes.SpaceTemplatesManagerQuery,
SchemaTypes.SpaceTemplatesManagerQueryVariables
>
) {
const options = { ...defaultOptions, ...baseOptions };
return Apollo.useLazyQuery<SchemaTypes.SpaceTemplatesManagerQuery, SchemaTypes.SpaceTemplatesManagerQueryVariables>(
SpaceTemplatesManagerDocument,
options
);
}

export type SpaceTemplatesManagerQueryHookResult = ReturnType<typeof useSpaceTemplatesManagerQuery>;
export type SpaceTemplatesManagerLazyQueryHookResult = ReturnType<typeof useSpaceTemplatesManagerLazyQuery>;
export type SpaceTemplatesManagerQueryResult = Apollo.QueryResult<
SchemaTypes.SpaceTemplatesManagerQuery,
SchemaTypes.SpaceTemplatesManagerQueryVariables
>;
export function refetchSpaceTemplatesManagerQuery(variables: SchemaTypes.SpaceTemplatesManagerQueryVariables) {
return { query: SpaceTemplatesManagerDocument, variables: variables };
}

export const SpaceHostDocument = gql`
query SpaceHost($spaceNameId: UUID_NAMEID!) {
space(ID: $spaceNameId) {
Expand Down
65 changes: 31 additions & 34 deletions src/core/apollo/generated/graphql-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21239,25 +21239,6 @@ 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 @@ -21320,6 +21301,37 @@ export type SpaceUrlQuery = {
space: { __typename?: 'Space'; id: string; profile: { __typename?: 'Profile'; id: string; url: string } };
};

export type SpaceTemplatesManagerQueryVariables = Exact<{
spaceNameId: Scalars['UUID_NAMEID'];
}>;

export type SpaceTemplatesManagerQuery = {
__typename?: 'Query';
space: {
__typename?: 'Space';
id: string;
templatesManager?:
| {
__typename?: 'TemplatesManager';
id: string;
templatesSet?:
| {
__typename?: 'TemplatesSet';
id: string;
authorization?:
| {
__typename?: 'Authorization';
id: string;
myPrivileges?: Array<AuthorizationPrivilege> | undefined;
}
| undefined;
}
| undefined;
}
| undefined;
};
};

export type SpaceInfoFragment = {
__typename?: 'Space';
visibility: SpaceVisibility;
Expand Down Expand Up @@ -21358,21 +21370,6 @@ 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
25 changes: 20 additions & 5 deletions src/domain/journey/space/SpaceContext/SpaceContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApolloError } from '@apollo/client';
import React, { FC, useMemo } from 'react';
import { useUrlParams } from '@/core/routing/useUrlParams';
import { useConfig } from '@/domain/platform/config/useConfig';
import { useSpaceProviderQuery } from '@/core/apollo/generated/apollo-hooks';
import { useSpaceProviderQuery, useSpaceTemplatesManagerQuery } from '@/core/apollo/generated/apollo-hooks';
import {
AuthorizationPrivilege,
CommunityMembershipStatus,
Expand Down Expand Up @@ -111,11 +111,26 @@ 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);

// A member has READ and an Admin can also access it, this is more of a temporary solution
const canAccessTemplatesManager =
space?.community.roleSet.myMembershipStatus === CommunityMembershipStatus.Member ||
spacePrivileges.includes(AuthorizationPrivilege.Grant);
let canCreateTemplates = false;

const { data: templatesManagerData } = useSpaceTemplatesManagerQuery({
variables: { spaceNameId },
skip: !spaceNameId || !canAccessTemplatesManager,
});

if (canAccessTemplatesManager) {
canCreateTemplates =
templatesManagerData?.space.templatesManager?.templatesSet?.authorization?.myPrivileges?.includes(
AuthorizationPrivilege.Create
) ?? false;
}

const canCreate = spacePrivileges.includes(AuthorizationPrivilege.Create);
const communityPrivileges = space?.community?.authorization?.myPrivileges ?? NO_PRIVILEGES;

const permissions = useMemo<SpacePermissions>(() => {
Expand Down
26 changes: 16 additions & 10 deletions src/domain/journey/space/SpaceContext/spaceProvider.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ query SpaceUrl($spaceNameId: UUID_NAMEID!) {
}
}

query SpaceTemplatesManager($spaceNameId: UUID_NAMEID!) {
space(ID: $spaceNameId) {
id
templatesManager {
id
templatesSet {
id
authorization {
id
myPrivileges
}
}
}
}
}

fragment SpaceInfo on Space {
...SpaceDetails
authorization {
Expand Down Expand Up @@ -46,16 +62,6 @@ fragment SpaceInfo on Space {
myPrivileges
}
}
templatesManager {
id
templatesSet{
id
authorization {
id
myPrivileges
}
}
}

visibility
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/inAppNotifications/useInAppNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { useUserContext } from '@/domain/community/user';
import { useInAppNotificationsContext } from './InAppNotificationsContext';

const POLLING_INTERVAL = 5 * 1000; // 5 seconds
const POLLING_INTERVAL = 15 * 1000; // 15 seconds

export interface InAppNotificationProps {
id: string;
Expand Down

0 comments on commit 2b6a7d5

Please sign in to comment.