Skip to content

Commit 3b79c2e

Browse files
committed
fix(settings): prevent access to settings for non-managers
1 parent 0513ea1 commit 3b79c2e

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

lib/manager/components/FeedSourceSettings.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,29 @@ export default class FeedSourceSettings extends Component {
6565
project,
6666
user
6767
} = this.props
68+
const {
69+
name,
70+
url
71+
} = this.state
6872
// const messages = getComponentMessages('FeedSourceSettings')
6973
const disabled = !user.permissions.hasFeedPermission(project.organizationId, project.id, feedSource.id, 'manage-feed')
7074
const isProjectAdmin = user.permissions.isProjectAdmin(project.id, project.organizationId)
7175
// const editGtfsDisabled = !user.permissions.hasFeedPermission(project.organizationId, project.id, feedSource.id, 'edit-gtfs')
7276
const autoFetchFeed = feedSource.retrievalMethod === 'FETCHED_AUTOMATICALLY'
7377
const resourceType = activeComponent === 'settings' && activeSubComponent && activeSubComponent.toUpperCase()
78+
if (disabled) {
79+
return (
80+
<Row>
81+
<Col xs={6} mdOffset={3}>
82+
<p className='lead text-center'><strong>Warning!</strong> You do not have permission to edit details for this feed source.</p>
83+
</Col>
84+
</Row>
85+
)
86+
}
7487
return (
7588
<Row>
7689
<Col xs={3}>
90+
{/* Side panel */}
7791
<Panel>
7892
<ListGroup fill>
7993
<LinkContainer
@@ -98,19 +112,21 @@ export default class FeedSourceSettings extends Component {
98112
<Col xs={6} />
99113
{!resourceType
100114
? <Col xs={7}>
115+
{/* Settings */}
101116
<Panel header={<h3>Settings</h3>}>
102117
<ListGroup fill>
103118
<ListGroupItem>
104119
<FormGroup>
105120
<ControlLabel>Feed source name</ControlLabel>
106121
<InputGroup>
107122
<FormControl
108-
value={typeof this.state.name !== 'undefined' ? this.state.name : feedSource.name}
123+
value={name || feedSource.name}
109124
name={'name'}
125+
disabled={disabled}
110126
onChange={this._onChange} />
111127
<InputGroup.Button>
112128
<Button
113-
disabled={!this.state.name || this.state.name === feedSource.name} // disable if no change or no value.
129+
disabled={disabled || !name || name === feedSource.name} // disable if no change or no value.
114130
onClick={this._onNameSaved}>
115131
Rename
116132
</Button>
@@ -137,12 +153,13 @@ export default class FeedSourceSettings extends Component {
137153
<ControlLabel>Feed source fetch URL</ControlLabel>
138154
<InputGroup>
139155
<FormControl
140-
value={typeof this.state.url !== 'undefined' ? this.state.url : feedSource.url || ''}
156+
value={url || feedSource.url}
141157
name={'url'}
158+
disabled={disabled}
142159
onChange={this._onChange} />
143160
<InputGroup.Button>
144161
<Button
145-
disabled={this.state.url === feedSource.url} // disable if no change.
162+
disabled={disabled || url === feedSource.url} // disable if no change.
146163
onClick={this._onSaveUrl}>
147164
Change URL
148165
</Button>
@@ -154,6 +171,7 @@ export default class FeedSourceSettings extends Component {
154171
<FormGroup>
155172
<Checkbox
156173
checked={autoFetchFeed}
174+
disabled={disabled}
157175
onChange={this._onToggleAutoFetch}
158176
bsStyle='danger'>
159177
<strong>Auto fetch feed source</strong>
@@ -168,6 +186,7 @@ export default class FeedSourceSettings extends Component {
168186
<ListGroupItem>
169187
<Button
170188
onClick={this._onTogglePublic}
189+
disabled={disabled}
171190
className='pull-right'>
172191
Make {feedSource.isPublic ? 'private' : 'public'}
173192
</Button>
@@ -178,6 +197,7 @@ export default class FeedSourceSettings extends Component {
178197
<Button
179198
onClick={confirmDeleteFeedSource}
180199
className='pull-right'
200+
disabled={disabled}
181201
bsStyle='danger'>
182202
<Icon type='trash' /> Delete feed source
183203
</Button>

lib/manager/components/GeneralSettings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ export default class GeneralSettings extends Component {
141141
const {project, editDisabled} = this.props
142142
const noEdits = Object.keys(this.state.general).length === 0 && this.state.general.constructor === Object
143143
const autoFetchChecked = typeof this.state.general.autoFetchFeeds !== 'undefined' ? this.state.general.autoFetchFeeds : project.autoFetchFeeds
144+
if (editDisabled) {
145+
return <p className='lead text-center'><strong>Warning!</strong> You do not have permission to edit details for this feed source.</p>
146+
}
144147
return (
145148
<div className='general-settings-panel'>
146149
<ConfirmModal ref='confirm' />

0 commit comments

Comments
 (0)