Skip to content

Commit

Permalink
Revert user expert status, add auto create user profile (#463)
Browse files Browse the repository at this point in the history
* Revert user expert status, add auto create user profile

* revert settings.
  • Loading branch information
zamuzakki authored Dec 18, 2023
1 parent 1c7f8f3 commit 09920cd
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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)
]
15 changes: 13 additions & 2 deletions django_project/minisass_authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -86,10 +85,13 @@ const EditProfile: React.FC<EditProfileInterface> = ({
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) => {
Expand Down
34 changes: 23 additions & 11 deletions django_project/minisass_frontend/src/pages/Howto/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1167,18 +1167,30 @@ const HowtoPage: React.FC = () => {
src={`${globalVariables.staticPath}img_rectangle6_280x303.png`}
alt="rectangleSix_One"
/>
<div className="scrolling-container">
{videos.map(video => (
<div key={video.id} className="VideoTile">
<iframe
className="VideoEmbed"
src={video.embed_code}
title={video.title}
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
></iframe>
<div className="flex container flex-col w-[70%]">
<div>
<Text
className="sm:text-4xl md:text-[38px] text-[40px] text-white-A700 w-auto"
size="txtRalewayRomanBold40"
>
How To Videos
</Text>
</div>
<div>
<div className="scrolling-container">
{videos.map(video => (
<div key={video.id} className="VideoTile">
<iframe
className="VideoEmbed"
src={video.embed_code}
title={video.title}
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
></iframe>
</div>
))}
</div>
))}
</div>
</div>
</div>

Expand Down

0 comments on commit 09920cd

Please sign in to comment.