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/collaborators/sandbox.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Alert, Checkbox, Popconfirm } from "antd";6import { Map } from "immutable";7import { join } from "path";8import { useState } from "react";910import { redux } from "@cocalc/frontend/app-framework";11import { CopyToClipBoard, Icon } from "@cocalc/frontend/components";12import { appBasePath } from "@cocalc/frontend/customize/app-base-path";13import { CancelText } from "@cocalc/frontend/i18n/components";14import { webapp_client } from "@cocalc/frontend/webapp-client";1516interface Props {17project?: Map<string, any>;18}1920export default function Sandbox({ project }: Props) {21const [expanded, setExpanded] = useState<boolean>(false);2223if (!redux.getStore("customize")?.get("sandbox_projects_enabled")) {24return null;25}2627if (28project == null ||29project.getIn(["users", webapp_client.account_id, "group"]) != "owner"30) {31// only owners can configure this settings.32// TODO: right now we are only enforcing this via the UI on the frontend.33// This isn't a huge issue, since a sandbox project is a free-for-all after all.34return null;35}3637const heading = (38<div>39<a40onClick={() => {41setExpanded(!expanded);42}}43style={{ cursor: "pointer" }}44>45{" "}46<Icon47style={{ width: "20px" }}48name={expanded ? "caret-down" : "caret-right"}49/>{" "}50{project?.get("sandbox") ? (51<b>This is a Public Sandbox Project...</b>52) : (53"Make this a public sandbox project..."54)}55</a>56</div>57);58if (!expanded) {59return heading;60}6162function render_link() {63if (!project?.get("sandbox")) {64return (65<div>66<p>67If you make this project a public sandbox project, then you can68share any URL in your project and when somebody visits that URL they69will automatically be added as a collaborator to your project. All70collaborators who are not the owner will be removed if they are not71active for about 10 minutes. Any trial, member hosting, and network72banners are also not visible.73</p>74<p>75Only do this if you have very minimal security requirements for the76content of this project, and have no concern about potential cross77site scripting attacks, e.g., you are running cocalc on a private78network, or only share this URL with trusted people.79</p>80</div>81);82}83return (84<div>85<p>Share this URL, or the URL of any file in your project:</p>86<CopyToClipBoard87value={`${document.location.origin}${join(88appBasePath,89"projects",90)}/${project?.get("project_id")}`}91style={{ width: "100%", marginBottom: "15px" }}92/>93<p>94When somebody with an account visits that URL, they will automatically95be added as a collaborator to this project.96</p>97</div>98);99}100101return (102<div>103{heading}104<div105style={{106border: "1px solid #eee",107borderRadius: "5px",108padding: "15px",109marginTop: "5px",110}}111>112{project.get("sandbox") ? (113<Checkbox114checked115onChange={() => {116redux117.getActions("projects")118.set_project_sandbox(project.get("project_id"), false);119}}120>121Public Sandbox Project122</Checkbox>123) : (124<Popconfirm125title={126<div style={{ maxWidth: "450px" }}>127Are you absolutely sure?128<Alert129style={{ margin: "15px" }}130showIcon131type="warning"132message="SECURITY WARNING"133description="Only do this if you have very minimal134security requirements for the content of this project, and have135no concern about potential cross site scripting attacks, e.g.,136you are running cocalc on a private network, or only share this137URL with trusted people."138/>139NOTE: You can always disable sandbox mode later, remove any140collaborators that were added, and collaborators can't delete141backups or TimeTravel history.142</div>143}144onConfirm={() => {145redux146.getActions("projects")147.set_project_sandbox(project.get("project_id"), true);148}}149okText={"Yes, make this a public sandbox project!"}150cancelText={<CancelText />}151>152<Checkbox checked={false}>Public Sandbox Project</Checkbox>153</Popconfirm>154)}155<br />156<br />157{render_link()}158</div>159</div>160);161}162163164