/******************************************************************************** * Copyright (c) 2020 TypeFox and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import { FunctionComponent, useState, useContext, useEffect, useRef } from 'react'; import { Button, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions, Typography, Link } from '@mui/material'; import { createAbsoluteURL } from '../../utils'; import { ButtonWithProgress } from '../../components/button-with-progress'; import { PublisherInfo, isError } from '../../extension-registry-types'; import { MainContext } from '../../context'; import { UpdateContext } from './publisher-admin'; export const PublisherRevokeDialog: FunctionComponent = props => { const { user, service, handleError } = useContext(MainContext); const updateContext = useContext(UpdateContext); const [dialogOpen, setDialogOpen] = useState(false); const [working, setWorking] = useState(false); const abortController = useRef(new AbortController()); useEffect(() => { return () => { abortController.current.abort(); }; }, []); if (props.publisherInfo.user.publisherAgreement && !(user?.additionalLogins?.find(login => login.provider === 'eclipse'))) { // If a publisher agreement is required, the admin must be logged in with Eclipse to revoke it return ; } const doRevoke = async () => { try { setWorking(true); const user = props.publisherInfo.user; const result = await service.admin.revokePublisherContributions(abortController.current, user.provider as string, user.loginName); if (isError(result)) { throw result; } updateContext.handleUpdate(); setDialogOpen(false); } catch (err) { handleError(err); } finally { setWorking(false); } }; const tokenCount = props.publisherInfo.activeAccessTokenNum; const extensionCount = props.publisherInfo.extensions.filter(e => e.active).length; const hasAgreement = props.publisherInfo.user.publisherAgreement?.status !== 'none'; return <> setDialogOpen(false)}> Revoke Publisher Contributions { !tokenCount && !extensionCount && !hasAgreement ? <> Publisher {props.publisherInfo.user.loginName} currently has no contributions to revoke. Send the request anyway? : <> The following actions will be executed:
    { tokenCount > 0 ?
  • Deactivate {tokenCount} access token{tokenCount > 1 ? 's' : ''} of {props.publisherInfo.user.loginName}
  • : null } { extensionCount > 0 ?
  • Deactivate {extensionCount} published extension version{extensionCount > 1 ? 's' : ''}
  • : null } { hasAgreement ?
  • Revoke the Publisher Agreement of {props.publisherInfo.user.loginName}
  • : null }
}
Revoke Contributions
; }; export interface PublisherRevokeDialogProps { publisherInfo: PublisherInfo; }