CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/admin/users/ban.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Component, Rendered } from "@cocalc/frontend/app-framework";
7
import { Button, Popconfirm } from "antd";
8
import { Icon, ErrorDisplay } from "@cocalc/frontend/components";
9
import { webapp_client } from "../../webapp-client";
10
11
interface Props {
12
account_id: string;
13
banned?: boolean;
14
name?: string;
15
}
16
17
interface State {
18
error?: string;
19
running: boolean;
20
link?: string;
21
banned: boolean;
22
}
23
24
export class Ban extends Component<Props, State> {
25
mounted: boolean = true;
26
27
constructor(props: any) {
28
super(props);
29
this.state = { running: false, banned: !!props.banned };
30
}
31
32
componentWillUnmount(): void {
33
this.mounted = false;
34
}
35
36
async do_request(): Promise<void> {
37
this.setState({ running: true });
38
try {
39
await webapp_client.admin_client.admin_ban_user(
40
this.props.account_id,
41
!this.state.banned,
42
);
43
this.setState({ running: false, banned: !this.state.banned });
44
} catch (err) {
45
if (!this.mounted) return;
46
this.setState({ error: `${err}`, running: false });
47
}
48
}
49
50
render_ban_button(): Rendered {
51
if (this.state.banned) {
52
return (
53
<Button
54
onClick={() => {
55
this.do_request();
56
}}
57
disabled={this.state.running}
58
>
59
<Icon
60
name={this.state.running ? "sync" : "lock-open"}
61
spin={this.state.running}
62
/>{" "}
63
Remove Ban on User
64
</Button>
65
);
66
}
67
return (
68
<Popconfirm
69
title={<>Ban "{this.props.name}"?</>}
70
description={
71
<div style={{ width: "400px" }}>
72
{this.props.name} won't be able to login, all API access is revoked,
73
auth_tokens are deleted, can't connect to projects, and all ability
74
to spend money is immeediately halted. This means{" "}
75
<b>
76
any compute servers they are running will be completely deleted.
77
</b>{" "}
78
Use this on spammers and credit card fraudsters. Before they refresh
79
their browser, they will just feel likely CoCalc is slow/broken, but
80
they won't know why.
81
</div>
82
}
83
okText="Yes, BAN THEM"
84
cancelText="No"
85
onConfirm={() => {
86
this.do_request();
87
}}
88
>
89
<Button disabled={this.state.running}>
90
<Icon
91
name={this.state.running ? "sync" : "lock-open"}
92
spin={this.state.running}
93
/>{" "}
94
Ban User...
95
</Button>
96
</Popconfirm>
97
);
98
}
99
100
render_error(): Rendered {
101
if (!this.state.error) {
102
return;
103
}
104
return (
105
<ErrorDisplay
106
error={this.state.error}
107
onClose={() => {
108
this.setState({ error: undefined });
109
}}
110
/>
111
);
112
}
113
114
render(): Rendered {
115
return (
116
<div>
117
<b>
118
User is currently{" "}
119
{this.state.banned
120
? "banned!"
121
: "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!"}
122
</b>
123
<br />
124
<br />
125
{this.render_error()}
126
{this.render_ban_button()}
127
<br />
128
<br />
129
</div>
130
);
131
}
132
}
133
134