forked from bigbluebutton/greenlight
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
2,853 additions
and
2,089 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
web: bin/rails server -p $PORT | ||
web: ruby bin/rails server -p $PORT | ||
js: yarn build:development | ||
css: yarn build:development:css --watch | ||
css: yarn build:development:css --watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/javascript/components/admin/manage_users/forms/CsvSignUpForm.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. | ||
// | ||
// Copyright (c) 2022 BigBlueButton Inc. and by respective authors (see below). | ||
// | ||
// This program is free software; you can redistribute it and/or modify it under the | ||
// terms of the GNU Lesser General Public License as published by the Free Software | ||
// Foundation; either version 3.0 of the License, or (at your option) any later | ||
// version. | ||
// | ||
// Greenlight is distributed in the hope that it will be useful, but WITHOUT ANY | ||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License along | ||
// with Greenlight; if not, see <http://www.gnu.org/licenses/>. | ||
|
||
import React from "react"; | ||
import { Button, Stack } from "react-bootstrap"; | ||
import PropTypes from "prop-types"; | ||
import { useTranslation } from "react-i18next"; | ||
import Spinner from "../../../shared_components/utilities/Spinner"; | ||
import useAdminCreateUser from "../../../../hooks/mutations/admin/manage_users/useAdminCreateUser"; | ||
|
||
export default function UserSignupForm({ handleClose, users, handleStatus }) { | ||
const { t } = useTranslation(); | ||
const createUserAPI = useAdminCreateUser({ onSettled: () => { } }); | ||
|
||
async function handleSubmit() { | ||
let index = 0; | ||
for (const user of users) { | ||
try { | ||
await createUserAPI.mutateAsync(user); | ||
handleStatus(index, t("toast.success.user.user_created")); | ||
} catch (error) { | ||
if (error.response.data.errors === "EmailAlreadyExists") { | ||
handleStatus(index, t("toast.error.users.email_exists")); | ||
} else { | ||
handleStatus(index, t("toast.error.problem_completing_action")); | ||
} | ||
} | ||
index++; | ||
} | ||
} | ||
|
||
return ( | ||
<Stack className="mt-1" direction="horizontal" gap={1}> | ||
<Button variant="neutral" className="ms-auto" onClick={handleClose}> | ||
{t("close")} | ||
</Button> | ||
<Button | ||
variant="brand" | ||
onClick={() => handleSubmit()} | ||
disabled={createUserAPI.isLoading} | ||
> | ||
{createUserAPI.isLoading && <Spinner className="me-2" />} | ||
{t("admin.manage_users.create_account")} | ||
</Button> | ||
</Stack> | ||
); | ||
} | ||
|
||
UserSignupForm.propTypes = { | ||
handleClose: PropTypes.func, | ||
}; | ||
|
||
UserSignupForm.defaultProps = { | ||
handleClose: () => { }, | ||
}; |
100 changes: 100 additions & 0 deletions
100
app/javascript/components/admin/manage_users/forms/ImportFromCSV.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React, { useState } from "react"; | ||
import { Button, Table, Form } from "react-bootstrap"; | ||
import Papa from "papaparse"; | ||
import CsvSignUpForm from "./CsvSignUpForm"; | ||
|
||
const CsvUploadAndDisplay = ({ handleClose }) => { | ||
const [csvData, setCsvData] = useState([]); | ||
const [error, setError] = useState(null); | ||
const handleFileUpload = (event) => { | ||
const file = event.target.files[0]; | ||
if (file) { | ||
Papa.parse(file, { | ||
header: true, | ||
complete: (results) => { | ||
if (results.errors.length) { | ||
setError(results.errors[0].message); | ||
} else { | ||
setCsvData( | ||
results.data.map((elem) => ({ | ||
...elem, | ||
import_status: "pending", | ||
})) | ||
); | ||
setError(null); | ||
} | ||
}, | ||
error: (error) => { | ||
setError(error.message); | ||
}, | ||
}); | ||
} | ||
}; | ||
|
||
function handleStatus(index, import_status) { | ||
setCsvData((prevData) => { | ||
const newData = [...prevData]; | ||
newData[index].import_status = import_status; | ||
return newData; | ||
}); | ||
} | ||
|
||
return ( | ||
<div className="d-flex flex-column gap-4"> | ||
<Form.Group controlId="formFile" className="mb-3"> | ||
<Form.Label>Upload CSV File</Form.Label> | ||
<Form.Control type="file" accept=".csv" onChange={handleFileUpload} /> | ||
</Form.Group> | ||
|
||
{error && <div className="alert alert-danger">{error}</div>} | ||
{csvData.length > 0 && ( | ||
<CsvSignUpForm | ||
users={csvData.map((data) => ({ | ||
name: data.name, | ||
email: data.email, | ||
role: data.role, | ||
language: data.language || "en", | ||
password: "Fe99b949!" + generateRandomFiveDigitNumber(), | ||
verified: data.verified?.toLowerCase() === "true", | ||
}))} | ||
handleStatus={handleStatus} | ||
handleClose={handleClose} | ||
/> | ||
)} | ||
{csvData.length > 0 && ( | ||
<div className="w-full h-96 overflow-scroll"> | ||
<Table striped bordered hover> | ||
<thead> | ||
<tr> | ||
{Object.keys(csvData[0]).map((key) => ( | ||
<th key={key}>{key}</th> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{csvData.map((row, index) => ( | ||
<tr key={index}> | ||
{Object.values(row).map((value, idx) => ( | ||
<td key={idx}>{value}</td> | ||
))} | ||
</tr> | ||
))} | ||
</tbody> | ||
</Table> | ||
</div> | ||
)} | ||
<p className="text-muted"> | ||
Please upload a CSV file with the following columns: name, email, role (Administrator, User, Guest), | ||
verified (true, false), language (de, en, es, ...) | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CsvUploadAndDisplay; | ||
|
||
function generateRandomFiveDigitNumber() { | ||
const min = 10000; | ||
const max = 99999; | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.