Skip to content

Commit

Permalink
Try to automatize the user_windows creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Heibert committed Feb 8, 2024
1 parent abfc488 commit fca9459
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 19 deletions.
4 changes: 3 additions & 1 deletion INSIGHTSAPI/INSIGHTSAPI/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
},
"django_auth_ldap": {
"handlers": ["console", "response_file", "exception_file"],
"level": "INFO",
"level": "DEBUG",
"propagate": True,
},
},
Expand Down Expand Up @@ -348,6 +348,8 @@
"last_name": "sn",
}

AUTH_LDAP_ALWAYS_UPDATE_USER = False

# This works faster in ldap but i don't know how implement it with the sAMAcountName
# AUTH_LDAP_USER_DN_TEMPLATE = 'CN=Heibert Steven Mogollon Mahecha,OU=IT,OU=BOGOTA,DC=CYC-SERVICES,DC=COM,DC=CO'

Expand Down
1 change: 1 addition & 0 deletions INSIGHTSAPI/api_token/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CustomTokenObtainPairView(TokenObtainPairView):

# This change is to allow cookies to be set in the response
def post(self, request, *args, **kwargs):
print("INICIE SESION LO JURO")
response = super().post(request, *args, **kwargs)
if response.data and "access" in response.data:
if settings.DEBUG:
Expand Down
32 changes: 23 additions & 9 deletions INSIGHTSAPI/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
from django.core.exceptions import ValidationError
import mysql.connector
from hierarchy.models import Area
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.contrib.auth.signals import user_logged_in
from django_auth_ldap.backend import populate_user

logger = logging.getLogger("exceptions")


# Pending of squashing this migrations to delete the function
def validate_file_extension(image):
"""Validates that the uploaded file is a .webp image."""
if not image.name.endswith(".webp"):
raise ValidationError("Solo puedes subir imágenes .webp ")
elif image.size > 5000000:
raise ValidationError("El archivo no puede pesar mas de 5MB")

# if not image.name.endswith(".webp"):
# raise ValidationError("Solo puedes subir imágenes .webp ")
# elif image.size > 5000000:
# raise ValidationError("El archivo no puede pesar mas de 5MB")

class User(AbstractUser):
"""Custom user model."""
Expand Down Expand Up @@ -52,6 +55,7 @@ class Meta:

def save(self, *args, **kwargs):
"""Create a user in the database."""
print("CREANDO USUARIO")
with connections["staffnet"].cursor() as db_connection:
db_connection.execute(
"SELECT cedula, cargo,campana_general FROM employment_information WHERE usuario_windows = %s",
Expand All @@ -61,9 +65,10 @@ def save(self, *args, **kwargs):
if str(self.username).upper() in {"ZEUS","ADMIN","STAFFNET"}:
result = ("00000000","Administrador", "Administrador")
elif not result:
raise ValidationError(
"Este usuario de windows no esta registrado en StaffNet contacta a tecnología para mas información."
)
# raise ValidationError(
# "Este usuario de windows no esta registrado en StaffNet contacta a tecnología para mas información."
# )
super(User, self).save(*args, **kwargs)
self.cedula = result[0]
self.job_title = result[1]
area, _ = Area.objects.get_or_create(name=result[2])
Expand All @@ -80,3 +85,12 @@ def save(self, *args, **kwargs):
):
setattr(self, field.attname, getattr(self, field.attname).upper())
super(User, self).save(*args, **kwargs)

# @receiver(pre_save, sender=User)
# def pre_save_user(sender, instance, **kwargs):
# print("PRE SAVE")
# print(sender.__dict__)
# print()
# print(instance.__dict__)
# print()
# print(kwargs)
12 changes: 12 additions & 0 deletions INSIGHTSAPI/vacancy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def __str__(self):
"""This method returns a string representation of the vacancy."""
return str(self.name)

# class Status(models.Model):
# """This class represents a status."""

# name = models.CharField(max_length=100)
# def __str__(self):
# """This method returns a string representation of the status."""
# return str(self.name)

class Reference(models.Model):
"""This class represents a reference."""
Expand All @@ -29,6 +36,11 @@ class Reference(models.Model):
vacancy = models.ForeignKey(
Vacancy, related_name="references", on_delete=models.DO_NOTHING
)
# status = models.ForeignKey(
# Status, related_name="references", on_delete=models.DO_NOTHING, null=True
# )
# comments = models.CharField(max_length=400, null=True, blank=True)
# created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
"""This method returns a string representation of the reference."""
Expand Down
8 changes: 0 additions & 8 deletions INSIGHTSAPI/vacancy/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ def validate_image(self, value):
"""Validates the image field"""
validate_and_convert_to_webp(value)
return value

def is_valid(self, raise_exception=False):
print("is_valid")
print(self.initial_data)
print(self.fields)
response = super().is_valid()
print("VALIDADO")
print(self.validated_data)


class ReferenceSerializer(serializers.ModelSerializer):
Expand Down
1 change: 0 additions & 1 deletion INSIGHTSAPI/vacancy/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def setUp(self, user=None):

def test_create_vacancy(self):
"""Test create vacancy."""
print("crear")
# Upload image
response = self.client.post(
reverse("vacancy-list"),
Expand Down

0 comments on commit fca9459

Please sign in to comment.