start to fix editing permissions for the sidebar

This commit is contained in:
Cassie Tarakajian 2017-04-11 20:06:04 -04:00
parent 7be45ce875
commit 94694c5a72
3 changed files with 34 additions and 2 deletions

View file

@ -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() { render() {
const sidebarClass = classNames({ const sidebarClass = classNames({
'sidebar': true, 'sidebar': true,
'sidebar--contracted': !this.props.isExpanded, 'sidebar--contracted': !this.props.isExpanded,
'sidebar--project-options': this.props.projectOptionsVisible 'sidebar--project-options': this.props.projectOptionsVisible,
'sidebar--cant-edit': !this.userCanEditProject()
}); });
return ( return (
@ -85,7 +98,18 @@ Sidebar.propTypes = {
newFile: PropTypes.func.isRequired, newFile: PropTypes.func.isRequired,
openProjectOptions: PropTypes.func.isRequired, openProjectOptions: PropTypes.func.isRequired,
closeProjectOptions: 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; export default Sidebar;

View file

@ -265,6 +265,8 @@ class IDEView extends React.Component {
openProjectOptions={this.props.openProjectOptions} openProjectOptions={this.props.openProjectOptions}
closeProjectOptions={this.props.closeProjectOptions} closeProjectOptions={this.props.closeProjectOptions}
newFolder={this.props.newFolder} newFolder={this.props.newFolder}
user={this.props.user}
owner={this.props.project.owner}
/> />
<SplitPane <SplitPane
split="vertical" split="vertical"

View file

@ -131,6 +131,9 @@
right: 0; right: 0;
.sidebar__file-item--selected > .file-item__content & { .sidebar__file-item--selected > .file-item__content & {
display: inline-block; display: inline-block;
.sidebar--cant-edit & {
display: none;
}
} }
& svg { & svg {
width: #{10 / $base-font-size}rem; width: #{10 / $base-font-size}rem;
@ -212,6 +215,9 @@
display: flex; display: flex;
align-items: center; align-items: center;
position: relative; position: relative;
.sidebar--cant-edit & {
display: none;
}
} }
.sidebar__folder-icon { .sidebar__folder-icon {