From 2933e2d5669d79f8d6f37965d3fd31423681fb02 Mon Sep 17 00:00:00 2001 From: mayar osama Date: Tue, 23 Apr 2024 11:19:19 +0200 Subject: [PATCH 1/3] Adding validation to update user --- client/src/components/UpdateUser.vue | 16 +++++-- client/src/utils/validators.ts | 9 +++- ...er_user_gender_alter_user_team_and_more.py | 48 +++++++++++++++++++ server/cshr/models/users.py | 6 +-- 4 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 server/cshr/migrations/0009_alter_user_gender_alter_user_team_and_more.py diff --git a/client/src/components/UpdateUser.vue b/client/src/components/UpdateUser.vue index ca57482e..e407c9a1 100644 --- a/client/src/components/UpdateUser.vue +++ b/client/src/components/UpdateUser.vue @@ -32,11 +32,11 @@ + :rules="[...requiredRules, ...lengthRules(45)]"> + :rules="[...requiredRules, ...lengthRules(45)]"> + :rules="[...emailRules, ...lengthRules(45)]"> + :rules="[...requiredRules, ...lengthRules(100)]"> @@ -69,7 +69,7 @@ + :rules="[...requiredStringRules, ...lengthRules(30)]"> { + console.log("image.value[0].name",image.value[0].name) + console.log("selectedUser.value.image",selectedUser.value.image) + + selectedUser.value.user_type = selectedUser.value.user_type === "Team Lead" ? "Supervisor" : selectedUser.value.user_type await $api.myprofile.update(selectedUser.value.id, { ...selectedUser.value, @@ -288,6 +293,7 @@ export default { supervisorPage, supervisorCount, requiredStringRules, + lengthRules, requiredRules, isLoading, userIsActive, diff --git a/client/src/utils/validators.ts b/client/src/utils/validators.ts index 8a950bf8..6bcedcc9 100644 --- a/client/src/utils/validators.ts +++ b/client/src/utils/validators.ts @@ -29,14 +29,14 @@ export const jobRules = [ (v: string) => typeof v === 'string' || 'Role must be a string.', (v: string) => !!v || 'Role is required.', (v: string) => - (v && v.length >= 3 && v.length <= 50) || 'Role must be between 3 and 50 characters.' + (v && v.length >= 3 && v.length <= 150) || 'Role must be between 3 and 150 characters.' ] export const addressRules = [ (v: string) => typeof v === 'string' || 'Address must be a string.', (v: string) => !!v || 'Address is required.', (v: string) => - (v && v.length >= 3 && v.length <= 50) || 'Address must be between 3 and 50 characters.' + (v && v.length >= 3 && v.length <= 150) || 'Address must be between 3 and 150 characters.' ] // export const socialInsuranceRules = [ // (v: string) => typeof v === 'string' || 'Social Number must be a string.', @@ -56,3 +56,8 @@ export const vacationRules = [ (v: string) => +v <= 80 || 'The maximum allowed value is 80. ', (v: string) => /^(?!00)\d{1,2}$/.test(v) || 'Invalid value.' ] + +export const lengthRules = (maxValue : number) => [ + (v: string) => + (v && v.length >= 3 && v.length <= maxValue) || `The maximum allowed value is ${maxValue}.` +]; \ No newline at end of file diff --git a/server/cshr/migrations/0009_alter_user_gender_alter_user_team_and_more.py b/server/cshr/migrations/0009_alter_user_gender_alter_user_team_and_more.py new file mode 100644 index 00000000..48369bb3 --- /dev/null +++ b/server/cshr/migrations/0009_alter_user_gender_alter_user_team_and_more.py @@ -0,0 +1,48 @@ +# Generated by Django 4.2.9 on 2024-04-23 09:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("cshr", "0008_alter_vacation_actual_days"), + ] + + operations = [ + migrations.AlterField( + model_name="user", + name="gender", + field=models.CharField( + choices=[("Male", "male"), ("Female", "female")], max_length=30 + ), + ), + migrations.AlterField( + model_name="user", + name="team", + field=models.CharField( + choices=[ + ("Business Development", "Businessdevelopment"), + ("Development", "Development"), + ("HR & Finance", "Hrandfinance"), + ("QA", "Qa"), + ("Marketing", "Marketing"), + ("Operations", "Operations"), + ("Support", "Support"), + ], + max_length=30, + ), + ), + migrations.AlterField( + model_name="user", + name="user_type", + field=models.CharField( + choices=[ + ("Admin", "admin"), + ("User", "user"), + ("Supervisor", "supervisor"), + ], + max_length=30, + ), + ), + ] diff --git a/server/cshr/models/users.py b/server/cshr/models/users.py index c8ccdedc..abaa2939 100644 --- a/server/cshr/models/users.py +++ b/server/cshr/models/users.py @@ -95,12 +95,12 @@ class User(AbstractBaseUser, TimeStamp): telegram_link = models.CharField(max_length=100) birthday = models.DateField() joining_at = models.DateField() - team = models.CharField(max_length=20, choices=TEAM.choices) + team = models.CharField(max_length=30, choices=TEAM.choices) salary = models.JSONField(default=dict, null=True, blank=True) location = models.ForeignKey(Office, on_delete=models.CASCADE) skills = models.ManyToManyField(UserSkills, related_name="skills", blank=True) - user_type = models.CharField(max_length=20, choices=USER_TYPE.choices) - gender = models.CharField(max_length=20, choices=GENDER_TYPE.choices) + user_type = models.CharField(max_length=30, choices=USER_TYPE.choices) + gender = models.CharField(max_length=30, choices=GENDER_TYPE.choices) social_insurance_number = models.CharField(max_length=45, null=True, blank=True) address = models.CharField(max_length=150) job_title = models.CharField(max_length=150) From 64b0bc3b1728e0b23d624e4e67562d322818a88e Mon Sep 17 00:00:00 2001 From: mayar osama Date: Tue, 23 Apr 2024 11:22:54 +0200 Subject: [PATCH 2/3] Removing logs --- client/src/components/UpdateUser.vue | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/client/src/components/UpdateUser.vue b/client/src/components/UpdateUser.vue index e407c9a1..02a5a10d 100644 --- a/client/src/components/UpdateUser.vue +++ b/client/src/components/UpdateUser.vue @@ -250,11 +250,7 @@ export default { ) const { execute, isLoading } = useAsyncState( - async () => { - console.log("image.value[0].name",image.value[0].name) - console.log("selectedUser.value.image",selectedUser.value.image) - - + async () => { selectedUser.value.user_type = selectedUser.value.user_type === "Team Lead" ? "Supervisor" : selectedUser.value.user_type await $api.myprofile.update(selectedUser.value.id, { ...selectedUser.value, From c0a4a1e9bd42476bf785a7db2d284bb6c6f3403b Mon Sep 17 00:00:00 2001 From: mayar osama Date: Tue, 23 Apr 2024 11:33:15 +0200 Subject: [PATCH 3/3] Adjusting role validation rules --- client/src/components/UpdateUser.vue | 2 +- client/src/utils/validators.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/components/UpdateUser.vue b/client/src/components/UpdateUser.vue index 02a5a10d..d63a1623 100644 --- a/client/src/components/UpdateUser.vue +++ b/client/src/components/UpdateUser.vue @@ -254,7 +254,7 @@ export default { selectedUser.value.user_type = selectedUser.value.user_type === "Team Lead" ? "Supervisor" : selectedUser.value.user_type await $api.myprofile.update(selectedUser.value.id, { ...selectedUser.value, - image: imageUrl.value ? imageUrl.value : selectedUser.value.image, + image: imageUrl.value ? imageUrl.value : null, location: selectedUser.value.location.id, filename: image.value ? image.value[0].name : null, reporting_to: reporting_to.value ? [reporting_to.value.id] : [] diff --git a/client/src/utils/validators.ts b/client/src/utils/validators.ts index 6bcedcc9..fe10521d 100644 --- a/client/src/utils/validators.ts +++ b/client/src/utils/validators.ts @@ -29,7 +29,7 @@ export const jobRules = [ (v: string) => typeof v === 'string' || 'Role must be a string.', (v: string) => !!v || 'Role is required.', (v: string) => - (v && v.length >= 3 && v.length <= 150) || 'Role must be between 3 and 150 characters.' + (v && v.length >= 2 && v.length <= 150) || 'Role must be between 2 and 150 characters.' ] export const addressRules = [