Skip to content

Commit

Permalink
fix(FeedLabel): further permission checks
Browse files Browse the repository at this point in the history
  • Loading branch information
miles-grant-ibigroup committed Jul 22, 2021
1 parent 9fca12b commit 330a9d1
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/common/components/FeedLabel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// @flow
import React from 'react'
import tinycolor from 'tinycolor2'
import Icon from '@conveyal/woonerf/components/icon'

import type { Label } from '../../types'
import type {ManagerUserState} from '../../types/reducers'
import ConfirmModal from '../../common/components/ConfirmModal'
import LabelEditorModal from '../../manager/components/LabelEditorModal'

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

export default class FeedLabel extends React.Component {
export type Props = {
checked?: boolean,
deleteLabel?: Function,
label: Label,
onClick?: Function,
small: boolean,
user?: ManagerUserState
}
export type State = {}

export default class FeedLabel extends React.Component<Props, State> {
_onConfirmDelete = () => {
this.props.deleteLabel(this.props.label)
this.props.deleteLabel && this.props.deleteLabel(this.props.label)
}

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

render () {
const {small, label, checked, onClick: labelOnClick} = this.props
const {small, label, checked, onClick: labelOnClick, user} = this.props
const projectAdmin =
user &&
user.permissions &&
user.permissions.isProjectAdmin(label.projectId)

return (
<div
Expand Down Expand Up @@ -56,8 +73,8 @@ export default class FeedLabel extends React.Component {
{label.adminOnly ? <Icon type='lock' /> : ''}
<span>{label.name}</span>
</div>
{ small ? ''
: <div className='actionButtons'>
{ !small && projectAdmin && (
<div className='actionButtons'>
<ConfirmModal
ref='deleteModal'
title='Delete Label?'
Expand All @@ -69,7 +86,7 @@ export default class FeedLabel extends React.Component {
<button onClick={() => this._onClickEdit()}><Icon type='pencil' /></button>
<button onClick={() => this._onClickDelete()}><Icon type='trash' /></button>
</div>
}
)}
</div>
)
}
Expand Down
1 change: 1 addition & 0 deletions lib/common/containers/FeedLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import FeedLabel from '../components/FeedLabel'

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3662,6 +3662,78 @@ exports[`lib > manager > FeedSourceTable should render with a project with feeds
"user": null,
}
}
user={
Object {
"isCheckingLogin": false,
"permissions": UserPermissions {
"appPermissionLookup": Object {
"administer-application": Object {
"type": "administer-application",
},
},
"orgPermissionLookup": Object {},
"organizationLookup": Object {},
"projectLookup": Object {},
},
"profile": Object {
"app_metadata": Object {
"datatools": Array [
Object {
"client_id": "mock-client-id",
"organizations": Array [],
"permissions": Array [
Object {
"type": "administer-application",
},
],
"projects": Array [],
"subscriptions": Array [],
},
],
},
"clientID": "mock-client-id",
"created_at": "2016-03-04T18:59:22.569Z",
"email": "mock-user@conveyal.com",
"email_verified": true,
"identities": Array [
Object {
"connection": "Username-Password-Authentication",
"isSocial": false,
"provider": "auth0",
"user_id": "12345",
},
],
"jti": "gibberish",
"last_password_reset": "2017-07-13T13:58:01.021Z",
"name": "mock-user@conveyal.com",
"nickname": "mock-user",
"persistent": Object {},
"picture": "https://s.gravatar.com/avatar/f8660ca52d1229e3d55e88f2db4affda?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fmu.png",
"sub": "auth0|12345",
"updated_at": "2019-03-21T19:05:30.180Z",
"user_id": "auth0|12345",
"user_metadata": Object {
"datatools": Array [
Object {
"client_id": "mock-client-id",
"editor": Object {
"map_id": "mapbox.streets",
},
"hideTutorial": true,
"sidebarExpanded": false,
},
],
"lang": "en",
},
},
"recentActivity": null,
"redirectOnSuccess": null,
"subscriptions": UserSubscriptions {
"subscriptionLookup": Object {},
},
"token": "mock-token",
}
}
>
<div>
<h4>
Expand Down

0 comments on commit 330a9d1

Please sign in to comment.