Skip to content

Commit 330a9d1

Browse files
committedJul 22, 2021
fix(FeedLabel): further permission checks
·
v5.0.1v0.0.0
1 parent 9fca12b commit 330a9d1

File tree

3 files changed

+96
-6
lines changed

3 files changed

+96
-6
lines changed
 

‎lib/common/components/FeedLabel.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// @flow
12
import React from 'react'
23
import tinycolor from 'tinycolor2'
34
import Icon from '@conveyal/woonerf/components/icon'
45

6+
import type { Label } from '../../types'
7+
import type {ManagerUserState} from '../../types/reducers'
58
import ConfirmModal from '../../common/components/ConfirmModal'
69
import LabelEditorModal from '../../manager/components/LabelEditorModal'
710

@@ -14,9 +17,19 @@ const getComplementaryColor = (cssHex, strength) => {
1417
return complementary.toHexString()
1518
}
1619

17-
export default class FeedLabel extends React.Component {
20+
export type Props = {
21+
checked?: boolean,
22+
deleteLabel?: Function,
23+
label: Label,
24+
onClick?: Function,
25+
small: boolean,
26+
user?: ManagerUserState
27+
}
28+
export type State = {}
29+
30+
export default class FeedLabel extends React.Component<Props, State> {
1831
_onConfirmDelete = () => {
19-
this.props.deleteLabel(this.props.label)
32+
this.props.deleteLabel && this.props.deleteLabel(this.props.label)
2033
}
2134

2235
_onClickDelete = () => {
@@ -28,7 +41,11 @@ export default class FeedLabel extends React.Component {
2841
}
2942

3043
render () {
31-
const {small, label, checked, onClick: labelOnClick} = this.props
44+
const {small, label, checked, onClick: labelOnClick, user} = this.props
45+
const projectAdmin =
46+
user &&
47+
user.permissions &&
48+
user.permissions.isProjectAdmin(label.projectId)
3249

3350
return (
3451
<div
@@ -56,8 +73,8 @@ export default class FeedLabel extends React.Component {
5673
{label.adminOnly ? <Icon type='lock' /> : ''}
5774
<span>{label.name}</span>
5875
</div>
59-
{ small ? ''
60-
: <div className='actionButtons'>
76+
{ !small && projectAdmin && (
77+
<div className='actionButtons'>
6178
<ConfirmModal
6279
ref='deleteModal'
6380
title='Delete Label?'
@@ -69,7 +86,7 @@ export default class FeedLabel extends React.Component {
6986
<button onClick={() => this._onClickEdit()}><Icon type='pencil' /></button>
7087
<button onClick={() => this._onClickDelete()}><Icon type='trash' /></button>
7188
</div>
72-
}
89+
)}
7390
</div>
7491
)
7592
}

‎lib/common/containers/FeedLabel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import FeedLabel from '../components/FeedLabel'
77

88
const mapStateToProps = (state, ownProps) => {
99
return {
10+
user: state.user
1011
}
1112
}
1213

‎lib/manager/containers/__tests__/__snapshots__/FeedSourceTable.js.snap

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3662,6 +3662,78 @@ exports[`lib > manager > FeedSourceTable should render with a project with feeds
36623662
"user": null,
36633663
}
36643664
}
3665+
user={
3666+
Object {
3667+
"isCheckingLogin": false,
3668+
"permissions": UserPermissions {
3669+
"appPermissionLookup": Object {
3670+
"administer-application": Object {
3671+
"type": "administer-application",
3672+
},
3673+
},
3674+
"orgPermissionLookup": Object {},
3675+
"organizationLookup": Object {},
3676+
"projectLookup": Object {},
3677+
},
3678+
"profile": Object {
3679+
"app_metadata": Object {
3680+
"datatools": Array [
3681+
Object {
3682+
"client_id": "mock-client-id",
3683+
"organizations": Array [],
3684+
"permissions": Array [
3685+
Object {
3686+
"type": "administer-application",
3687+
},
3688+
],
3689+
"projects": Array [],
3690+
"subscriptions": Array [],
3691+
},
3692+
],
3693+
},
3694+
"clientID": "mock-client-id",
3695+
"created_at": "2016-03-04T18:59:22.569Z",
3696+
"email": "mock-user@conveyal.com",
3697+
"email_verified": true,
3698+
"identities": Array [
3699+
Object {
3700+
"connection": "Username-Password-Authentication",
3701+
"isSocial": false,
3702+
"provider": "auth0",
3703+
"user_id": "12345",
3704+
},
3705+
],
3706+
"jti": "gibberish",
3707+
"last_password_reset": "2017-07-13T13:58:01.021Z",
3708+
"name": "mock-user@conveyal.com",
3709+
"nickname": "mock-user",
3710+
"persistent": Object {},
3711+
"picture": "https://s.gravatar.com/avatar/f8660ca52d1229e3d55e88f2db4affda?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fmu.png",
3712+
"sub": "auth0|12345",
3713+
"updated_at": "2019-03-21T19:05:30.180Z",
3714+
"user_id": "auth0|12345",
3715+
"user_metadata": Object {
3716+
"datatools": Array [
3717+
Object {
3718+
"client_id": "mock-client-id",
3719+
"editor": Object {
3720+
"map_id": "mapbox.streets",
3721+
},
3722+
"hideTutorial": true,
3723+
"sidebarExpanded": false,
3724+
},
3725+
],
3726+
"lang": "en",
3727+
},
3728+
},
3729+
"recentActivity": null,
3730+
"redirectOnSuccess": null,
3731+
"subscriptions": UserSubscriptions {
3732+
"subscriptionLookup": Object {},
3733+
},
3734+
"token": "mock-token",
3735+
}
3736+
}
36653737
>
36663738
<div>
36673739
<h4>

0 commit comments

Comments
 (0)
Please sign in to comment.