From 09920cdbff7b01f7fe732a6494cc125f25f47e70 Mon Sep 17 00:00:00 2001 From: Zulfikar Akbar Muzakki Date: Mon, 18 Dec 2023 17:02:45 +0700 Subject: [PATCH] Revert user expert status, add auto create user profile (#463) * Revert user expert status, add auto create user profile * revert settings. --- ...profile_expert_approval_status_and_more.py | 35 +++++++++++++++++++ .../minisass_authentication/models.py | 15 ++++++-- .../src/components/UserForm/EditProfile.tsx | 6 ++-- .../src/pages/Howto/index.tsx | 34 ++++++++++++------ 4 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 django_project/minisass_authentication/migrations/0009_alter_userprofile_expert_approval_status_and_more.py diff --git a/django_project/minisass_authentication/migrations/0009_alter_userprofile_expert_approval_status_and_more.py b/django_project/minisass_authentication/migrations/0009_alter_userprofile_expert_approval_status_and_more.py new file mode 100644 index 000000000..9caa771f6 --- /dev/null +++ b/django_project/minisass_authentication/migrations/0009_alter_userprofile_expert_approval_status_and_more.py @@ -0,0 +1,35 @@ +# Generated by Django 4.2.7 on 2023-12-18 05:40 + +from django.db import migrations, models + + +def change_user_profile(apps, schema_editor): + UserProfile = apps.get_model('minisass_authentication', 'UserProfile') + for user_profile in UserProfile.objects.all(): + user_profile.expert_approval_status = 'REJECTED' + if user_profile.expert_approval_status == 'APPROVED' and user_profile.certificate: + user_profile.is_expert = True + else: + user_profile.is_expert = False + user_profile.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('minisass_authentication', '0008_userprofile_expert_approval_status'), + ] + + operations = [ + migrations.AlterField( + model_name='userprofile', + name='expert_approval_status', + field=models.CharField(choices=[('PENDING', 'PENDING'), ('APPROVED', 'APPROVED'), ('REJECTED', 'REJECTED')], default='REJECTED'), + ), + migrations.AlterField( + model_name='userprofile', + name='is_password_enforced', + field=models.BooleanField(default=True, help_text='Flag whether user has been enforced to use strong password'), + ), + migrations.RunPython(change_user_profile, lambda a, b: None) + ] diff --git a/django_project/minisass_authentication/models.py b/django_project/minisass_authentication/models.py index 0fd0ea810..559b27bb0 100644 --- a/django_project/minisass_authentication/models.py +++ b/django_project/minisass_authentication/models.py @@ -56,11 +56,11 @@ class UserProfile(models.Model): country = models.CharField(max_length=255, blank=True, null=True) is_expert = models.BooleanField(default=False) is_password_enforced = models.BooleanField( - default=False, + default=True, help_text='Flag whether user has been enforced to use strong password' ) expert_approval_status = models.CharField( - default=PENDING_STATUS, + default=REJECTED_STATUS, choices=EXPERT_APPROVAL_STATUS ) certificate = models.FileField( @@ -93,3 +93,14 @@ def post_certificate_approve(sender, instance: UserProfile, **kwargs): [email], html_message=message ) + + +@receiver(post_save, sender=settings.AUTH_USER_MODEL) +def post_user_create(sender, instance: UserProfile, created, **kwargs): + if created: + UserProfile.objects.get_or_create( + user=instance, + defaults={ + 'is_password_enforced': True + } + ) diff --git a/django_project/minisass_frontend/src/components/UserForm/EditProfile.tsx b/django_project/minisass_frontend/src/components/UserForm/EditProfile.tsx index 878e2b885..1550461fd 100644 --- a/django_project/minisass_frontend/src/components/UserForm/EditProfile.tsx +++ b/django_project/minisass_frontend/src/components/UserForm/EditProfile.tsx @@ -4,7 +4,6 @@ import Select from "react-select"; import CountrySelector from "../../components/Countries/selector"; import {COUNTRIES} from "../../components/Countries/countries"; import {SelectMenuOption} from "../../components/Countries/types"; -import LoginFormModal from "../../components/LoginFormModal"; import {globalVariables} from '../../utils'; import axios from "axios"; import {useAuth} from "../../AuthContext"; @@ -86,10 +85,13 @@ const EditProfile: React.FC = ({ const headers = {'Authorization': `Bearer ${state.user.access_token}`}; axios.get(UPDATE_PROFILE, {headers}).then((response) => { if (response.data) { + const country = COUNTRIES.find((option) => option.value === response.data.country) ? + COUNTRIES.find((option) => option.value === response.data.country) : 'ZA' const newFormData = { ...response.data, - country: response.data.country ? response.data.country : 'ZA', + country: country, } + console.debug(newFormData) setFormData(newFormData) } }).catch((error) => { diff --git a/django_project/minisass_frontend/src/pages/Howto/index.tsx b/django_project/minisass_frontend/src/pages/Howto/index.tsx index 9ba0ae754..f42cf5232 100644 --- a/django_project/minisass_frontend/src/pages/Howto/index.tsx +++ b/django_project/minisass_frontend/src/pages/Howto/index.tsx @@ -1167,18 +1167,30 @@ const HowtoPage: React.FC = () => { src={`${globalVariables.staticPath}img_rectangle6_280x303.png`} alt="rectangleSix_One" /> -
- {videos.map(video => ( -
- +
+
+ + How To Videos + +
+
+
+ {videos.map(video => ( +
+ +
+ ))}
- ))} +