From d2a86f12c332a120d5a10ab2821292a4eee4ac6e Mon Sep 17 00:00:00 2001 From: Faheed Date: Mon, 8 Dec 2025 19:55:21 +0300 Subject: [PATCH] new changes removed the encryption --- NorahUniversity/settings.py | 3 +- recruitment/forms.py | 39 +- recruitment/migrations/0001_initial.py | 19 +- .../migrations/0002_alter_person_address.py | 19 - ...r_person_national_id_alter_person_phone.py | 24 - ...formsubmission_applicant_email_and_more.py | 39 -- recruitment/models.py | 24 +- recruitment/signals.py | 23 +- recruitment/views.py | 6 +- requirements.txt | 3 +- templates/people/person_detail.html | 4 +- templates/people/update_person.html | 8 + .../agency_portal_persons_list.html | 9 + templates/recruitment/applicant_signup.html | 26 ++ templates/recruitment/application_delete.html | 423 ++++++++++++++++-- 15 files changed, 499 insertions(+), 170 deletions(-) delete mode 100644 recruitment/migrations/0002_alter_person_address.py delete mode 100644 recruitment/migrations/0003_alter_person_national_id_alter_person_phone.py delete mode 100644 recruitment/migrations/0004_alter_formsubmission_applicant_email_and_more.py diff --git a/NorahUniversity/settings.py b/NorahUniversity/settings.py index 5662002..66bd7bb 100644 --- a/NorahUniversity/settings.py +++ b/NorahUniversity/settings.py @@ -62,7 +62,7 @@ INSTALLED_APPS = [ "django_q", "widget_tweaks", "easyaudit", - "encrypted_model_fields", + "mathfilters" ] @@ -534,4 +534,3 @@ LOGGING={ } -FIELD_ENCRYPTION_KEY="PWQimxxcDjlRsSSof2gaj42a3frmrLt2xgCTa4R06pE=" \ No newline at end of file diff --git a/recruitment/forms.py b/recruitment/forms.py index fe5829f..4340ba3 100644 --- a/recruitment/forms.py +++ b/recruitment/forms.py @@ -285,6 +285,42 @@ class PersonForm(forms.ModelForm): "gpa": forms.TextInput(attrs={'class': 'custom-decimal-input'}), "national_id":forms.NumberInput(attrs={'min': 0, 'step': 1}), } + def clean_email(self): + email = self.cleaned_data.get('email') + + if not email: + + return email + + + if email: + instance = self.instance + qs = CustomUser.objects.filter(email=email) | CustomUser.objects.filter(username=email) + if not instance.pk: # Creating new instance + + + if qs.exists(): + raise ValidationError(_("A user account with this email address already exists. Please use a different email.")) + + else: # Editing existing instance + # if ( + # qs + # .exclude(pk=instance.user.pk) + # .exists() + # ): + + # raise ValidationError(_("An user with this email already exists.")) + pass + + return email.strip() + + + + + + + return email + class ApplicationForm(forms.ModelForm): class Meta: @@ -987,7 +1023,7 @@ class HiringAgencyForm(forms.ModelForm): } ), "email": forms.EmailInput( - attrs={"class": "form-control"} + attrs={"class": "form-control","required": True} ), "phone": forms.TextInput( attrs={"class": "form-control"} @@ -1076,6 +1112,7 @@ class HiringAgencyForm(forms.ModelForm): # instance = self.instance email = email.lower().strip() if not instance.pk: # Creating new instance + print("created ....") if HiringAgency.objects.filter(email=email).exists(): raise ValidationError("An agency with this email already exists.") else: # Editing existing instance diff --git a/recruitment/migrations/0001_initial.py b/recruitment/migrations/0001_initial.py index ca93ff6..17ce045 100644 --- a/recruitment/migrations/0001_initial.py +++ b/recruitment/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.2.7 on 2025-12-07 13:15 +# Generated by Django 5.2.7 on 2025-12-08 15:04 import django.contrib.auth.models import django.contrib.auth.validators @@ -8,7 +8,6 @@ import django.utils.timezone import django_ckeditor_5.fields import django_countries.fields import django_extensions.db.fields -import encrypted_model_fields.fields import recruitment.validators from django.conf import settings from django.db import migrations, models @@ -153,10 +152,10 @@ class Migration(migrations.Migration): ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), ('user_type', models.CharField(choices=[('staff', 'Staff'), ('agency', 'Agency'), ('candidate', 'Candidate')], default='staff', max_length=20, verbose_name='User Type')), - ('phone', encrypted_model_fields.fields.EncryptedCharField(blank=True, null=True, verbose_name='Phone')), + ('phone', models.CharField(blank=True, null=True, verbose_name='Phone')), ('profile_image', models.ImageField(blank=True, null=True, upload_to='profile_pic/', validators=[recruitment.validators.validate_image_size], verbose_name='Profile Image')), ('designation', models.CharField(blank=True, max_length=100, null=True, verbose_name='Designation')), - ('email', encrypted_model_fields.fields.EncryptedEmailField(error_messages={'unique': 'A user with this email already exists.'}, unique=True)), + ('email', models.EmailField(error_messages={'unique': 'A user with this email already exists.'}, max_length=254, unique=True)), ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), ], @@ -245,8 +244,8 @@ class Migration(migrations.Migration): ('slug', django_extensions.db.fields.RandomCharField(blank=True, editable=False, length=8, unique=True, verbose_name='Slug')), ('name', models.CharField(max_length=200, unique=True, verbose_name='Agency Name')), ('contact_person', models.CharField(blank=True, max_length=150, verbose_name='Contact Person')), - ('email', models.EmailField(blank=True, max_length=254)), - ('phone', models.CharField(blank=True, max_length=20)), + ('email', models.EmailField(max_length=254, unique=True)), + ('phone', models.CharField(blank=True, max_length=20, null=True)), ('website', models.URLField(blank=True)), ('notes', models.TextField(blank=True, help_text='Internal notes about the agency')), ('country', django_countries.fields.CountryField(blank=True, max_length=2, null=True)), @@ -487,14 +486,14 @@ class Migration(migrations.Migration): ('first_name', models.CharField(max_length=255, verbose_name='First Name')), ('last_name', models.CharField(max_length=255, verbose_name='Last Name')), ('middle_name', models.CharField(blank=True, max_length=255, null=True, verbose_name='Middle Name')), - ('email', encrypted_model_fields.fields.EncryptedEmailField(db_index=True, unique=True, verbose_name='Email')), - ('phone', encrypted_model_fields.fields.EncryptedPositiveIntegerField(blank=True, null=True, verbose_name='Phone')), + ('email', models.EmailField(db_index=True, max_length=254, unique=True, verbose_name='Email')), + ('phone', models.CharField(blank=True, null=True, verbose_name='Phone')), ('date_of_birth', models.DateField(blank=True, null=True, verbose_name='Date of Birth')), ('gender', models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female')], max_length=1, null=True, verbose_name='Gender')), ('gpa', models.DecimalField(decimal_places=2, help_text='GPA must be between 0 and 4.', max_digits=3, verbose_name='GPA')), - ('national_id', encrypted_model_fields.fields.EncryptedPositiveIntegerField(help_text='Enter the national id or iqama number')), + ('national_id', models.CharField(help_text='Enter the national id or iqama number')), ('nationality', django_countries.fields.CountryField(blank=True, max_length=2, null=True, verbose_name='Nationality')), - ('address', encrypted_model_fields.fields.EncryptedCharField(blank=True, null=True, verbose_name='Address')), + ('address', models.TextField(blank=True, null=True, verbose_name='Address')), ('profile_image', models.ImageField(blank=True, null=True, upload_to='profile_pic/', validators=[recruitment.validators.validate_image_size], verbose_name='Profile Image')), ('linkedin_profile', models.URLField(blank=True, null=True, verbose_name='LinkedIn Profile URL')), ('agency', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='recruitment.hiringagency', verbose_name='Hiring Agency')), diff --git a/recruitment/migrations/0002_alter_person_address.py b/recruitment/migrations/0002_alter_person_address.py deleted file mode 100644 index 652cf32..0000000 --- a/recruitment/migrations/0002_alter_person_address.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 5.2.7 on 2025-12-07 13:38 - -import encrypted_model_fields.fields -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('recruitment', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='person', - name='address', - field=encrypted_model_fields.fields.EncryptedTextField(blank=True, null=True, verbose_name='Address'), - ), - ] diff --git a/recruitment/migrations/0003_alter_person_national_id_alter_person_phone.py b/recruitment/migrations/0003_alter_person_national_id_alter_person_phone.py deleted file mode 100644 index 059c9f8..0000000 --- a/recruitment/migrations/0003_alter_person_national_id_alter_person_phone.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 5.2.7 on 2025-12-07 13:43 - -import encrypted_model_fields.fields -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('recruitment', '0002_alter_person_address'), - ] - - operations = [ - migrations.AlterField( - model_name='person', - name='national_id', - field=encrypted_model_fields.fields.EncryptedCharField(help_text='Enter the national id or iqama number'), - ), - migrations.AlterField( - model_name='person', - name='phone', - field=encrypted_model_fields.fields.EncryptedCharField(blank=True, null=True, verbose_name='Phone'), - ), - ] diff --git a/recruitment/migrations/0004_alter_formsubmission_applicant_email_and_more.py b/recruitment/migrations/0004_alter_formsubmission_applicant_email_and_more.py deleted file mode 100644 index b0fc78d..0000000 --- a/recruitment/migrations/0004_alter_formsubmission_applicant_email_and_more.py +++ /dev/null @@ -1,39 +0,0 @@ -# Generated by Django 5.2.7 on 2025-12-07 13:59 - -import encrypted_model_fields.fields -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('recruitment', '0003_alter_person_national_id_alter_person_phone'), - ] - - operations = [ - migrations.AlterField( - model_name='formsubmission', - name='applicant_email', - field=encrypted_model_fields.fields.EncryptedEmailField(blank=True, db_index=True, help_text='Email of the applicant'), - ), - migrations.AlterField( - model_name='hiringagency', - name='email', - field=encrypted_model_fields.fields.EncryptedEmailField(blank=True), - ), - migrations.AlterField( - model_name='hiringagency', - name='phone', - field=encrypted_model_fields.fields.EncryptedCharField(blank=True), - ), - migrations.AlterField( - model_name='participants', - name='email', - field=encrypted_model_fields.fields.EncryptedEmailField(verbose_name='Email'), - ), - migrations.AlterField( - model_name='participants', - name='phone', - field=encrypted_model_fields.fields.EncryptedCharField(blank=True, null=True, verbose_name='Phone Number'), - ), - ] diff --git a/recruitment/models.py b/recruitment/models.py index 27c0181..71c220a 100644 --- a/recruitment/models.py +++ b/recruitment/models.py @@ -21,7 +21,7 @@ from django.contrib.contenttypes.models import ContentType from django.db.models import F, Value, IntegerField, CharField,Q from django.db.models.functions import Coalesce, Cast from django.db.models.fields.json import KeyTransform, KeyTextTransform -from encrypted_model_fields.fields import EncryptedCharField,EncryptedEmailField,EncryptedTextField + class EmailContent(models.Model): subject = models.CharField(max_length=255, verbose_name=_("Subject")) @@ -47,7 +47,7 @@ class CustomUser(AbstractUser): user_type = models.CharField( max_length=20, choices=USER_TYPES, default="staff", verbose_name=_("User Type") ) - phone = EncryptedCharField( + phone = models.CharField( blank=True, null=True, verbose_name=_("Phone") ) profile_image = models.ImageField( @@ -60,7 +60,7 @@ class CustomUser(AbstractUser): designation = models.CharField( max_length=100, blank=True, null=True, verbose_name=_("Designation") ) - email = EncryptedEmailField( + email = models.EmailField( unique=True, error_messages={ "unique": _("A user with this email already exists."), @@ -517,12 +517,12 @@ class Person(Base): middle_name = models.CharField( max_length=255, blank=True, null=True, verbose_name=_("Middle Name") ) - email = EncryptedEmailField( + email = models.EmailField( unique=True, db_index=True, verbose_name=_("Email"), ) - phone = EncryptedCharField( + phone = models.CharField( blank=True, null=True, verbose_name=_("Phone") ) date_of_birth = models.DateField( @@ -538,11 +538,11 @@ class Person(Base): gpa = models.DecimalField( max_digits=3, decimal_places=2, verbose_name=_("GPA"),help_text=_("GPA must be between 0 and 4.") ) - national_id = EncryptedCharField( + national_id = models.CharField( help_text=_("Enter the national id or iqama number") ) nationality = CountryField(blank=True, null=True, verbose_name=_("Nationality")) - address = EncryptedTextField(blank=True, null=True, verbose_name=_("Address")) + address = models.TextField(blank=True, null=True, verbose_name=_("Address")) # Optional linking to user account user = models.OneToOneField( @@ -1790,7 +1790,7 @@ class FormSubmission(Base): applicant_name = models.CharField( max_length=200, blank=True, help_text="Name of the applicant" ) - applicant_email = EncryptedEmailField( + applicant_email = models.EmailField( db_index=True, blank=True, help_text="Email of the applicant" ) # Added index @@ -2092,8 +2092,8 @@ class HiringAgency(Base): contact_person = models.CharField( max_length=150, blank=True, verbose_name=_("Contact Person") ) - email = EncryptedEmailField(blank=True) - phone = EncryptedCharField(max_length=20, blank=True) + email = models.EmailField(unique=True) + phone = models.CharField(max_length=20, blank=True,null=True) website = models.URLField(blank=True) notes = models.TextField(blank=True, help_text=_("Internal notes about the agency")) country = CountryField(blank=True, null=True, blank_label=_("Select country")) @@ -2503,8 +2503,8 @@ class Participants(Base): name = models.CharField( max_length=255, verbose_name=_("Participant Name"), null=True, blank=True ) - email =EncryptedEmailField(verbose_name=_("Email")) - phone = EncryptedCharField( + email =models.EmailField(verbose_name=_("Email")) + phone = models.CharField( max_length=12, verbose_name=_("Phone Number"), null=True, blank=True ) designation = models.CharField( diff --git a/recruitment/signals.py b/recruitment/signals.py index 3745585..3e7f408 100644 --- a/recruitment/signals.py +++ b/recruitment/signals.py @@ -459,16 +459,19 @@ def hiring_agency_created(sender, instance, created, **kwargs): def person_created(sender, instance, created, **kwargs): if created and not instance.user: logger.info(f"New Person created: {instance.pk} - {instance.email}") - user = User.objects.create_user( - username=instance.email, - first_name=instance.first_name, - last_name=instance.last_name, - email=instance.email, - phone=instance.phone, - user_type="candidate", - ) - instance.user = user - instance.save() + try: + user = User.objects.create_user( + username=instance.email, + first_name=instance.first_name, + last_name=instance.last_name, + email=instance.email, + phone=instance.phone, + user_type="candidate", + ) + instance.user = user + instance.save() + except Exception as e: + print(e) @receiver(post_save, sender=Source) diff --git a/recruitment/views.py b/recruitment/views.py index 2ea9ccb..7a42f3a 100644 --- a/recruitment/views.py +++ b/recruitment/views.py @@ -242,6 +242,7 @@ class PersonUpdateView( UpdateView,LoginRequiredMixin,StaffOrAgencyRequiredMixin success_url = reverse_lazy("person_list") def form_valid(self, form): + if self.request.POST.get("view") == "portal": form.save() return redirect("agency_portal_persons_list") @@ -5994,9 +5995,12 @@ def application_signup(request, slug): address = form.cleaned_data["address"] # gpa = form.cleaned_data["gpa"] password = form.cleaned_data["password"] + gpa=form.cleaned_data["gpa"] + natiional_id=form.cleaned_data["national_id"] user = User.objects.create_user( - username = email,email=email,first_name=first_name,last_name=last_name,phone=phone,user_type="candidate" + username = email,email=email,first_name=first_name,last_name=last_name,phone=phone,user_type="candidate", + gpa=gpa,natiional_id=natiional_id ) user.set_password(password) user.save() diff --git a/requirements.txt b/requirements.txt index 6c77b46..de2bc7a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -47,8 +47,7 @@ django-ckeditor-5==0.2.18 django-cors-headers==4.9.0 django-countries==7.6.1 django-crispy-forms==2.4 -django-easy-audit==1.3.7 -django-encrypted-model-fields==0.6.5 +django-easy-audit==1.3.7s django-extensions==4.1 django-filter==25.1 django-js-asset==3.1.2 diff --git a/templates/people/person_detail.html b/templates/people/person_detail.html index 7534661..cdf7a1b 100644 --- a/templates/people/person_detail.html +++ b/templates/people/person_detail.html @@ -252,7 +252,7 @@ {% endif %} - {% if user.is_staff %} + {% comment %} {% if user.is_staff %}
{% trans "Edit Applicant" %} @@ -261,7 +261,7 @@ {% trans "Delete" %}
- {% endif %} + {% endif %} {% endcomment %} diff --git a/templates/people/update_person.html b/templates/people/update_person.html index 98c26a9..9b07c1b 100644 --- a/templates/people/update_person.html +++ b/templates/people/update_person.html @@ -278,6 +278,14 @@ {% include "bootstrap5/field.html" with field=form.phone %} +
+ + {% include "bootstrap5/field.html" with field=form.gpa %} +
+
+ + {% include "bootstrap5/field.html" with field=form.national_id %} +
{% include "bootstrap5/field.html" with field=form.date_of_birth %} diff --git a/templates/recruitment/agency_portal_persons_list.html b/templates/recruitment/agency_portal_persons_list.html index 2fae9c3..4ac480d 100644 --- a/templates/recruitment/agency_portal_persons_list.html +++ b/templates/recruitment/agency_portal_persons_list.html @@ -326,6 +326,7 @@