Skip to content

Commit

Permalink
Ready View for making sure bamboohr Creds are valid (#119)
Browse files Browse the repository at this point in the history
* Ready View for making sure bamboohr Creds are valid

* comment changes

* new field to check if creds have expire

* minor comment changes
  • Loading branch information
Ashutosh619-sudo authored Dec 27, 2023
1 parent 14e9bee commit 2b10338
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
18 changes: 18 additions & 0 deletions apps/bamboohr/migrations/0006_bamboohr_is_credentials_expired.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.14 on 2023-12-27 10:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bamboohr', '0005_bamboohr_employee_exported_at'),
]

operations = [
migrations.AddField(
model_name='bamboohr',
name='is_credentials_expired',
field=models.BooleanField(default=False, help_text='BambooHr Credential Status'),
),
]
1 change: 1 addition & 0 deletions apps/bamboohr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BambooHr(models.Model):
created_at = models.DateTimeField(auto_now_add=True, help_text='Created at datetime')
updated_at = models.DateTimeField(auto_now=True, help_text='Updated at datetime')
employee_exported_at = models.DateTimeField(auto_now_add=True, help_text='Employee exported to Fyle at datetime')
is_credentials_expired = models.BooleanField(default=False, help_text='BambooHr Credential Status')

class Meta:
db_table = 'bamboohr'
Expand Down
3 changes: 2 additions & 1 deletion apps/bamboohr/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.urls import path

from .views import PostFolder, PostPackage, BambooHrConnection, BambooHrView, BambooHrConfigurationView, \
DisconnectView, SyncEmployeesView
DisconnectView, SyncEmployeesView, HealthCheck

app_name = 'bamboohr'

urlpatterns = [
path('health_check/', HealthCheck.as_view(), name='health-check'),
path('', BambooHrView.as_view(), name='bamboohr'),
path('packages/', PostPackage.as_view(), name='package'),
path('folder/', PostFolder.as_view(), name='folder'),
Expand Down
32 changes: 32 additions & 0 deletions apps/bamboohr/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from bamboosdk.bamboohrsdk import BambooHrSDK

from rest_framework.response import Response
from rest_framework.views import status
Expand All @@ -12,9 +13,40 @@
from apps.bamboohr.actions import disconnect_bamboohr, sync_employees
from apps.names import BAMBOO_HR

from rest_framework.views import APIView

logger = logging.getLogger(__name__)
logger.level = logging.INFO

class HealthCheck(generics.ListAPIView):

def get(self, request, *args, **kwargs):
try:
bamboohr = BambooHr.objects.get(org_id__in=[kwargs['org_id']], is_credentials_expire=False)
bamboohrsdk = BambooHrSDK(api_token=bamboohr.api_token, sub_domain=bamboohr.sub_domain)
response = bamboohrsdk.time_off.get()

if response['timeOffTypes']:
return Response(
data = {
'message': 'Ready'
},
status=status.HTTP_200_OK
)
else:
bamboohr.is_credentials_expired = True
bamboohr.save()
return Response(
data = {
'message': 'Invalid token'
},
status=status.HTTP_400_BAD_REQUEST
)
except BambooHr.DoesNotExist:
return Response(
data={'message': 'Bamboo HR Details Not Found'},
status=status.HTTP_404_NOT_FOUND
)

class BambooHrView(generics.ListAPIView):
serializer_class = BambooHrSerializer
Expand Down

0 comments on commit 2b10338

Please sign in to comment.