Skip to content

Commit

Permalink
feat(auth-ui): toggle node browser delete button per authz
Browse files Browse the repository at this point in the history
  • Loading branch information
vpsx committed Oct 10, 2019
1 parent e5ca2ef commit 513210f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
49 changes: 37 additions & 12 deletions src/QueryNode/QueryNode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { jsonToString, getSubmitPath } from '../utils';
import Popup from '../components/Popup';
import QueryForm from './QueryForm';
import './QueryNode.less';
import { useArboristUI } from '../configs';

const Entity = ({ value, project, onUpdatePopup, onStoreNodeInfo, tabindexStart }) => {
const Entity = ({ value, project, onUpdatePopup, onStoreNodeInfo, tabindexStart, showDelete }) => {
const onDelete = () => {
onStoreNodeInfo({ project, id: value.id }).then(
() => onUpdatePopup({ nodedelete_popup: true }),
Expand All @@ -20,7 +21,9 @@ const Entity = ({ value, project, onUpdatePopup, onStoreNodeInfo, tabindexStart
<span>{value.submitter_id}</span>
<a role='button' tabIndex={tabindexStart} className='query-node__button query-node__button--download' href={`${getSubmitPath(project)}/export?format=json&ids=${value.id}`}>Download</a>
<a role='button' tabIndex={tabindexStart + 1} className='query-node__button query-node__button--view' onClick={onView}>View</a>
<a role='button' tabIndex={tabindexStart + 2} className='query-node__button query-node__button--delete' onClick={onDelete}>Delete</a>
{
showDelete ? <a role='button' tabIndex={tabindexStart + 2} className='query-node__button query-node__button--delete' onClick={onDelete}>Delete</a> : null
}
</li>
);
};
Expand All @@ -31,6 +34,7 @@ Entity.propTypes = {
tabindexStart: PropTypes.number.isRequired,
onUpdatePopup: PropTypes.func,
onStoreNodeInfo: PropTypes.func,
showDelete: PropTypes.bool.isRequired,
};

Entity.defaultProps = {
Expand All @@ -40,7 +44,7 @@ Entity.defaultProps = {
onSearchFormSubmit: null,
};

const Entities = ({ value, project, onUpdatePopup, onStoreNodeInfo }) => (
const Entities = ({ value, project, onUpdatePopup, onStoreNodeInfo, showDelete }) => (
<ul>
{
value.map(
Expand All @@ -51,6 +55,7 @@ const Entities = ({ value, project, onUpdatePopup, onStoreNodeInfo }) => (
key={v.submitter_id}
value={v}
tabindexStart={i * 3}
showDelete={showDelete}
/>),
)
}
Expand All @@ -62,6 +67,7 @@ Entities.propTypes = {
project: PropTypes.string.isRequired,
onUpdatePopup: PropTypes.func,
onStoreNodeInfo: PropTypes.func,
showDelete: PropTypes.bool.isRequired,
};

Entities.defaultProps = {
Expand Down Expand Up @@ -188,6 +194,16 @@ class QueryNode extends React.Component {
return popup;
}

userHasDeleteOnProject = () => {
var split = this.props.params.project.split('-');
var program = split[0]
var project = split.slice(1).join('-')
var resourcePath = ["/programs", program, "projects", project].join('/')
var actions = this.props.userAuthMapping[resourcePath]

return actions !== undefined && actions.some(x => x["method"] === "delete")
}

render() {
const queryNodesList = this.props.queryNodes.search_status === 'succeed: 200' ?
Object.entries(this.props.queryNodes.search_result.data)
Expand Down Expand Up @@ -226,15 +242,23 @@ class QueryNode extends React.Component {
/>
<h4>most recent 20:</h4>
{ queryNodesList.map(
value => (<Entities
project={project}
onStoreNodeInfo={this.props.onStoreNodeInfo}
onUpdatePopup={this.props.onUpdatePopup}
node_type={value[0]}
key={value[0]}
value={value[1]}
/>
),
value => {
var showDelete = true
if (useArboristUI) {
showDelete = this.userHasDeleteOnProject()
}
return (
<Entities
project={project}
onStoreNodeInfo={this.props.onStoreNodeInfo}
onUpdatePopup={this.props.onUpdatePopup}
node_type={value[0]}
key={value[0]}
value={value[1]}
showDelete={showDelete}
/>
)
}
)
}
</div>
Expand All @@ -253,6 +277,7 @@ QueryNode.propTypes = {
onClearDeleteSession: PropTypes.func.isRequired,
onDeleteNode: PropTypes.func.isRequired,
onStoreNodeInfo: PropTypes.func.isRequired,
userAuthMapping: PropTypes.object.isRequired,
};

QueryNode.defaultProps = {
Expand Down
1 change: 1 addition & 0 deletions src/QueryNode/ReduxQueryNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const mapStateToProps = (state, ownProps) => {
ownProps,
queryNodes: state.queryNodes,
popups: Object.assign({}, state.popups),
userAuthMapping: state.userAuthMapping,
};
return result;
};
Expand Down

0 comments on commit 513210f

Please sign in to comment.