Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit

Permalink
Merge pull request #619 from BlueBrain/dev
Browse files Browse the repository at this point in the history
Merging changes for version 1.3.4
  • Loading branch information
dhaneshnm authored Apr 15, 2020
2 parents dc69df2 + 65f4c04 commit 6c08d69
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/shared/components/Loading/loading.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

.loading {
width: 100%;
padding: 30px;
margin: 18px 0;
padding: 0 15px 30px;
box-sizing: border-box;
transition: all ease-out 0.5s;

Expand Down
7 changes: 1 addition & 6 deletions src/shared/containers/ResourceEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import * as React from 'react';
import { useAsyncEffect } from 'use-async-effect';
import {
ExpandedResource,
ResourceSource,
Resource,
NexusClient,
} from '@bbp/nexus-sdk';
import { ExpandedResource, ResourceSource, Resource } from '@bbp/nexus-sdk';
import { useNexusContext } from '@bbp/react-nexus';

import ResourceEditor from '../components/ResourceEditor';
Expand Down
37 changes: 33 additions & 4 deletions src/shared/containers/ResourceViewContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
getOrgAndProjectFromProjectId,
matchPlugins,
pluginsMap,
getUsername,
getDestinationParam,
} from '../utils';
import { isDeprecated } from '../utils/nexusMaybe';

Expand Down Expand Up @@ -223,10 +225,7 @@ const ResourceViewContainer: React.FunctionComponent<{
duration: 4,
});
if (!user) {
const destination = location.pathname;
history.push(
`/login?destination=${encodeURIComponent(destination)}`
);
history.push(`/login${getDestinationParam()}`);
}
}

Expand Down Expand Up @@ -298,6 +297,36 @@ const ResourceViewContainer: React.FunctionComponent<{
<AccessControl
path={`/${orgLabel}/${projectLabel}`}
permissions={['resources/write']}
noAccessComponent={() => (
<div>
<p>
<Alert
message={
!filteredPlugins || filteredPlugins.length === 0
? `There are no plugin configured for this resource, and you don't have admin access. Please ask the resource creator: ${getUsername(
resource['_createdBy']
)} for more information.`
: `It looks like you don't have admin access. Please ask the resource creator: ${getUsername(
resource['_createdBy']
)} for more information.`
}
type="info"
/>
</p>
<ResourceEditorContainer
resourceId={resource['@id']}
orgLabel={orgLabel}
projectLabel={projectLabel}
rev={resource._rev}
defaultExpanded={
!!expandedFromQuery && expandedFromQuery === 'true'
}
defaultEditable={false}
onSubmit={() => {}}
onExpanded={handleExpanded}
/>
</div>
)}
>
<Collapse
defaultActiveKey={
Expand Down
29 changes: 26 additions & 3 deletions src/shared/containers/StudioContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { Resource } from '@bbp/nexus-sdk';
import { Resource, Identity } from '@bbp/nexus-sdk';
import { useNexusContext } from '@bbp/react-nexus';
import { notification, Empty, message } from 'antd';

import { useHistory } from 'react-router';
import EditStudio from '../components/Studio/EditStudio';
import StudioHeader from '../components/Studio/StudioHeader';
import { getDestinationParam } from '../utils';
import { resourcesWritePermissionsWrapper } from '../utils/permission';

type StudioContainerProps = {
Expand Down Expand Up @@ -36,11 +37,20 @@ const StudioContainer: React.FunctionComponent<StudioContainerProps> = ({
] = React.useState<StudioResource | null>(null);
const [workspaceIds, setWorkspaceIds] = React.useState<string[]>([]);
const nexus = useNexusContext();
const history = useHistory();

React.useEffect(() => {
fetchAndSetupStudio();
}, [orgLabel, projectLabel, studioId]);

const [identities, setIdentities] = React.useState<Identity[]>([]);

React.useEffect(() => {
nexus.Identity.list().then(({ identities }) => {
setIdentities(identities);
});
}, []); // Run only once.

const fetchAndSetupStudio = async () => {
nexus.Resource.get(orgLabel, projectLabel, studioId)
.then(value => {
Expand All @@ -52,7 +62,20 @@ const StudioContainer: React.FunctionComponent<StudioContainerProps> = ({
);
})
.catch(e => {
// TODO: show a meaningful error to the user.
if (e['@type'] === 'AuthorizationFailed') {
const user = identities.find(i => i['@type'] === 'User');
const message = user
? "You don't have the permissions to view the studio"
: 'Please login to view the studio';
notification.error({
message: 'Authentication error',
description: message,
duration: 4,
});
if (!user) {
history.push(`/login${getDestinationParam()}`);
}
}
});
};

Expand Down

0 comments on commit 6c08d69

Please sign in to comment.