From 0cd44d2de08430872f65f64209ca4d0c8bce914b Mon Sep 17 00:00:00 2001 From: SilentFlameCR Date: Wed, 17 Jan 2024 13:17:41 -0500 Subject: [PATCH 1/3] added checks for confirm terms and email notifications --- app/assets/locales/en.json | 24 ++++- .../stylesheets/application.bootstrap.scss | 1 + app/assets/stylesheets/signup.scss | 39 ++++++++ app/controllers/api/v1/users_controller.rb | 7 +- .../admin/site_settings/settings/Settings.jsx | 14 +++ .../users/account_activation/ConfirmTerms.jsx | 96 +++++++++++++++++++ .../users/authentication/forms/SignupForm.jsx | 4 + app/javascript/contexts/auth/AuthProvider.jsx | 2 + .../users/authentication/useSignUpForm.js | 18 ++++ .../site_settings/useUpdateSiteSetting.jsx | 3 + app/javascript/routes/AuthenticatedOnly.jsx | 7 ++ app/serializers/user_serializer.rb | 6 +- ...2126_add_confirm_terms_to_site_settings.rb | 20 ++++ db/schema.rb | 10 +- 14 files changed, 241 insertions(+), 10 deletions(-) create mode 100644 app/assets/stylesheets/signup.scss create mode 100644 app/javascript/components/users/account_activation/ConfirmTerms.jsx create mode 100644 db/migrate/20240108202126_add_confirm_terms_to_site_settings.rb diff --git a/app/assets/locales/en.json b/app/assets/locales/en.json index de7aa671bf..fcbe1b7990 100644 --- a/app/assets/locales/en.json +++ b/app/assets/locales/en.json @@ -286,7 +286,11 @@ "allow_users_to_preupload_presentation": "Allow Users to Preupload Presentations", "allow_users_to_preupload_presentation_description": "Users can preupload a presentation to be used as the default presentation for that specific room", "default_visibility": "Default Recording Visibility", - "default_visibility_description": "All newly created recordings will have this visibility by default" + "default_visibility_description": "All newly created recordings will have this visibility by default", + "confirm_terms": "Confirm terms and conditions", + "confirm_terms_description": "Require users to confirm terms and conditions", + "disable": "Disable", + "enable": "Enable" }, "registration": { "registration": "Registration", @@ -401,7 +405,8 @@ "brand_image_deleted": "The brand image has been deleted.", "privacy_policy_updated": "The privacy policy has been updated.", "helpcenter_updated": "The help center link has been updated.", - "terms_of_service_updated": "The terms of service have been updated." + "terms_of_service_updated": "The terms of service have been updated.", + "confirm_terms_updated": "The confirmation for terms of service have been updated." }, "recording": { "recording_visibility_updated": "The recording visibility has been updated.", @@ -460,6 +465,12 @@ "resend_activation_link": "If you haven't received an activation email or if you are having a problem using it, click on the button below to request a new activation email.", "resend_btn_lbl": "Resend Verification" }, + "confirm_terms_page": { + "title": "Confirm terms and conditions", + "account_unconfirmed": "Your account has not accepted the terms and conditions.", + "message": "Please accept the terms and conditions for Greenlight.", + "confirm_btn_lbl": "Confirm" + }, "forms": { "validations": { "full_name": { @@ -487,6 +498,9 @@ "required": "Please enter a password confirmation", "match": "The passwords do not match" }, + "confirm_terms": { + "required": "Please accept the terms and conditions" + }, "emails": { "required": "Please enter at least one valid email", "list": "Please provide a comma separated list of valid emails (user@users.com,user1@users.com,user2@users.com)" @@ -560,6 +574,12 @@ "password_confirmation": { "label": "Confirm Password", "placeholder": "Confirm password" + }, + "confirm_terms": { + "label": "I Accept the terms and conditions" + }, + "email_notifs": { + "label": "I would like to receive email updates from Greenlight" } } }, diff --git a/app/assets/stylesheets/application.bootstrap.scss b/app/assets/stylesheets/application.bootstrap.scss index 57e48faba3..62625d6f91 100644 --- a/app/assets/stylesheets/application.bootstrap.scss +++ b/app/assets/stylesheets/application.bootstrap.scss @@ -27,6 +27,7 @@ @import 'admin_panel'; @import 'pagination'; @import 'fonts'; +@import 'signup.scss'; html, body { diff --git a/app/assets/stylesheets/signup.scss b/app/assets/stylesheets/signup.scss new file mode 100644 index 0000000000..8308585f2f --- /dev/null +++ b/app/assets/stylesheets/signup.scss @@ -0,0 +1,39 @@ +// 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 . + +// making it look like a normal checkbox removing FormControl Css +input[type="checkbox"].form-control { + width: auto; + height: auto; + padding: 0; + margin: 0; + vertical-align: baseline; + position: static; + display: inline-block; + border: none; + background: none; + box-shadow: none; + outline: none; + opacity: 1; + -webkit-appearance: checkbox; /* for WebKit browsers */ + -moz-appearance: checkbox; /* for Firefox */ + appearance: checkbox; +} + +// additional styling +input[type="checkbox"].form-control { + margin-left: 0.5em; +} \ No newline at end of file diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 364199ac45..8fb8b45136 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -100,7 +100,6 @@ def create # Updates the values of a user def update user = User.find(params[:id]) - # User can't change their own role if params[:user][:role_id].present? && current_user == user && params[:user][:role_id] != user.role_id return render_error errors: Rails.configuration.custom_error_msgs[:unauthorized], status: :forbidden @@ -156,11 +155,13 @@ 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, + :confirm_terms, :email_notifs, :invite_token) end def update_user_params - @update_user_params ||= params.require(:user).permit(:name, :password, :avatar, :language, :role_id, :invite_token) + @update_user_params ||= params.require(:user).permit(:name, :password, :avatar, :language, :role_id, + :confirm_terms, :email_notifs, :invite_token) end def change_password_params diff --git a/app/javascript/components/admin/site_settings/settings/Settings.jsx b/app/javascript/components/admin/site_settings/settings/Settings.jsx index 22c9f5b40d..5b0c4f4a22 100644 --- a/app/javascript/components/admin/site_settings/settings/Settings.jsx +++ b/app/javascript/components/admin/site_settings/settings/Settings.jsx @@ -26,6 +26,7 @@ export default function Settings() { const { t } = useTranslation(); const { data: siteSettings, isLoading } = useSiteSettings(['ShareRooms', 'PreuploadPresentation', 'DefaultRecordingVisibility']); const updateDefaultRecordingVisibility = useUpdateSiteSetting('DefaultRecordingVisibility'); + const updateConfirmTerms = useUpdateSiteSetting('ConfirmTerms'); if (isLoading) return null; @@ -77,6 +78,19 @@ export default function Settings() { {t('recording.unpublished')} + + + updateConfirmTerms.mutate({ value: 'false' })}> + {t('admin.site_settings.settings.disable')} + + updateConfirmTerms.mutate({ value: 'true' })}> + {t('admin.site_settings.settings.enable')} + + ); } diff --git a/app/javascript/components/users/account_activation/ConfirmTerms.jsx b/app/javascript/components/users/account_activation/ConfirmTerms.jsx new file mode 100644 index 0000000000..42ed06ae94 --- /dev/null +++ b/app/javascript/components/users/account_activation/ConfirmTerms.jsx @@ -0,0 +1,96 @@ +// 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 . + +import React, { useState } from 'react'; +import { + Button, Card, Stack, +} from 'react-bootstrap'; +import { useTranslation } from 'react-i18next'; +import Spinner from '../../shared_components/utilities/Spinner'; +import Logo from '../../shared_components/Logo'; +import { useAuth } from '../../../contexts/auth/AuthProvider'; +import useUpdateUser from '../../../hooks/mutations/users/useUpdateUser'; + +export default function ConfirmTerms() { + const { t } = useTranslation(); + + const currentUser = useAuth(); + const updateUserAPI = useUpdateUser(currentUser?.id); + const [isCheckedTerms, setIsCheckedTerms] = useState(currentUser?.confirm_terms || false); + const [isCheckedEmails, setIsCheckedEmails] = useState(currentUser?.email_notifs || false); + + // Update the user's confirm_terms value when the button is clicked + const handleConfirmTerms = () => { + updateUserAPI.mutate({ + confirm_terms: isCheckedTerms, + email_notifs: isCheckedEmails, + }); + }; + + return ( +
+
+ +
+ + +

{ t('confirm_terms_page.title') }

+
{ t('confirm_terms_page.account_unconfirmed') }
+
+ { t('confirm_terms_page.message') } + + + + {t('forms.user.signup.fields.confirm_terms.label')} + +
+ setIsCheckedTerms(!isCheckedTerms)} + /> +
+
+ + + + {t('forms.user.signup.fields.email_notifs.label')} + +
+ setIsCheckedEmails(!isCheckedEmails)} + /> +
+
+ + +
+
+ ); +} diff --git a/app/javascript/components/users/authentication/forms/SignupForm.jsx b/app/javascript/components/users/authentication/forms/SignupForm.jsx index c59e2f2b8d..514727e4a5 100644 --- a/app/javascript/components/users/authentication/forms/SignupForm.jsx +++ b/app/javascript/components/users/authentication/forms/SignupForm.jsx @@ -43,6 +43,10 @@ export default function SignupForm() { + + + +