Skip to content

Commit

Permalink
Merge pull request #132 from CodeHive-Solutions/dev
Browse files Browse the repository at this point in the history
Some bug fix
  • Loading branch information
Heibert authored Sep 10, 2024
2 parents 3532a29 + 06e255d commit d181efe
Show file tree
Hide file tree
Showing 14 changed files with 233 additions and 185 deletions.
2 changes: 2 additions & 0 deletions INSIGHTSAPI/INSIGHTSAPI/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
app.config_from_object("django.conf:settings", namespace="CELERY")

app.autodiscover_tasks(["INSIGHTSAPI"])

app.log.setup()
2 changes: 1 addition & 1 deletion INSIGHTSAPI/INSIGHTSAPI/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def str_to_bool(value: str) -> bool:
# LDAP configuration
AUTH_LDAP_SERVER_URI = "ldap://CYC-SERVICES.COM.CO:389"
AUTH_LDAP_BIND_DN = "CN=StaffNet,OU=TECNOLOGÍA,OU=BOGOTA,DC=CYC-SERVICES,DC=COM,DC=CO"
AUTH_LDAP_BIND_PASSWORD = os.getenv("AdminLDAPPassword")
AUTH_LDAP_BIND_PASSWORD = os.environ["AdminLDAPPassword"]

# AUTH_LDAP_USER_SEARCH = LDAPSearch(
# "OU=BOGOTA,DC=CYC-SERVICES,DC=COM,DC=CO", # Search base
Expand Down
6 changes: 5 additions & 1 deletion INSIGHTSAPI/services/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.test import TestCase, Client, override_settings
from django.urls import reverse
from django.conf import settings
from django.core.cache import cache
from users.models import User
from services.models import Answer
from hierarchy.models import Area, JobPosition
Expand Down Expand Up @@ -140,6 +141,9 @@ def test_send_report_ethical_line_with_contact(self):
class HolidayTest(TestCase):
"""Test for holidays."""

def setUp(self):
cache.clear()

def test_holiday(self):
"""Test that the holiday is a holiday."""
self.assertTrue(holidays.Colombia().get("2022-01-01"))
Expand All @@ -152,7 +156,7 @@ def test_get_holidays(self):
"""Test that the holidays are retrieved."""
response = self.client.get("/services/holidays/2024/")
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(response.data, holidays.CO(years=range(2024, 2026)).items())
self.assertEqual(response.data, list(holidays.CO(years=range(2024, 2026)).items()))


class QuestionTest(BaseTestCase):
Expand Down
3 changes: 2 additions & 1 deletion INSIGHTSAPI/services/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import holidays
from rest_framework.response import Response
from django.http import JsonResponse
from django.views.decorators.cache import cache_page, cache_control
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import AllowAny
Expand Down Expand Up @@ -88,7 +89,7 @@ def get_holidays(request, year):
except ValueError:
return Response({"error": "El año debe ser un número"}, status=400)
# Get the holidays of the year and the next year
holidays_year = holidays.CO(years=range(year, year + 2)).items()
holidays_year = list(holidays.CO(years=range(year, year + 2)).items())
return Response(holidays_year, status=200)


Expand Down
10 changes: 10 additions & 0 deletions INSIGHTSAPI/vacation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ def validate(self, attrs):
raise serializers.ValidationError(
"No puedes crear una solicitud para este usuario."
)
else:
# Update
if (
self.instance.manager_approbation
and "status" in attrs
and attrs["status"] == "CANCELADA"
):
raise serializers.ValidationError(
"No puedes cancelar una solicitud que ya ha sido aprobada por tu jefe."
)
return attrs

def create(self, validated_data):
Expand Down
46 changes: 8 additions & 38 deletions INSIGHTSAPI/vacation/templates/vacation_request.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
html,
body {
height: 100%;
margin: 0;
padding: 0;
margin: -100px 10px 0px 10px;
font-family: 'Helvetica Neue', Arial, sans-serif;
color: #333;
line-height: 1.6;
background: linear-gradient(rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.9)),
url('https://insights-api.cyc-bpo.com/static/images/just_logo.png') no-repeat center center;
background-size: cover;
text-align: center;
align-items: center;
font-size: 20px;
display: flex;
justify-content: center;
}
Expand All @@ -26,7 +25,6 @@
}

.header {
text-align: center;
margin-top: 80px;
margin-bottom: 40px;
}
Expand All @@ -38,26 +36,14 @@
letter-spacing: 1px;
}

.content p {
margin-bottom: 15px;
font-size: 18px;
text-align: justify;
}

.signature {
margin-top: 30px;
margin-top: 200px;
text-align: center;
}

.signature p {
margin: 5px 0;
}

.signature-line {
margin: 150px 0 10px 0;
padding-top: 10px;
font-size: 18px;
font-style: italic;
text-align: left;
}

.footer {
Expand All @@ -66,23 +52,6 @@
text-align: center;
color: #777;
}

@media print {
body {
padding: 0;
margin: 0;
height: auto;
background: none;
}

.card {
margin: 0;
padding: 20px;
box-shadow: none;
width: 100%;
height: auto;
}
}
</style>
</head>

Expand All @@ -93,10 +62,11 @@
<br>
<p>Estimado (a) Gestión Humana</p>
<p>CYC SERVICES S.A.S.</p>
<p>Ref. Solicitud de vacaciones disfrutadas</p>
<br>
<p>
Por la presente le solicito se me conceda {{ vacation.duration }} días de mi periodo vacacional
comprendido para el año {{ vacation.start_date|date:"Y" }},
comprendido para el año {{ vacation.start_date|date:"Y" }}.
</p>
<p>
Los días tomados serán a partir del {{ vacation.start_date }} hasta el día {{ vacation.end_date }}, para
Expand Down
10 changes: 6 additions & 4 deletions INSIGHTSAPI/vacation/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_vacation_list_manager(self):
Q(user__job_position__rank__lt=self.user.job_position.rank)
& Q(user__area=self.user.area)
)
)
).order_by("-created_at")
serializer = VacationRequestSerializer(vacation_requests, many=True)
self.assertEqual(response.data, serializer.data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down Expand Up @@ -289,10 +289,12 @@ def test_vacation_owner_cancel_approved(self):
reverse("vacation-detail", kwargs={"pk": vacation_object.pk}),
{"status": "CANCELADA"},
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)
self.assertEqual(
response.data["non_field_errors"][0],
"No puedes cancelar una solicitud aprobada.",
response.status_code, status.HTTP_400_BAD_REQUEST, response.data
)
self.assertEqual(
str(response.data["non_field_errors"][0]),
"No puedes cancelar una solicitud que ya ha sido aprobada por tu jefe.",
)

def test_vacation_cancel_no_owner(self):
Expand Down
12 changes: 2 additions & 10 deletions INSIGHTSAPI/vacation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class VacationRequestViewSet(viewsets.ModelViewSet):
queryset = VacationRequest.objects.all().select_related("user", "uploaded_by")
queryset = VacationRequest.objects.all().select_related("user", "uploaded_by").order_by("-created_at")
serializer_class = VacationRequestSerializer
permission_classes = [IsAuthenticated]

Expand Down Expand Up @@ -291,15 +291,7 @@ def partial_update(self, request, *args, **kwargs):
and request.user == self.get_object().user
and request.data["status"] == "CANCELADA"
):
if self.get_object().manager_approbation:
return Response(
{
"detail": "No puedes cancelar una solicitud de vacaciones aprobada."
},
status=status.HTTP_400_BAD_REQUEST,
)
else:
return super().partial_update(request, *args, **kwargs)
return super().partial_update(request, *args, **kwargs)

return Response(
{"detail": "You do not have permission to perform this action."},
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
"@mui/lab": "5.0.0-alpha.173",
"@mui/material": "^5.16.7",
"@mui/x-data-grid": "^7.16.0",
"@sentry/react": "^8.29.0",
"@sentry/react": "^8.30.0",
"@sentry/vite-plugin": "^2.22.4",
"cally": "^0.7.1",
"depcheck": "^1.4.7",
"embla-carousel-autoplay": "^8.2.1",
"formik": "^2.4.6",
"lodash": "^4.17.21",
"node-fetch": "^3.3.2",
Expand All @@ -36,6 +37,7 @@
"devDependencies": {
"@types/react": "^18.3.5",
"@vitejs/plugin-react": "^4.3.1",
"rollup-plugin-visualizer": "^5.12.0",
"vite": "^5.4.3"
}
}
Loading

0 comments on commit d181efe

Please sign in to comment.