Skip to content

Commit

Permalink
Merge pull request #764 from neuroscout/draft_ownership
Browse files Browse the repository at this point in the history
check if analysis is public or owned before rendering analysis builder in routes
  • Loading branch information
rwblair committed Jun 22, 2020
2 parents 36cff9a + fbf7efd commit fa964e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 4 additions & 3 deletions neuroscout/frontend/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ export default class Routes extends React.Component<AppState, {}> {
/>
<Route
path="/builder/:id"
render={props =>
<AnalysisBuilder
render={props => {
return <AnalysisBuilder
id={props.match.params.id}
updatedAnalysis={() => this.props.loadAnalyses()}
userOwns={this.props.analyses.filter((x) => x.id === props.match.params.id).length > 0}
datasets={this.props.datasets}
doTooltip={true}
/>}
/>;
}}
/>
<Route
exact={true}
Expand Down
16 changes: 14 additions & 2 deletions neuroscout/frontend/src/analysis_builder/Builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Redirect } from 'react-router-dom';
import { createBrowserHistory } from 'history';
import * as React from 'react';
import {
Tag, Tabs, Row, Button, Modal, Icon, message, Tooltip, Form, Input, Collapse
Alert, Tag, Tabs, Row, Button, Modal, Icon, message, Tooltip, Form, Input, Collapse
} from 'antd';
import { Prompt } from 'react-router-dom';
import Reflux from 'reflux';
Expand Down Expand Up @@ -55,7 +55,7 @@ const history = createBrowserHistory();
// const logo = require('./logo.svg');
const domainRoot = config.server_url;
const DEFAULT_SMOOTHING = 5;
const editableStatus = ['DRAFT', 'FAILED'];
let editableStatus = ['DRAFT', 'FAILED'];

const defaultConfig: AnalysisConfig = { smoothing: DEFAULT_SMOOTHING, predictorConfigs: {} };

Expand Down Expand Up @@ -226,6 +226,7 @@ type BuilderProps = {
export default class AnalysisBuilder extends Reflux.Component<any, BuilderProps & RouteComponentProps<{}>, Store> {
constructor(props: BuilderProps) {
super(props);
editableStatus = ['DRAFT', 'FAILED'];
this.state = initializeStore();
this.store = AuthStore;
// Load analysis from server if an analysis id is specified in the props
Expand All @@ -243,6 +244,9 @@ export default class AnalysisBuilder extends Reflux.Component<any, BuilderProps
})
.then((data: ApiAnalysis) => {
if (this.state.analysis404) { return; }
if (!this.props.userOwns && editableStatus.includes(data.status)) {
editableStatus = [];
}
if (editableStatus.includes(data.status)) {
this.setState({model: this.buildModel()});
} else if (data.model !== undefined) {
Expand Down Expand Up @@ -1106,6 +1110,14 @@ export default class AnalysisBuilder extends Reflux.Component<any, BuilderProps
className="builderTabs"
tabPosition="left"
>
{!this.props.userOwns && isDraft &&
<Alert
message="This analysis is a draft and is currently read only. Only the owner of this draft can edit it."
type="info"
showIcon={true}
style={{ marginBottom: '.5em' }}
/>
}
{isEditable && <TabPane tab="Overview" key="overview" disabled={!isEditable}>
<h2>Overview</h2>
<OverviewTab
Expand Down

0 comments on commit fa964e7

Please sign in to comment.