Skip to content

Commit

Permalink
fix(EditorFeedSourcePanel): disable buttons based on user permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed Jun 22, 2017
1 parent 5e98908 commit 352008f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
22 changes: 18 additions & 4 deletions lib/editor/components/EditorFeedSourcePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ export default class EditorFeedSourcePanel extends Component {

render () {
const {
feedSource
feedSource,
project,
user
} = this.props
const disabled = !user.permissions.hasFeedPermission(project.organizationId, project.id, feedSource.id, 'manage-feed')
const editDisabled = !user.permissions.hasFeedPermission(project.organizationId, project.id, feedSource.id, 'edit-gtfs')
const hasVersions = feedSource && feedSource.feedVersions && feedSource.feedVersions.length > 0
const currentSnapshot = feedSource.editorSnapshots && feedSource.editorSnapshots.length
? feedSource.editorSnapshots.find(s => s.current)
Expand All @@ -68,6 +72,7 @@ export default class EditorFeedSourcePanel extends Component {
? <ListGroup fill>
<SnapshotItem
modal={this.refs.confirmModal}
disabled={disabled}
snapshot={currentSnapshot}
{...this.props} />
</ListGroup>
Expand All @@ -82,7 +87,12 @@ export default class EditorFeedSourcePanel extends Component {
? <ListGroupItem>No other snapshots</ListGroupItem>
: inactiveSnapshots.map(s => {
return (
<SnapshotItem modal={this.refs.confirmModal} key={s.id} snapshot={s} {...this.props} />
<SnapshotItem
modal={this.refs.confirmModal}
key={s.id}
disabled={disabled}
snapshot={s}
{...this.props} />
)
})
}
Expand Down Expand Up @@ -110,13 +120,15 @@ export default class EditorFeedSourcePanel extends Component {
<Col xs={3}>
<LinkContainer to={`/feed/${feedSource.id}/edit`}>
<Button
disabled={editDisabled}
block>
<Icon type='pencil' /> Edit feed
</Button>
</LinkContainer>
<Button
block
bsStyle='primary'
disabled={editDisabled}
style={{marginBottom: '20px'}}
onClick={this._openModal}>
<Icon type='camera' /> Take snapshot of latest changes
Expand Down Expand Up @@ -163,7 +175,7 @@ class SnapshotItem extends Component {
}

render () {
const {snapshot} = this.props
const {disabled, snapshot} = this.props
const dateFormat = getConfigProperty('application.date_format')
const timeFormat = 'h:MMa'
return (
Expand All @@ -178,7 +190,7 @@ class SnapshotItem extends Component {
<ButtonGroup className='pull-right' style={{marginTop: '-20px'}}>
<Button
bsSize='small'
disabled={snapshot.current}
disabled={snapshot.current || disabled}
onClick={this._onRestoreSnapshot}>
{snapshot.current
? <span><Icon type='check-circle' /> {getMessage(this.messages, 'active')}</span>
Expand All @@ -192,11 +204,13 @@ class SnapshotItem extends Component {
</Button>
<Button
bsSize='small'
disabled={disabled}
onClick={this._onClickExport}>
<Glyphicon glyph='export' /> {getMessage(this.messages, 'publish')}
</Button>
<Button
bsSize='small'
disabled={disabled}
onClick={this._onDeleteSnapshot}>
<span className='text-danger'><Icon type='trash' /> {getMessage(this.messages, 'delete')}</span>
</Button>
Expand Down
5 changes: 4 additions & 1 deletion lib/editor/containers/ActiveEditorFeedSourcePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { createFeedVersionFromSnapshot } from '../../manager/actions/versions'
import EditorFeedSourcePanel from '../components/EditorFeedSourcePanel'

const mapStateToProps = (state, ownProps) => {
return {}
const {user} = state
return {
user
}
}

const mapDispatchToProps = {
Expand Down

0 comments on commit 352008f

Please # to comment.