web UI: allow a privileged user to dequeue a change
Add a togglable "Actions" kebab menu on the right of a change, if the currently logged in user is an admin on the tenant. Show available actions (currently "dequeue" only) when toggled. Clicking the "Dequeue" item opens a modal, so that the user can confirm her decision. Change-Id: I7c97509d62ef167ee5904a816998049d88c6b3cb
This commit is contained in:
parent
560fa563db
commit
3152171aa5
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
Allow an authorized user to dequeue changes from the Web UI's status page.
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2020 Red Hat, Inc
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
// not use this file except in compliance with the License. You may obtain
|
||||
// a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
export const ADMIN_DEQUEUE_FAIL = 'ADMIN_DEQUEUE_FAIL'
|
||||
|
||||
|
||||
export const addDequeueError = error => ({
|
||||
type: ADMIN_DEQUEUE_FAIL,
|
||||
error: error
|
||||
})
|
|
@ -181,6 +181,35 @@ function fetchUserAuthorizations(apiPrefix, token) {
|
|||
return res
|
||||
}
|
||||
|
||||
function dequeue (apiPrefix, projectName, pipeline, change, token) {
|
||||
const instance = Axios.create({
|
||||
baseURL: apiUrl
|
||||
})
|
||||
instance.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
||||
let res = instance.post(
|
||||
apiPrefix + 'project/' + projectName + '/dequeue',
|
||||
{
|
||||
pipeline: pipeline,
|
||||
change: change,
|
||||
}
|
||||
)
|
||||
return res
|
||||
}
|
||||
function dequeue_ref (apiPrefix, projectName, pipeline, ref, token) {
|
||||
const instance = Axios.create({
|
||||
baseURL: apiUrl
|
||||
})
|
||||
instance.defaults.headers.common['Authorization'] = 'Bearer ' + token
|
||||
let res = instance.post(
|
||||
apiPrefix + 'project/' + projectName + '/dequeue',
|
||||
{
|
||||
pipeline: pipeline,
|
||||
ref: ref,
|
||||
}
|
||||
)
|
||||
return res
|
||||
}
|
||||
|
||||
export {
|
||||
apiUrl,
|
||||
getHomepageUrl,
|
||||
|
@ -204,4 +233,6 @@ export {
|
|||
fetchComponents,
|
||||
fetchTenantInfo,
|
||||
fetchUserAuthorizations,
|
||||
dequeue,
|
||||
dequeue_ref,
|
||||
}
|
||||
|
|
|
@ -17,6 +17,22 @@ import PropTypes from 'prop-types'
|
|||
import { connect } from 'react-redux'
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
import {
|
||||
Button,
|
||||
Dropdown,
|
||||
DropdownItem,
|
||||
KebabToggle,
|
||||
Modal,
|
||||
ModalVariant
|
||||
} from '@patternfly/react-core'
|
||||
import {
|
||||
BanIcon,
|
||||
} from '@patternfly/react-icons'
|
||||
import { dequeue, dequeue_ref } from '../../api'
|
||||
import { addDequeueError } from '../../actions/adminActions'
|
||||
|
||||
import { addError } from '../../actions/errors'
|
||||
|
||||
import LineAngleImage from '../../images/line-angle.png'
|
||||
import LineTImage from '../../images/line-t.png'
|
||||
import ChangePanel from './ChangePanel'
|
||||
|
@ -27,10 +43,112 @@ class Change extends React.Component {
|
|||
change: PropTypes.object.isRequired,
|
||||
queue: PropTypes.object.isRequired,
|
||||
expanded: PropTypes.bool.isRequired,
|
||||
tenant: PropTypes.object
|
||||
pipeline: PropTypes.string,
|
||||
tenant: PropTypes.object,
|
||||
user: PropTypes.object,
|
||||
dispatch: PropTypes.func
|
||||
}
|
||||
|
||||
renderStatusIcon (change) {
|
||||
state = {
|
||||
showDequeueModal: false,
|
||||
showAdminActions: false,
|
||||
}
|
||||
|
||||
dequeueConfirm = () => {
|
||||
const { tenant, user, change, pipeline } = this.props
|
||||
let projectName = change.project
|
||||
let changeId = change.id || 'N/A'
|
||||
let changeRef = change.ref
|
||||
this.setState(() => ({ showDequeueModal: false }))
|
||||
// post-merge
|
||||
if (/^[0-9a-f]{40}$/.test(changeId)) {
|
||||
dequeue_ref(tenant.apiPrefix, projectName, pipeline.name, changeRef, user.token)
|
||||
.catch(error => {
|
||||
this.props.dispatch(addDequeueError(error))
|
||||
})
|
||||
// pre-merge, ie we have a change id
|
||||
} else if (changeId !== 'N/A') {
|
||||
dequeue(tenant.apiPrefix, projectName, pipeline.name, changeId, user.token)
|
||||
.catch(error => {
|
||||
this.props.dispatch(addDequeueError(error))
|
||||
})
|
||||
} else {
|
||||
this.props.dispatch(addError({
|
||||
url: null,
|
||||
status: 'Invalid change ' + changeRef + ' on project ' + projectName,
|
||||
text: ''
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
dequeueCancel = () => {
|
||||
this.setState(() => ({ showDequeueModal: false }))
|
||||
}
|
||||
|
||||
renderDequeueModal() {
|
||||
const { showDequeueModal } = this.state
|
||||
const { change } = this.props
|
||||
let projectName = change.project
|
||||
let changeId = change.id || change.ref
|
||||
const title = 'You are about to dequeue a change'
|
||||
return (
|
||||
<Modal
|
||||
variant={ModalVariant.small}
|
||||
// titleIconVariant={BullhornIcon}
|
||||
isOpen={showDequeueModal}
|
||||
title={title}
|
||||
onClose={this.dequeueCancel}
|
||||
actions={[
|
||||
<Button key="deq_confirm" variant="primary" onClick={this.dequeueConfirm}>Confirm</Button>,
|
||||
<Button key="deq_cancel" variant="link" onClick={this.dequeueCancel}>Cancel</Button>,
|
||||
]}>
|
||||
<p>Please confirm that you want to cancel <strong>all ongoing builds</strong> on change <strong>{changeId}</strong> for project <strong>{projectName}</strong>.</p>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
renderAdminCommands(idx) {
|
||||
const { showAdminActions } = this.state
|
||||
const { queue } = this.props
|
||||
const dropdownCommands = [
|
||||
<DropdownItem
|
||||
key="dequeue"
|
||||
|
||||
icon={<BanIcon style={{
|
||||
color: 'var(--pf-global--danger-color--100)',
|
||||
}} />}
|
||||
description="Stop all jobs for this change"
|
||||
onClick={(event) => {
|
||||
event.preventDefault()
|
||||
this.setState(() => ({ showDequeueModal: true }))
|
||||
}}
|
||||
>Dequeue</DropdownItem>,
|
||||
]
|
||||
return (
|
||||
<Dropdown
|
||||
title='Actions'
|
||||
isOpen={showAdminActions}
|
||||
onSelect={() => {
|
||||
this.setState({ showAdminActions: !showAdminActions })
|
||||
const element = document.getElementById('toggle-id-' + idx + '-' + queue.uuid)
|
||||
element.focus()
|
||||
}}
|
||||
dropdownItems={dropdownCommands}
|
||||
isPlain
|
||||
toggle={
|
||||
<KebabToggle
|
||||
onToggle={(showAdminActions) => {
|
||||
this.setState({ showAdminActions })
|
||||
}}
|
||||
id={'toggle-id-' + idx + '-' + queue.uuid} />
|
||||
}
|
||||
/>
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
renderStatusIcon(change) {
|
||||
let iconGlyph = 'pficon pficon-ok'
|
||||
let iconTitle = 'Succeeding'
|
||||
if (change.active !== true) {
|
||||
|
@ -66,18 +184,19 @@ class Change extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
renderLineImg (change, i) {
|
||||
renderLineImg(change, i) {
|
||||
let image = LineTImage
|
||||
if (change._tree_branches.indexOf(i) === change._tree_branches.length - 1) {
|
||||
// Angle line
|
||||
image = LineAngleImage
|
||||
}
|
||||
return <img alt="Line" src={image} style={{verticalAlign: 'baseline'}} />
|
||||
return <img alt="Line" src={image} style={{ verticalAlign: 'baseline' }} />
|
||||
}
|
||||
|
||||
render () {
|
||||
const { change, queue, expanded } = this.props
|
||||
render() {
|
||||
const { change, queue, expanded, pipeline, user, tenant } = this.props
|
||||
let row = []
|
||||
let adminMenuWidth = 15
|
||||
let i
|
||||
for (i = 0; i < queue._tree_columns; i++) {
|
||||
let className = ''
|
||||
|
@ -91,22 +210,39 @@ class Change extends React.Component {
|
|||
this.renderLineImg(change, i)) : ''}
|
||||
</td>)
|
||||
}
|
||||
let changeWidth = 360 - 16 * queue._tree_columns
|
||||
let changeWidth = (user.isAdmin && user.scope.indexOf(tenant.name) !== -1)
|
||||
? 360 - adminMenuWidth - 16 * queue._tree_columns
|
||||
: 360 - 16 * queue._tree_columns
|
||||
row.push(
|
||||
<td key={i + 1}
|
||||
className="zuul-change-cell"
|
||||
style={{width: changeWidth + 'px'}}>
|
||||
<ChangePanel change={change} globalExpanded={expanded} />
|
||||
style={{ width: changeWidth + 'px' }}>
|
||||
<ChangePanel change={change} globalExpanded={expanded} pipeline={pipeline} />
|
||||
</td>
|
||||
)
|
||||
if (user.isAdmin && user.scope.indexOf(tenant.name) !== -1) {
|
||||
row.push(
|
||||
<td key={i + 2}
|
||||
style={{ verticalAlign: 'top', width: adminMenuWidth + 'px' }}>
|
||||
{this.renderAdminCommands(i + 2)}
|
||||
</td>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<table className="zuul-change-box" style={{boxSizing: 'content-box'}}>
|
||||
<>
|
||||
<table className="zuul-change-box" style={{ boxSizing: 'content-box' }}>
|
||||
<tbody>
|
||||
<tr>{row}</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{this.renderDequeueModal()}
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(state => ({tenant: state.tenant}))(Change)
|
||||
export default connect(state => ({
|
||||
tenant: state.tenant,
|
||||
user: state.user,
|
||||
}))(Change)
|
||||
|
|
|
@ -43,6 +43,7 @@ class ChangeQueue extends React.Component {
|
|||
change={change}
|
||||
queue={queue}
|
||||
expanded={expanded}
|
||||
pipeline={pipeline}
|
||||
key={changeIdx.toString() + idx}
|
||||
/>)
|
||||
})
|
||||
|
|
|
@ -69,6 +69,12 @@ span.zuul-job-result.label {
|
|||
vertical-align: top;
|
||||
}
|
||||
|
||||
/* Restore the menuitem styling */
|
||||
.zuul-status-content .pf-c-content ul[role="menu"] {
|
||||
padding-left: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
/* Avoid duplicated lines/borders for the job items on the status page */
|
||||
.zuul-status-content li+li {
|
||||
margin-top: 0;
|
||||
|
|
|
@ -25,6 +25,10 @@ export default (state = [], action) => {
|
|||
if (action.error && action.type.match(/.*_FETCH_FAIL$/)) {
|
||||
action = addApiError(action.error)
|
||||
}
|
||||
// Intercept Admin API failures
|
||||
if (action.error && action.type.match(/ADMIN_.*_FAIL$/)) {
|
||||
action = addApiError(action.error)
|
||||
}
|
||||
switch (action.type) {
|
||||
case ADD_ERROR:
|
||||
if (state.filter(error => (
|
||||
|
|
Loading…
Reference in New Issue