diff --git a/backend/dataall/modules/dashboards/api/resolvers.py b/backend/dataall/modules/dashboards/api/resolvers.py index 7a9bbe133..8f703419d 100644 --- a/backend/dataall/modules/dashboards/api/resolvers.py +++ b/backend/dataall/modules/dashboards/api/resolvers.py @@ -48,6 +48,12 @@ def get_dashboard(context: Context, source, dashboardUri: str = None): return DashboardService.get_dashboard(uri=dashboardUri) +def get_dashboard_restricted_information(context: Context, source: Dashboard): + if not source: + return None + return DashboardService.get_dashboard_restricted_information(uri=source.dashboardUri, dashboard=source) + + def resolve_user_role(context: Context, source: Dashboard): if context.username and source.owner == context.username: return DashboardRole.Creator.value diff --git a/backend/dataall/modules/dashboards/api/types.py b/backend/dataall/modules/dashboards/api/types.py index 857cf9333..9e5405891 100644 --- a/backend/dataall/modules/dashboards/api/types.py +++ b/backend/dataall/modules/dashboards/api/types.py @@ -1,7 +1,7 @@ from dataall.base.api import gql from dataall.modules.dashboards.api.resolvers import ( DashboardRole, - get_dashboard_organization, + get_dashboard_restricted_information, resolve_glossary_terms, resolve_upvotes, resolve_user_role, @@ -9,6 +9,11 @@ from dataall.core.environment.api.resolvers import resolve_environment +DashboardRestrictedInformation = gql.ObjectType( + name='DashboardRestrictedInformation', + fields=[gql.Field('AwsAccountId', type=gql.String), gql.Field('region', type=gql.String)], +) + Dashboard = gql.ObjectType( name='Dashboard', fields=[ @@ -19,10 +24,14 @@ gql.Field('DashboardId', type=gql.String), gql.Field('tags', type=gql.ArrayType(gql.String)), gql.Field('created', type=gql.String), - gql.Field('AwsAccountId', type=gql.String), gql.Field('updated', type=gql.String), gql.Field('owner', type=gql.String), gql.Field('SamlGroupName', type=gql.String), + gql.Field( + 'restricted', + type=DashboardRestrictedInformation, + resolver=get_dashboard_restricted_information, + ), gql.Field( 'environment', type=gql.Ref('EnvironmentSimplified'), diff --git a/backend/dataall/modules/dashboards/services/dashboard_service.py b/backend/dataall/modules/dashboards/services/dashboard_service.py index 34d6c3a34..30c205e0f 100644 --- a/backend/dataall/modules/dashboards/services/dashboard_service.py +++ b/backend/dataall/modules/dashboards/services/dashboard_service.py @@ -25,11 +25,15 @@ class DashboardService: """Service that serves request related to dashboard""" @staticmethod - @ResourcePolicyService.has_resource_permission(GET_DASHBOARD) def get_dashboard(uri: str) -> Dashboard: with get_context().db_engine.scoped_session() as session: return DashboardRepository.get_dashboard_by_uri(session, uri) + @staticmethod + @ResourcePolicyService.has_resource_permission(GET_DASHBOARD) + def get_dashboard_restricted_information(uri: str, dashboard: Dashboard): + return dashboard + @staticmethod @TenantPolicyService.has_tenant_permission(MANAGE_DASHBOARDS) @ResourcePolicyService.has_resource_permission(CREATE_DASHBOARD) diff --git a/frontend/src/modules/Dashboards/components/DashboardListItem.js b/frontend/src/modules/Dashboards/components/DashboardListItem.js index 17f40b9bd..a7f410562 100644 --- a/frontend/src/modules/Dashboards/components/DashboardListItem.js +++ b/frontend/src/modules/Dashboards/components/DashboardListItem.js @@ -159,7 +159,7 @@ export const DashboardListItem = (props) => { - {dashboard.AwsAccountId} + {dashboard.restricted.AwsAccountId} @@ -178,7 +178,7 @@ export const DashboardListItem = (props) => { - {dashboard.environment.region} + {dashboard.restricted.region} diff --git a/frontend/src/modules/Dashboards/components/DashboardOverview.js b/frontend/src/modules/Dashboards/components/DashboardOverview.js index 74953923e..09931d69a 100644 --- a/frontend/src/modules/Dashboards/components/DashboardOverview.js +++ b/frontend/src/modules/Dashboards/components/DashboardOverview.js @@ -30,7 +30,7 @@ export const DashboardOverview = (props) => { { const client = useClient(); const [dashboardRef] = useState(createRef()); const [sessionUrl, setSessionUrl] = useState(null); + const [loading, setLoading] = useState(false); const fetchReaderSessionUrl = useCallback(async () => { + setLoading(true); const response = await client.query( getReaderSession(dashboard.dashboardUri) ); @@ -40,6 +42,7 @@ export const DashboardViewer = ({ dashboard }) => { } else { dispatch({ type: SET_ERROR, error: response.errors[0].message }); } + setLoading(false); }, [client, dispatch, dashboard, dashboardRef]); useEffect(() => { @@ -50,7 +53,10 @@ export const DashboardViewer = ({ dashboard }) => { } }, [client, dispatch, fetchReaderSessionUrl, sessionUrl]); - if (!sessionUrl) { + if (!sessionUrl && !loading) { + return null; + } + if (loading) { return ; } return ( diff --git a/frontend/src/modules/Dashboards/services/getDashboard.js b/frontend/src/modules/Dashboards/services/getDashboard.js index 2c1148d85..5a17d6f64 100644 --- a/frontend/src/modules/Dashboards/services/getDashboard.js +++ b/frontend/src/modules/Dashboards/services/getDashboard.js @@ -18,10 +18,13 @@ export const getDashboard = (dashboardUri) => ({ userRoleForDashboard DashboardId upvotes + restricted { + region + AwsAccountId + } environment { environmentUri label - region organization { organizationUri label diff --git a/frontend/src/modules/Dashboards/services/searchDashboards.js b/frontend/src/modules/Dashboards/services/searchDashboards.js index c3741f5d5..b149237a8 100644 --- a/frontend/src/modules/Dashboards/services/searchDashboards.js +++ b/frontend/src/modules/Dashboards/services/searchDashboards.js @@ -17,7 +17,10 @@ export const searchDashboards = (filter) => ({ name owner SamlGroupName - AwsAccountId + restricted { + region + AwsAccountId + } description label created @@ -27,7 +30,6 @@ export const searchDashboards = (filter) => ({ environment { environmentUri label - region } } } diff --git a/frontend/src/modules/Dashboards/views/DashboardView.js b/frontend/src/modules/Dashboards/views/DashboardView.js index d093546e7..0ebf5f742 100644 --- a/frontend/src/modules/Dashboards/views/DashboardView.js +++ b/frontend/src/modules/Dashboards/views/DashboardView.js @@ -47,7 +47,7 @@ const DashboardView = () => { const client = useClient(); const { enqueueSnackbar } = useSnackbar(); const navigate = useNavigate(); - const [currentTab, setCurrentTab] = useState('viewer'); + const [currentTab, setCurrentTab] = useState('overview'); const [loading, setLoading] = useState(true); const [isUpVoted, setIsUpVoted] = useState(false); const [upVotes, setUpvotes] = useState(null); @@ -119,7 +119,7 @@ const DashboardView = () => { const fetchItem = useCallback(async () => { setLoading(true); const response = await client.query(getDashboard(params.uri)); - if (!response.errors) { + if (response.data.getDashboard !== null) { setDashboard(response.data.getDashboard); setUpvotes(response.data.getDashboard.upvotes); setIsAdmin( diff --git a/tests/modules/dashboards/test_dashboards.py b/tests/modules/dashboards/test_dashboards.py index fe1f1054a..9b66acdfe 100644 --- a/tests/modules/dashboards/test_dashboards.py +++ b/tests/modules/dashboards/test_dashboards.py @@ -82,7 +82,6 @@ def test_get_dashboard(client, env_fixture, db, dashboard, group): environment { environmentUri label - region organization { organizationUri label diff --git a/tests_new/integration_tests/modules/dashboards/queries.py b/tests_new/integration_tests/modules/dashboards/queries.py index 047fb7de3..4d167a920 100644 --- a/tests_new/integration_tests/modules/dashboards/queries.py +++ b/tests_new/integration_tests/modules/dashboards/queries.py @@ -25,16 +25,18 @@ def search_dashboards(client, filter): owner SamlGroupName description - AwsAccountId label created tags userRoleForDashboard upvotes + restricted { + region + AwsAccountId + } environment { environmentUri label - region organization { organizationUri label @@ -65,10 +67,13 @@ def get_dashboard(client, dashboardUri): created tags userRoleForDashboard + restricted { + region + AwsAccountId + } environment { environmentUri label - region organization { organizationUri label