Skip to content

Commit

Permalink
Merge pull request #143 from CodeHive-Solutions/dev
Browse files Browse the repository at this point in the history
Solve bug with vacations
  • Loading branch information
Heibert authored Nov 14, 2024
2 parents 7de9153 + 68a8e19 commit 759dadf
Show file tree
Hide file tree
Showing 38 changed files with 351 additions and 401 deletions.
17 changes: 9 additions & 8 deletions INSIGHTSAPI/users/tests.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
"""Tests for the users app."""

import os
import ldap # type: ignore
import random
from notifications.models import Notification
from services.tests import BaseTestCase
from users.models import User
from hierarchy.models import Area

import ldap # type: ignore
from django.conf import settings
from django.contrib.auth.models import Permission
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase
from django.conf import settings
from django.urls import reverse
from django.test.client import Client
from django.urls import reverse
from hierarchy.models import Area
from notifications.models import Notification
from services.tests import BaseTestCase
from users.models import User


class LDAPAuthenticationTest(TestCase):
Expand Down Expand Up @@ -348,7 +349,7 @@ def test_upload_points_user_not_found(self):
self.assertEqual(response.status_code, 400)
self.assertEqual(
response.data["error"],
"Algunos usuarios no fueron encontrados",
"Actualización exitosa, pero algunos usuarios no fueron encontrados: 1001185391",
)
self.assertEqual(response.data["errors"], ["1001185391"])
self.assertEqual(Notification.objects.count(), 1)
Expand Down
12 changes: 10 additions & 2 deletions INSIGHTSAPI/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import requests
from django.conf import settings
from django.contrib.auth.decorators import permission_required

from django.core.mail import mail_admins
from django.core.validators import validate_email
from django.db import connections
Expand Down Expand Up @@ -277,6 +276,13 @@ def upload_points(request):
for line in lines:
cedula = line[0]
points = line[1]
if not cedula.isdigit() or not points.isdigit():
return Response(
{
"error": f"{'La cédula' if not cedula.isdigit() else 'Los puntos'} ingresados no son válidos, por favor verifica el valor {cedula if not cedula.isdigit() else points} e intenta de nuevo."
},
status=400,
)
user = User.objects.filter(cedula=cedula).first()
if user:
user.points = points
Expand All @@ -293,7 +299,9 @@ def upload_points(request):
request.user,
)
return Response(
{"error": "Actualización exitosa, pero algunos usuarios no fueron encontrados", "errors": errors},
{
"error": f"Actualización exitosa, pero algunos usuarios no fueron encontrados: {', '.join(errors)}"
},
status=400,
)
return Response({"message": "User points updated"})
Expand Down
19 changes: 18 additions & 1 deletion INSIGHTSAPI/vacation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,21 @@

from .models import VacationRequest

admin.site.register(VacationRequest)

@admin.register(VacationRequest)
class VacationAdmin(admin.ModelAdmin):
list_display = (
"user",
"user_job_position",
"start_date",
"end_date",
# "status",
"duration",
"return_date",
)
search_fields = ("user__first_name", "user__last_name")
list_filter = ("status",)
readonly_fields = (
"duration",
"return_date",
)
23 changes: 23 additions & 0 deletions INSIGHTSAPI/vacation/migrations/0023_set_user_job_position.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.db import migrations


def set_user_job_position(apps, schema_editor):
# Get the models involved
VacationRequest = apps.get_model("vacation", "VacationRequest")
User = apps.get_model("users", "User")

# Iterate over all VacationRequest instances to set user_job_position
for request in VacationRequest.objects.all():
if request.user and request.user.job_position:
request.user_job_position = request.user.job_position
request.save(update_fields=["user_job_position"])


class Migration(migrations.Migration):
operations = [
migrations.RunPython(set_user_job_position),
]

dependencies = [
("vacation", "0022_alter_vacationrequest_sat_is_working"),
]
10 changes: 5 additions & 5 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"@mui/icons-material": "^6.1.6",
"@mui/lab": "6.0.0-beta.14",
"@mui/material": "^6.1.6",
"@mui/x-data-grid": "^7.22.1",
"@sentry/react": "^8.37.1",
"@mui/x-data-grid": "^7.22.2",
"@sentry/react": "^8.38.0",
"@sentry/vite-plugin": "^2.22.6",
"cally": "^0.7.2",
"clsx": "^2.1.1",
Expand All @@ -39,7 +39,7 @@
"react-dropzone": "^14.3.5",
"react-filepond": "^7.1.2",
"react-material-ui-carousel": "^3.4.2",
"react-router-dom": "^6.27.0",
"react-router-dom": "^6.28.0",
"rollup-plugin-visualizer": "^5.12.0",
"sonner": "^1.7.0",
"swiper": "^11.1.14",
Expand All @@ -55,10 +55,10 @@
"@vitejs/plugin-react": "^4.3.3",
"@vitest/ui": "^2.1.4",
"jsdom": "^25.0.1",
"oxlint": "^0.11.0",
"oxlint": "^0.11.1",
"prettier": "^3.3.3",
"rollup-plugin-visualizer": "^5.12.0",
"vite": "^5.4.10",
"vite": "^5.4.11",
"vitest": "^2.1.4"
}
}
Loading

0 comments on commit 759dadf

Please sign in to comment.