Skip to content

Commit 41637d2

Browse files
committed
Move handleUploadClick from inline function, prevent user from uploading to folder if not authenticated
1 parent 9185447 commit 41637d2

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

client/components/__test__/FileNode.test.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('<FileNode />', () => {
2424
showFolderChildren: jest.fn(),
2525
hideFolderChildren: jest.fn(),
2626
canEdit: true,
27+
authenticated: false
2728
};
2829
component = shallow(<FileNode {...props} />);
2930
});

client/modules/IDE/components/FileNode.jsx

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ export class FileNode extends React.Component {
8787
setTimeout(() => this.hideFileOptions(), 0);
8888
}
8989

90+
handleClickUploadFile = () => {
91+
this.props.openUploadFileModal(this.props.id);
92+
setTimeout(this.hideFileOptions, 0);
93+
}
94+
9095
handleClickDelete = () => {
9196
if (window.confirm(`Are you sure you want to delete ${this.props.name}?`)) {
9297
this.setState({ isDeleting: true });
@@ -252,19 +257,18 @@ export class FileNode extends React.Component {
252257
Create file
253258
</button>
254259
</li>
255-
<li>
256-
<button
257-
aria-label="upload file"
258-
onClick={() => {
259-
this.props.openUploadFileModal(this.props.id);
260-
setTimeout(this.hideFileOptions, 0);
261-
}}
262-
onBlur={this.onBlurComponent}
263-
onFocus={this.onFocusComponent}
264-
>
265-
Upload file
266-
</button>
267-
</li>
260+
{ this.props.authenticated &&
261+
<li>
262+
<button
263+
aria-label="upload file"
264+
onClick={this.handleClickUploadFile}
265+
onBlur={this.onBlurComponent}
266+
onFocus={this.onFocusComponent}
267+
>
268+
Upload file
269+
</button>
270+
</li>
271+
}
268272
</React.Fragment>
269273
}
270274
<li>
@@ -318,7 +322,8 @@ FileNode.propTypes = {
318322
showFolderChildren: PropTypes.func.isRequired,
319323
hideFolderChildren: PropTypes.func.isRequired,
320324
canEdit: PropTypes.bool.isRequired,
321-
openUploadFileModal: PropTypes.func.isRequired
325+
openUploadFileModal: PropTypes.func.isRequired,
326+
authenticated: PropTypes.bool.isRequired
322327
};
323328

324329
FileNode.defaultProps = {
@@ -329,7 +334,8 @@ FileNode.defaultProps = {
329334

330335
function mapStateToProps(state, ownProps) {
331336
// this is a hack, state is updated before ownProps
332-
return state.files.find(file => file.id === ownProps.id) || { name: 'test', fileType: 'file' };
337+
const fileNode = state.files.find(file => file.id === ownProps.id) || { name: 'test', fileType: 'file' };
338+
return Object.assign({}, fileNode, { authenticated: state.user.authenticated });
333339
}
334340

335341
function mapDispatchToProps(dispatch) {

0 commit comments

Comments
 (0)