Skip to content

Commit

Permalink
DBP-830 Merge all feature branches
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncolincap committed Jun 7, 2024
2 parents 001bf21 + c4de7ee commit 2f16b3e
Show file tree
Hide file tree
Showing 18 changed files with 2,853 additions and 2,089 deletions.
13 changes: 10 additions & 3 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ RUN apk add --no-cache \
# Builder stage for installing build dependencies
FROM base AS builder



# Builder stage for installing build dependencies
FROM base AS builder

RUN apk add --no-cache \
build-base \
curl-dev \
Expand All @@ -36,7 +41,11 @@ RUN apk add --no-cache \
yaml-dev \
zlib-dev



COPY Gemfile* ./

RUN bundle lock --add-platform x86_64-linux-musl
RUN bundle config build.nokogiri --use-system-libraries \
&& bundle config set --local deployment 'true' --without 'development test' \
&& bundle install -j4 \
Expand Down Expand Up @@ -80,6 +89,4 @@ ARG VERSION_CODE
ENV VERSION_CODE=$VERSION_CODE

EXPOSE 3000

# Start rsyslog and cron daemon, then start the Rails application
CMD ["sh", "-c", "./bin/start"]
CMD ["bash", "-c", "./bin/start"]
4 changes: 2 additions & 2 deletions Procfile.dev
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
1 change: 1 addition & 0 deletions app/assets/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
"ban": "Sperren",
"unban": "Entsperren",
"deleted": "Gelöscht",
"import_from_csv": "Von CSV importieren",
"invited_tab": "Eingeladen",
"invite_user": "Nutzer:in einladen",
"send_invitation": "Einladung senden",
Expand Down
1 change: 1 addition & 0 deletions app/assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
"ban": "Ban",
"unban": "Unban",
"deleted": "Deleted",
"import_from_csv": "Import from CSV",
"invited_tab": "Invited",
"invite_user": "Invite User",
"send_invitation": "Send Invitation",
Expand Down
25 changes: 21 additions & 4 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ def create
return render_error errors: Rails.configuration.custom_error_msgs[:hcaptcha_invalid]
end

if create_user_params[:language].blank?
# Users created by a user will have the creator language by default with a fallback to the server configured default_locale.
create_user_params[:language] = current_user&.language || I18n.default_locale if create_user_params[:language].blank?
create_user_params[:language] = current_user&.language || I18n.default_locale if create_user_params[:language].blank?
end

role_name = create_user_params[:role] || default_role.name
user_role = Role.find_by(name: role_name, provider: current_provider)

user = UserCreator.new(user_params: create_user_params.except(:invite_token), provider: current_provider, role: default_role).call
user = UserCreator.new(user_params: create_user_params.except(:invite_token, :role), provider: current_provider, role: user_role).call

smtp_enabled = ENV['SMTP_SERVER'].present?

Expand All @@ -71,12 +76,18 @@ def create
user.pending! if !admin_create && registration_method == SiteSetting::REGISTRATION_METHODS[:approval]

if user.save
if smtp_enabled
if smtp_enabled && !user.verified?
token = user.generate_activation_token!
UserMailer.with(user:,
activation_url: activate_account_url(token), base_url: request.base_url,
provider: current_provider).activate_account_email.deliver_later

token = user.generate_reset_token!

UserMailer.with(user:,
reset_url: reset_password_url(token), base_url: request.base_url,
provider: current_provider).reset_password_email.deliver_later

UserMailer.with(user:, admin_panel_url:, base_url: request.base_url, provider: current_provider).new_user_signup_email.deliver_later
end

Expand Down Expand Up @@ -156,7 +167,7 @@ def change_password
private

def create_user_params
@create_user_params ||= params.require(:user).permit(:name, :email, :password, :avatar, :language, :role_id, :invite_token)
@create_user_params ||= params.require(:user).permit(:name, :email, :password, :avatar, :language, :role_id, :invite_token, :role, :verified)
end

def update_user_params
Expand All @@ -174,6 +185,12 @@ def valid_invite_token
Invitation.destroy_by(email: create_user_params[:email].downcase, provider: current_provider,
token: create_user_params[:invite_token]).present?
end

def get_role_by_name(role_name)
role = Role.find_by(name: role_name, provider: current_provider)
Rails.logger.info "Role found: #{role.inspect} (Class: #{role.class})" # Log the role object and its class
role
end
end
end
end
14 changes: 13 additions & 1 deletion app/javascript/components/admin/manage_users/ManageUsers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import PendingUsers from './PendingUsers';
import BannedUsers from './BannedUsers';
import { useAuth } from '../../../contexts/auth/AuthProvider';
import useEnv from '../../../hooks/queries/env/useEnv';
import ImportFromCSV from './forms/ImportFromCSV';


export default function ManageUsers() {
const { t } = useTranslation();
Expand Down Expand Up @@ -92,7 +94,17 @@ export default function ManageUsers() {
/>
)
}

{(!envAPI.isLoading && !envAPI.data?.EXTERNAL_AUTH) && (
<Modal size="xl"
modalButton={(
<Button variant="brand" className="mx-2">
<UserPlusIcon className="hi-s me-1" /> {t('admin.manage_users.import_from_csv')}
</Button>
)}
title={t('admin.manage_users.import_from_csv')}
body={<ImportFromCSV />}
/>
)}
</div>
</Stack>
<Tabs defaultActiveKey="active" unmountOnExit>
Expand Down
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 app/javascript/components/admin/manage_users/forms/ImportFromCSV.jsx
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ export default function UserSignupForm({ handleClose }) {
<FormControl field={fields.password} type="password" />
<FormControl field={fields.password_confirmation} type="password" />


<Stack className="mt-1" direction="horizontal" gap={1}>
<Button variant="neutral" className="ms-auto" onClick={handleClose}>
{t('close')}
</Button>
<Button variant="brand" type="submit" disabled={createUserAPI.isLoading}>
{ createUserAPI.isLoading && <Spinner className="me-2" /> }
{ t('admin.manage_users.create_account') }
{createUserAPI.isLoading && <Spinner className="me-2" />}
{t('admin.manage_users.create_account')}
</Button>
</Stack>
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ export default function useUserSignupForm({ defaultValues: _defaultValues, ..._c
},
},
},
role: {
label: "Role",
placeHolder: "Role",
controlId: 'createUserFormRole',
hookForm: {
id: 'role',
},
},
}), [i18n.resolvedLanguage]);

const validationSchema = useSignUpFormValidation();
Expand Down
5 changes: 2 additions & 3 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env bash

if [ -f .env ]; then
export $(echo $(cat .env | sed 's/#.*//g'| xargs) | envsubst)
export $(echo $(cat .env | sed 's/#.*//g' | xargs) | envsubst)
fi
export PORT="${PORT:=3000}"
echo "Web app starting on port: $PORT"

if ! command -v foreman &> /dev/null
then
if ! command -v foreman &>/dev/null; then
echo "Installing foreman..."
gem install foreman
fi
Expand Down
6 changes: 3 additions & 3 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ de:
sign_up: Registrieren
new_user_signup:
new_user: Neue BigBlueButton Benutzeranmeldung
new_user_description: Ein neuer Benutzer hat sich angemeldet, um BigBlueButton zu nutzen.
new_user_description: Ein neuer Benutzer hat sich für die Nutzung von BigBlueButton angemeldet.
name: "Name: %{name}"
email: "E-Mail: %{email}"
admin_panel: "Administrator-Panel"
take_action: "Um den neuen Benutzer zu sehen oder die notwendigen Maßnahmen zu ergreifen, besuchen Sie das Administrator-Panel"
admin_panel: "Administrationsbereich"
take_action: "Um den neuen Benutzer zu sehen oder die notwendigen Maßnahmen zu ergreifen, besuchen Sie den Administrationsbereich"
reset:
password_reset: Passwort zurücksetzen
password_reset_requested: "Eine Passwortrücksetzung wurde für %{email} beantragt."
Expand Down
Loading

0 comments on commit 2f16b3e

Please sign in to comment.