Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/admin/users/ban.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Component, Rendered } from "@cocalc/frontend/app-framework";6import { Button, Popconfirm } from "antd";7import { Icon, ErrorDisplay } from "@cocalc/frontend/components";8import { webapp_client } from "../../webapp-client";910interface Props {11account_id: string;12banned?: boolean;13name?: string;14}1516interface State {17error?: string;18running: boolean;19link?: string;20banned: boolean;21}2223export class Ban extends Component<Props, State> {24mounted: boolean = true;2526constructor(props: any) {27super(props);28this.state = { running: false, banned: !!props.banned };29}3031componentWillUnmount(): void {32this.mounted = false;33}3435async do_request(): Promise<void> {36this.setState({ running: true });37try {38await webapp_client.admin_client.admin_ban_user(39this.props.account_id,40!this.state.banned,41);42this.setState({ running: false, banned: !this.state.banned });43} catch (err) {44if (!this.mounted) return;45this.setState({ error: `${err}`, running: false });46}47}4849render_ban_button(): Rendered {50if (this.state.banned) {51return (52<Button53onClick={() => {54this.do_request();55}}56disabled={this.state.running}57>58<Icon59name={this.state.running ? "sync" : "lock-open"}60spin={this.state.running}61/>{" "}62Remove Ban on User63</Button>64);65}66return (67<Popconfirm68title={<>Ban "{this.props.name}"?</>}69description={70<div style={{ width: "400px" }}>71{this.props.name} won't be able to login, all API access is revoked,72auth_tokens are deleted, can't connect to projects, and all ability73to spend money is immeediately halted. This means{" "}74<b>75any compute servers they are running will be completely deleted.76</b>{" "}77Use this on spammers and credit card fraudsters. Before they refresh78their browser, they will just feel likely CoCalc is slow/broken, but79they won't know why.80</div>81}82okText="Yes, BAN THEM"83cancelText="No"84onConfirm={() => {85this.do_request();86}}87>88<Button disabled={this.state.running}>89<Icon90name={this.state.running ? "sync" : "lock-open"}91spin={this.state.running}92/>{" "}93Ban User...94</Button>95</Popconfirm>96);97}9899render_error(): Rendered {100if (!this.state.error) {101return;102}103return (104<ErrorDisplay105error={this.state.error}106onClose={() => {107this.setState({ error: undefined });108}}109/>110);111}112113render(): Rendered {114return (115<div>116<b>117User is currently{" "}118{this.state.banned119? "banned!"120: "NOT banned: If you ban them, they lose access to their account. You can easily remove the ban, but any pay as you go purchases are halted, so compute servers they own will be immediately deleted!"}121</b>122<br />123<br />124{this.render_error()}125{this.render_ban_button()}126<br />127<br />128</div>129);130}131}132133134