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/collaborators/sandbox.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 { Alert, Checkbox, Popconfirm } from "antd";
7
import { Map } from "immutable";
8
import { join } from "path";
9
import { useState } from "react";
10
11
import { redux } from "@cocalc/frontend/app-framework";
12
import { CopyToClipBoard, Icon } from "@cocalc/frontend/components";
13
import { appBasePath } from "@cocalc/frontend/customize/app-base-path";
14
import { CancelText } from "@cocalc/frontend/i18n/components";
15
import { webapp_client } from "@cocalc/frontend/webapp-client";
16
17
interface Props {
18
project?: Map<string, any>;
19
}
20
21
export default function Sandbox({ project }: Props) {
22
const [expanded, setExpanded] = useState<boolean>(false);
23
24
if (!redux.getStore("customize")?.get("sandbox_projects_enabled")) {
25
return null;
26
}
27
28
if (
29
project == null ||
30
project.getIn(["users", webapp_client.account_id, "group"]) != "owner"
31
) {
32
// only owners can configure this settings.
33
// TODO: right now we are only enforcing this via the UI on the frontend.
34
// This isn't a huge issue, since a sandbox project is a free-for-all after all.
35
return null;
36
}
37
38
const heading = (
39
<div>
40
<a
41
onClick={() => {
42
setExpanded(!expanded);
43
}}
44
style={{ cursor: "pointer" }}
45
>
46
{" "}
47
<Icon
48
style={{ width: "20px" }}
49
name={expanded ? "caret-down" : "caret-right"}
50
/>{" "}
51
{project?.get("sandbox") ? (
52
<b>This is a Public Sandbox Project...</b>
53
) : (
54
"Make this a public sandbox project..."
55
)}
56
</a>
57
</div>
58
);
59
if (!expanded) {
60
return heading;
61
}
62
63
function render_link() {
64
if (!project?.get("sandbox")) {
65
return (
66
<div>
67
<p>
68
If you make this project a public sandbox project, then you can
69
share any URL in your project and when somebody visits that URL they
70
will automatically be added as a collaborator to your project. All
71
collaborators who are not the owner will be removed if they are not
72
active for about 10 minutes. Any trial, member hosting, and network
73
banners are also not visible.
74
</p>
75
<p>
76
Only do this if you have very minimal security requirements for the
77
content of this project, and have no concern about potential cross
78
site scripting attacks, e.g., you are running cocalc on a private
79
network, or only share this URL with trusted people.
80
</p>
81
</div>
82
);
83
}
84
return (
85
<div>
86
<p>Share this URL, or the URL of any file in your project:</p>
87
<CopyToClipBoard
88
value={`${document.location.origin}${join(
89
appBasePath,
90
"projects",
91
)}/${project?.get("project_id")}`}
92
style={{ width: "100%", marginBottom: "15px" }}
93
/>
94
<p>
95
When somebody with an account visits that URL, they will automatically
96
be added as a collaborator to this project.
97
</p>
98
</div>
99
);
100
}
101
102
return (
103
<div>
104
{heading}
105
<div
106
style={{
107
border: "1px solid #eee",
108
borderRadius: "5px",
109
padding: "15px",
110
marginTop: "5px",
111
}}
112
>
113
{project.get("sandbox") ? (
114
<Checkbox
115
checked
116
onChange={() => {
117
redux
118
.getActions("projects")
119
.set_project_sandbox(project.get("project_id"), false);
120
}}
121
>
122
Public Sandbox Project
123
</Checkbox>
124
) : (
125
<Popconfirm
126
title={
127
<div style={{ maxWidth: "450px" }}>
128
Are you absolutely sure?
129
<Alert
130
style={{ margin: "15px" }}
131
showIcon
132
type="warning"
133
message="SECURITY WARNING"
134
description="Only do this if you have very minimal
135
security requirements for the content of this project, and have
136
no concern about potential cross site scripting attacks, e.g.,
137
you are running cocalc on a private network, or only share this
138
URL with trusted people."
139
/>
140
NOTE: You can always disable sandbox mode later, remove any
141
collaborators that were added, and collaborators can't delete
142
backups or TimeTravel history.
143
</div>
144
}
145
onConfirm={() => {
146
redux
147
.getActions("projects")
148
.set_project_sandbox(project.get("project_id"), true);
149
}}
150
okText={"Yes, make this a public sandbox project!"}
151
cancelText={<CancelText />}
152
>
153
<Checkbox checked={false}>Public Sandbox Project</Checkbox>
154
</Popconfirm>
155
)}
156
<br />
157
<br />
158
{render_link()}
159
</div>
160
</div>
161
);
162
}
163
164