mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-02-17 00:21:20 -05:00
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
This commit is contained in:
parent
29a6a27f46
commit
4124e26588
3 changed files with 36 additions and 12 deletions
|
@ -44,6 +44,8 @@ const onKeyPress = e => {
|
|||
const PreviewPresentation = ({
|
||||
assetHost,
|
||||
backpackOptions,
|
||||
canAddToStudio,
|
||||
canReport,
|
||||
comments,
|
||||
editable,
|
||||
extensions,
|
||||
|
@ -171,12 +173,11 @@ const PreviewPresentation = ({
|
|||
/>
|
||||
<Subactions
|
||||
addToStudioOpen={addToStudioOpen}
|
||||
isLoggedIn={isLoggedIn}
|
||||
canReport={canReport}
|
||||
projectInfo={projectInfo}
|
||||
reportOpen={reportOpen}
|
||||
shareDate={shareDate}
|
||||
studios={studios}
|
||||
userOwnsProject={userOwnsProject}
|
||||
onAddToStudioClicked={onAddToStudioClicked}
|
||||
onAddToStudioClosed={onAddToStudioClosed}
|
||||
onReportClicked={onReportClicked}
|
||||
|
@ -284,12 +285,12 @@ const PreviewPresentation = ({
|
|||
/>
|
||||
<Subactions
|
||||
addToStudioOpen={addToStudioOpen}
|
||||
isLoggedIn={isLoggedIn}
|
||||
canAddToStudio={canAddToStudio}
|
||||
canReport={canReport}
|
||||
projectInfo={projectInfo}
|
||||
reportOpen={reportOpen}
|
||||
shareDate={shareDate}
|
||||
studios={studios}
|
||||
userOwnsProject={userOwnsProject}
|
||||
onAddToStudioClicked={onAddToStudioClicked}
|
||||
onAddToStudioClosed={onAddToStudioClosed}
|
||||
onReportClicked={onReportClicked}
|
||||
|
@ -404,6 +405,8 @@ PreviewPresentation.propTypes = {
|
|||
host: PropTypes.string,
|
||||
visible: PropTypes.bool
|
||||
}),
|
||||
canAddToStudio: PropTypes.bool,
|
||||
canReport: PropTypes.bool,
|
||||
comments: PropTypes.arrayOf(PropTypes.object),
|
||||
editable: PropTypes.bool,
|
||||
extensions: PropTypes.arrayOf(PropTypes.object),
|
||||
|
|
|
@ -337,6 +337,8 @@ class Preview extends React.Component {
|
|||
addToStudioOpen={this.state.addToStudioOpen}
|
||||
assetHost={this.props.assetHost}
|
||||
backpackOptions={this.props.backpackOptions}
|
||||
canAddToStudio={this.props.canAddToStudio}
|
||||
canReport={this.props.canReport}
|
||||
comments={this.props.comments}
|
||||
editable={this.props.isEditable}
|
||||
extensions={this.state.extensions}
|
||||
|
@ -382,6 +384,11 @@ class Preview extends React.Component {
|
|||
assetHost={this.props.assetHost}
|
||||
backpackOptions={this.props.backpackOptions}
|
||||
basePath="/"
|
||||
canCreateNew={this.props.canCreateNew}
|
||||
canRemix={this.props.canRemix}
|
||||
canSave={this.props.canSave}
|
||||
canSaveAsCopy={this.props.canSaveAsCopy}
|
||||
canShare={this.props.canShare}
|
||||
className="gui"
|
||||
projectHost={this.props.projectHost}
|
||||
projectId={this.state.projectId}
|
||||
|
@ -407,6 +414,13 @@ Preview.propTypes = {
|
|||
host: PropTypes.string,
|
||||
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),
|
||||
faved: PropTypes.bool,
|
||||
fullScreen: PropTypes.bool,
|
||||
|
@ -513,8 +527,17 @@ const mapStateToProps = state => {
|
|||
userPresent;
|
||||
const authorPresent = projectInfoPresent && state.preview.projectInfo.author &&
|
||||
Object.keys(state.preview.projectInfo.author).length > 0;
|
||||
const userOwnsProject = isLoggedIn && authorPresent &&
|
||||
state.session.session.user.id === state.preview.projectInfo.author.id;
|
||||
|
||||
return {
|
||||
canAddToStudio: isLoggedIn && userOwnsProject,
|
||||
canCreateNew: false,
|
||||
canRemix: false,
|
||||
canReport: isLoggedIn && !userOwnsProject,
|
||||
canSave: userOwnsProject,
|
||||
canSaveAsCopy: false,
|
||||
canShare: userOwnsProject && state.permissions.social,
|
||||
comments: state.preview.comments,
|
||||
faved: state.preview.faved,
|
||||
fullScreen: state.scratchGui.mode.isFullScreen,
|
||||
|
@ -542,8 +565,7 @@ const mapStateToProps = state => {
|
|||
state.preview.projectStudios, state.preview.currentStudioIds,
|
||||
state.preview.status.studioRequests),
|
||||
user: state.session.session.user,
|
||||
userOwnsProject: isLoggedIn && authorPresent &&
|
||||
state.session.session.user.id === state.preview.projectInfo.author.id
|
||||
userOwnsProject: userOwnsProject
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ const Subactions = props => (
|
|||
{/* eslint-enable react/jsx-sort-props */}
|
||||
</div>
|
||||
<FlexRow className="action-buttons">
|
||||
{(props.isLoggedIn && props.userOwnsProject) &&
|
||||
{props.canAddToStudio &&
|
||||
<React.Fragment>
|
||||
<Button
|
||||
className="action-button studio-button"
|
||||
|
@ -48,7 +48,7 @@ const Subactions = props => (
|
|||
<Button className="action-button copy-link-button">
|
||||
Copy Link
|
||||
</Button>
|
||||
{(props.isLoggedIn && !props.userOwnsProject) &&
|
||||
{(props.canReport) &&
|
||||
<React.Fragment>
|
||||
<Button
|
||||
className="action-button report-button"
|
||||
|
@ -72,7 +72,8 @@ const Subactions = props => (
|
|||
|
||||
Subactions.propTypes = {
|
||||
addToStudioOpen: PropTypes.bool,
|
||||
isLoggedIn: PropTypes.bool,
|
||||
canAddToStudio: PropTypes.bool,
|
||||
canReport: PropTypes.bool,
|
||||
onAddToStudioClicked: PropTypes.func,
|
||||
onAddToStudioClosed: PropTypes.func,
|
||||
onReportClicked: PropTypes.func.isRequired,
|
||||
|
@ -81,9 +82,7 @@ Subactions.propTypes = {
|
|||
onToggleStudio: PropTypes.func,
|
||||
reportOpen: PropTypes.bool,
|
||||
shareDate: PropTypes.string,
|
||||
studios: PropTypes.arrayOf(PropTypes.object),
|
||||
userOwnsProject: PropTypes.bool
|
||||
|
||||
studios: PropTypes.arrayOf(PropTypes.object)
|
||||
};
|
||||
|
||||
module.exports = Subactions;
|
||||
|
|
Loading…
Reference in a new issue