Skip to content

Commit

Permalink
User is granted API access on approval (#1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkonecn authored Oct 7, 2024
1 parent 7867383 commit 99e6883
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/main/webapp/app/pages/userManagement/UserDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class UserDetailsPage extends React.Component<{
}

@action
updateActiveStatus(sendEmail = true) {
updateActiveStatus(sendEmail: boolean, authorities: string[]) {
this.showUpdateStatusModal = false;
if (this.currentSelected.user === undefined) {
notifyError(new Error('No user specified'));
Expand All @@ -122,6 +122,7 @@ export default class UserDetailsPage extends React.Component<{
const userToUpdate: UserDTO = {
...this.currentSelected.user,
activated: !this.currentSelected.user.activated,
authorities,
};
this.updateUser(userToUpdate, sendEmail);
}
Expand Down Expand Up @@ -399,7 +400,7 @@ export default class UserDetailsPage extends React.Component<{
show={this.showUpdateStatusModal}
user={this.currentSelected.user}
onCancel={() => this.cancelUpdateActiveStatus()}
onConfirm={(sendEmail: boolean) => this.updateActiveStatus(sendEmail)}
onConfirm={this.updateActiveStatus.bind(this)}
/>
</>
);
Expand Down
35 changes: 31 additions & 4 deletions src/main/webapp/app/shared/modal/UserStatusModal.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,58 @@
import { DefaultTooltip } from 'cbioportal-frontend-commons';
import React from 'react';
import { Button, Modal } from 'react-bootstrap';
import { Button, Modal, Alert } from 'react-bootstrap';
import { UserDTO } from '../api/generated/API';
import { AUTHORITIES } from 'app/config/constants';

type UserStatusModalProps = {
user: UserDTO | undefined;
show: boolean;
onCancel: () => void;
onConfirm: (sendEmail: boolean) => void;
onConfirm: (sendEmail: boolean, authorities: string[]) => void;
};

export class UserStatusModal extends React.Component<UserStatusModalProps> {
render() {
const isRequestingApiAccess =
!this.props.user?.activated &&
this.props.user?.additionalInfo?.apiAccessRequest?.requested;
const authorities = [...(this.props.user?.authorities ?? [])];
if (isRequestingApiAccess && !authorities.includes(AUTHORITIES.API)) {
authorities.push(AUTHORITIES.API);
}
return (
<Modal show={this.props.show} onHide={this.props.onCancel}>
<Modal.Header closeButton>
<Modal.Title>Update User Status</Modal.Title>
</Modal.Header>
<Modal.Body>
{isRequestingApiAccess && (
<Alert variant="warning">
<p>
This user is requesting API access with the following
justification:
</p>
<p>
"
{
this.props.user?.additionalInfo?.apiAccessRequest
?.justification
}
"
</p>
</Alert>
)}
Are you sure to{' '}
{this.props.user?.activated ? 'deactivate' : 'activate'} the user?
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={this.props.onCancel}>
Close
</Button>
<Button variant="primary" onClick={() => this.props.onConfirm(true)}>
<Button
variant="primary"
onClick={() => this.props.onConfirm(true, authorities)}
>
Update
</Button>
{!this.props.user?.activated ? (
Expand All @@ -37,7 +64,7 @@ export class UserStatusModal extends React.Component<UserStatusModalProps> {
>
<Button
variant="primary"
onClick={() => this.props.onConfirm(false)}
onClick={() => this.props.onConfirm(false, authorities)}
>
Silent Update
</Button>
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/app/shared/table/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class UserTable extends React.Component<IUserTableProps> {
}

@action
updateActiveStatus(sendEmail = true) {
updateActiveStatus(sendEmail: boolean) {
if (this.currentSelectedUser) {
const userToUpdate: UserDTO = {
...this.currentSelectedUser,
Expand Down Expand Up @@ -314,7 +314,7 @@ export class UserTable extends React.Component<IUserTableProps> {
show={this.showUserStatusModal}
user={this.currentSelectedUser}
onCancel={this.cancelUpdateActiveStatus}
onConfirm={(sendEmail: boolean) => this.updateActiveStatus(sendEmail)}
onConfirm={this.updateActiveStatus.bind(this)}
/>
</>
);
Expand Down

0 comments on commit 99e6883

Please sign in to comment.