admins should not see editable project title in editor

This commit is contained in:
Ben Wheeler 2018-12-19 11:57:50 -05:00
parent d13a773f7c
commit 5ff13da56d

View file

@ -655,7 +655,7 @@ class Preview extends React.Component {
basePath="/" basePath="/"
canCreateCopy={this.props.canCreateCopy} canCreateCopy={this.props.canCreateCopy}
canCreateNew={this.props.canCreateNew} canCreateNew={this.props.canCreateNew}
canEditTitle={this.props.isEditable} canEditTitle={this.props.canEditTitleInEditor}
canRemix={this.props.canRemix} canRemix={this.props.canRemix}
canSave={this.props.canSave} canSave={this.props.canSave}
canShare={this.props.canShare} canShare={this.props.canShare}
@ -700,6 +700,7 @@ Preview.propTypes = {
canAddToStudio: PropTypes.bool, canAddToStudio: PropTypes.bool,
canCreateCopy: PropTypes.bool, canCreateCopy: PropTypes.bool,
canCreateNew: PropTypes.bool, canCreateNew: PropTypes.bool,
canEditTitleInEditor: PropTypes.bool,
canRemix: PropTypes.bool, canRemix: PropTypes.bool,
canReport: PropTypes.bool, canReport: PropTypes.bool,
canSave: PropTypes.bool, canSave: PropTypes.bool,
@ -808,6 +809,9 @@ const mapStateToProps = state => {
const authorUsername = authorPresent && author.username; const authorUsername = authorPresent && author.username;
const userOwnsProject = isLoggedIn && authorPresent && const userOwnsProject = isLoggedIn && authorPresent &&
state.session.session.user.id.toString() === authorId; state.session.session.user.id.toString() === authorId;
const isEditable = isLoggedIn &&
(authorUsername === state.session.session.user.username ||
state.permissions.admin === true);
// if we don't have projectInfo, assume it's shared until we know otherwise // if we don't have projectInfo, assume it's shared until we know otherwise
const isShared = !projectInfoPresent || state.preview.projectInfo.is_published; const isShared = !projectInfoPresent || state.preview.projectInfo.is_published;
@ -819,6 +823,8 @@ const mapStateToProps = state => {
canAddToStudio: isLoggedIn && isShared, canAddToStudio: isLoggedIn && isShared,
canCreateCopy: userOwnsProject && projectInfoPresent, canCreateCopy: userOwnsProject && projectInfoPresent,
canCreateNew: isLoggedIn, canCreateNew: isLoggedIn,
// admins want to see author credit in editor; only let them edit title if they own project
canEditTitleInEditor: isEditable && (userOwnsProject || !isAdmin),
canRemix: isLoggedIn && projectInfoPresent && !userOwnsProject, canRemix: isLoggedIn && projectInfoPresent && !userOwnsProject,
canReport: isLoggedIn && !userOwnsProject, canReport: isLoggedIn && !userOwnsProject,
canSave: isLoggedIn && userOwnsProject, canSave: isLoggedIn && userOwnsProject,
@ -832,9 +838,7 @@ const mapStateToProps = state => {
fullScreen: state.scratchGui.mode.isFullScreen, fullScreen: state.scratchGui.mode.isFullScreen,
// project is editable iff logged in user is the author of the project, or // project is editable iff logged in user is the author of the project, or
// logged in user is an admin. // logged in user is an admin.
isEditable: isLoggedIn && isEditable: isEditable,
(authorUsername === state.session.session.user.username ||
state.permissions.admin === true),
isLoggedIn: isLoggedIn, isLoggedIn: isLoggedIn,
isAdmin: isAdmin, isAdmin: isAdmin,
isNewScratcher: isLoggedIn && state.permissions.new_scratcher, isNewScratcher: isLoggedIn && state.permissions.new_scratcher,