Unverified Commit 4124e265 authored by Benjamin Wheeler's avatar Benjamin Wheeler Committed by GitHub

set explicit capabilities like “can____” for GUI and project page (#2187)

* set explicit capabilities like “can____” for GUI and project page

* set canShare to proper value instead of hardcoding it

* don't tell gui canReport
parent 29a6a27f
...@@ -44,6 +44,8 @@ const onKeyPress = e => { ...@@ -44,6 +44,8 @@ const onKeyPress = e => {
const PreviewPresentation = ({ const PreviewPresentation = ({
assetHost, assetHost,
backpackOptions, backpackOptions,
canAddToStudio,
canReport,
comments, comments,
editable, editable,
extensions, extensions,
...@@ -171,12 +173,11 @@ const PreviewPresentation = ({ ...@@ -171,12 +173,11 @@ const PreviewPresentation = ({
/> />
<Subactions <Subactions
addToStudioOpen={addToStudioOpen} addToStudioOpen={addToStudioOpen}
isLoggedIn={isLoggedIn} canReport={canReport}
projectInfo={projectInfo} projectInfo={projectInfo}
reportOpen={reportOpen} reportOpen={reportOpen}
shareDate={shareDate} shareDate={shareDate}
studios={studios} studios={studios}
userOwnsProject={userOwnsProject}
onAddToStudioClicked={onAddToStudioClicked} onAddToStudioClicked={onAddToStudioClicked}
onAddToStudioClosed={onAddToStudioClosed} onAddToStudioClosed={onAddToStudioClosed}
onReportClicked={onReportClicked} onReportClicked={onReportClicked}
...@@ -284,12 +285,12 @@ const PreviewPresentation = ({ ...@@ -284,12 +285,12 @@ const PreviewPresentation = ({
/> />
<Subactions <Subactions
addToStudioOpen={addToStudioOpen} addToStudioOpen={addToStudioOpen}
isLoggedIn={isLoggedIn} canAddToStudio={canAddToStudio}
canReport={canReport}
projectInfo={projectInfo} projectInfo={projectInfo}
reportOpen={reportOpen} reportOpen={reportOpen}
shareDate={shareDate} shareDate={shareDate}
studios={studios} studios={studios}
userOwnsProject={userOwnsProject}
onAddToStudioClicked={onAddToStudioClicked} onAddToStudioClicked={onAddToStudioClicked}
onAddToStudioClosed={onAddToStudioClosed} onAddToStudioClosed={onAddToStudioClosed}
onReportClicked={onReportClicked} onReportClicked={onReportClicked}
...@@ -404,6 +405,8 @@ PreviewPresentation.propTypes = { ...@@ -404,6 +405,8 @@ PreviewPresentation.propTypes = {
host: PropTypes.string, host: PropTypes.string,
visible: PropTypes.bool visible: PropTypes.bool
}), }),
canAddToStudio: PropTypes.bool,
canReport: PropTypes.bool,
comments: PropTypes.arrayOf(PropTypes.object), comments: PropTypes.arrayOf(PropTypes.object),
editable: PropTypes.bool, editable: PropTypes.bool,
extensions: PropTypes.arrayOf(PropTypes.object), extensions: PropTypes.arrayOf(PropTypes.object),
......
...@@ -337,6 +337,8 @@ class Preview extends React.Component { ...@@ -337,6 +337,8 @@ class Preview extends React.Component {
addToStudioOpen={this.state.addToStudioOpen} addToStudioOpen={this.state.addToStudioOpen}
assetHost={this.props.assetHost} assetHost={this.props.assetHost}
backpackOptions={this.props.backpackOptions} backpackOptions={this.props.backpackOptions}
canAddToStudio={this.props.canAddToStudio}
canReport={this.props.canReport}
comments={this.props.comments} comments={this.props.comments}
editable={this.props.isEditable} editable={this.props.isEditable}
extensions={this.state.extensions} extensions={this.state.extensions}
...@@ -382,6 +384,11 @@ class Preview extends React.Component { ...@@ -382,6 +384,11 @@ class Preview extends React.Component {
assetHost={this.props.assetHost} assetHost={this.props.assetHost}
backpackOptions={this.props.backpackOptions} backpackOptions={this.props.backpackOptions}
basePath="/" basePath="/"
canCreateNew={this.props.canCreateNew}
canRemix={this.props.canRemix}
canSave={this.props.canSave}
canSaveAsCopy={this.props.canSaveAsCopy}
canShare={this.props.canShare}
className="gui" className="gui"
projectHost={this.props.projectHost} projectHost={this.props.projectHost}
projectId={this.state.projectId} projectId={this.state.projectId}
...@@ -407,6 +414,13 @@ Preview.propTypes = { ...@@ -407,6 +414,13 @@ Preview.propTypes = {
host: PropTypes.string, host: PropTypes.string,
visible: PropTypes.bool visible: PropTypes.bool
}), }),
canAddToStudio: PropTypes.bool,
canCreateNew: PropTypes.bool,
canRemix: PropTypes.bool,
canReport: PropTypes.bool,
canSave: PropTypes.bool,
canSaveAsCopy: PropTypes.bool,
canShare: PropTypes.bool,
comments: PropTypes.arrayOf(PropTypes.object), comments: PropTypes.arrayOf(PropTypes.object),
faved: PropTypes.bool, faved: PropTypes.bool,
fullScreen: PropTypes.bool, fullScreen: PropTypes.bool,
...@@ -513,8 +527,17 @@ const mapStateToProps = state => { ...@@ -513,8 +527,17 @@ const mapStateToProps = state => {
userPresent; userPresent;
const authorPresent = projectInfoPresent && state.preview.projectInfo.author && const authorPresent = projectInfoPresent && state.preview.projectInfo.author &&
Object.keys(state.preview.projectInfo.author).length > 0; Object.keys(state.preview.projectInfo.author).length > 0;
const userOwnsProject = isLoggedIn && authorPresent &&
state.session.session.user.id === state.preview.projectInfo.author.id;
return { return {
canAddToStudio: isLoggedIn && userOwnsProject,
canCreateNew: false,
canRemix: false,
canReport: isLoggedIn && !userOwnsProject,
canSave: userOwnsProject,
canSaveAsCopy: false,
canShare: userOwnsProject && state.permissions.social,
comments: state.preview.comments, comments: state.preview.comments,
faved: state.preview.faved, faved: state.preview.faved,
fullScreen: state.scratchGui.mode.isFullScreen, fullScreen: state.scratchGui.mode.isFullScreen,
...@@ -542,8 +565,7 @@ const mapStateToProps = state => { ...@@ -542,8 +565,7 @@ const mapStateToProps = state => {
state.preview.projectStudios, state.preview.currentStudioIds, state.preview.projectStudios, state.preview.currentStudioIds,
state.preview.status.studioRequests), state.preview.status.studioRequests),
user: state.session.session.user, user: state.session.session.user,
userOwnsProject: isLoggedIn && authorPresent && userOwnsProject: userOwnsProject
state.session.session.user.id === state.preview.projectInfo.author.id
}; };
}; };
......
...@@ -27,7 +27,7 @@ const Subactions = props => ( ...@@ -27,7 +27,7 @@ const Subactions = props => (
{/* eslint-enable react/jsx-sort-props */} {/* eslint-enable react/jsx-sort-props */}
</div> </div>
<FlexRow className="action-buttons"> <FlexRow className="action-buttons">
{(props.isLoggedIn && props.userOwnsProject) && {props.canAddToStudio &&
<React.Fragment> <React.Fragment>
<Button <Button
className="action-button studio-button" className="action-button studio-button"
...@@ -48,7 +48,7 @@ const Subactions = props => ( ...@@ -48,7 +48,7 @@ const Subactions = props => (
<Button className="action-button copy-link-button"> <Button className="action-button copy-link-button">
Copy Link Copy Link
</Button> </Button>
{(props.isLoggedIn && !props.userOwnsProject) && {(props.canReport) &&
<React.Fragment> <React.Fragment>
<Button <Button
className="action-button report-button" className="action-button report-button"
...@@ -72,7 +72,8 @@ const Subactions = props => ( ...@@ -72,7 +72,8 @@ const Subactions = props => (
Subactions.propTypes = { Subactions.propTypes = {
addToStudioOpen: PropTypes.bool, addToStudioOpen: PropTypes.bool,
isLoggedIn: PropTypes.bool, canAddToStudio: PropTypes.bool,
canReport: PropTypes.bool,
onAddToStudioClicked: PropTypes.func, onAddToStudioClicked: PropTypes.func,
onAddToStudioClosed: PropTypes.func, onAddToStudioClosed: PropTypes.func,
onReportClicked: PropTypes.func.isRequired, onReportClicked: PropTypes.func.isRequired,
...@@ -81,9 +82,7 @@ Subactions.propTypes = { ...@@ -81,9 +82,7 @@ Subactions.propTypes = {
onToggleStudio: PropTypes.func, onToggleStudio: PropTypes.func,
reportOpen: PropTypes.bool, reportOpen: PropTypes.bool,
shareDate: PropTypes.string, shareDate: PropTypes.string,
studios: PropTypes.arrayOf(PropTypes.object), studios: PropTypes.arrayOf(PropTypes.object)
userOwnsProject: PropTypes.bool
}; };
module.exports = Subactions; module.exports = Subactions;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment