From 94694c5a725e092336f189668b31b76ea82bcc1c Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 11 Apr 2017 20:06:04 -0400 Subject: [PATCH] start to fix editing permissions for the sidebar --- client/modules/IDE/components/Sidebar.jsx | 28 +++++++++++++++++++++-- client/modules/IDE/pages/IDEView.jsx | 2 ++ client/styles/components/_sidebar.scss | 6 +++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/client/modules/IDE/components/Sidebar.jsx b/client/modules/IDE/components/Sidebar.jsx index f73bb7b6..902a393f 100644 --- a/client/modules/IDE/components/Sidebar.jsx +++ b/client/modules/IDE/components/Sidebar.jsx @@ -27,11 +27,24 @@ class Sidebar extends React.Component { } } + userCanEditProject() { + let canEdit; + if (!this.props.owner) { + canEdit = true; + } else if (this.props.user.authenticated && this.props.owner.id === this.props.user.id) { + canEdit = true; + } else { + canEdit = false; + } + return canEdit; + } + render() { const sidebarClass = classNames({ 'sidebar': true, 'sidebar--contracted': !this.props.isExpanded, - 'sidebar--project-options': this.props.projectOptionsVisible + 'sidebar--project-options': this.props.projectOptionsVisible, + 'sidebar--cant-edit': !this.userCanEditProject() }); return ( @@ -85,7 +98,18 @@ Sidebar.propTypes = { newFile: PropTypes.func.isRequired, openProjectOptions: PropTypes.func.isRequired, closeProjectOptions: PropTypes.func.isRequired, - newFolder: PropTypes.func.isRequired + newFolder: PropTypes.func.isRequired, + owner: PropTypes.shape({ + id: PropTypes.string + }), + user: PropTypes.shape({ + id: PropTypes.string, + authenticated: PropTypes.bool.isRequired + }).isRequired +}; + +Sidebar.defaultProps = { + owner: undefined }; export default Sidebar; diff --git a/client/modules/IDE/pages/IDEView.jsx b/client/modules/IDE/pages/IDEView.jsx index bf097d7e..31f0af47 100644 --- a/client/modules/IDE/pages/IDEView.jsx +++ b/client/modules/IDE/pages/IDEView.jsx @@ -265,6 +265,8 @@ class IDEView extends React.Component { openProjectOptions={this.props.openProjectOptions} closeProjectOptions={this.props.closeProjectOptions} newFolder={this.props.newFolder} + user={this.props.user} + owner={this.props.project.owner} /> .file-item__content & { display: inline-block; + .sidebar--cant-edit & { + display: none; + } } & svg { width: #{10 / $base-font-size}rem; @@ -212,6 +215,9 @@ display: flex; align-items: center; position: relative; + .sidebar--cant-edit & { + display: none; + } } .sidebar__folder-icon {