setting offerAccepted to only superAdmins

This commit is contained in:
Gowtham Sai 2022-09-05 23:36:27 +05:30
parent 8d6976fb81
commit c7304cb814
2 changed files with 12 additions and 4 deletions

View File

@ -104,22 +104,29 @@ def updateDeadline(request, id, email, user_type):
@api_view(['POST']) @api_view(['POST'])
@isAuthorized([ADMIN]) @isAuthorized([SUPER_ADMIN])
@precheck([OPENING_ID, OFFER_ACCEPTED]) @precheck([OPENING_ID, OFFER_ACCEPTED])
def updateOfferAccepted(request, id, email, user_type): def updateOfferAccepted(request, id, email, user_type):
try: try:
data = request.data data = request.data
offer_accepted = data[OFFER_ACCEPTED]
opening = get_object_or_404(Placement, pk=data[OPENING_ID]) opening = get_object_or_404(Placement, pk=data[OPENING_ID])
if not opening.offer_accepted: if opening.offer_accepted is None:
opening.offer_accepted = True opening.offer_accepted = offer_accepted == "true"
opening.changed_by = get_object_or_404(User, id=id) opening.changed_by = get_object_or_404(User, id=id)
opening.save() opening.save()
send_opening_notifications(opening.id) send_opening_notifications(opening.id)
else:
raise ValueError("Offer Status already updated")
return Response({'action': "Update Offer Accepted", 'message': "Offer Accepted Updated"}, return Response({'action': "Update Offer Accepted", 'message': "Offer Accepted Updated"},
status=status.HTTP_200_OK) status=status.HTTP_200_OK)
except Http404: except Http404:
return Response({'action': "Update Offer Accepted", 'message': 'Opening Not Found'}, return Response({'action': "Update Offer Accepted", 'message': 'Opening Not Found'},
status=status.HTTP_404_NOT_FOUND) status=status.HTTP_404_NOT_FOUND)
except ValueError as e:
return Response({'action': "Update Offer Accepted", 'message': str(e)},
status=status.HTTP_400_BAD_REQUEST)
except: except:
logger.warning("Update Offer Accepted: " + str(sys.exc_info())) logger.warning("Update Offer Accepted: " + str(sys.exc_info()))
return Response({'action': "Update Offer Accepted", 'message': "Something went wrong"}, return Response({'action': "Update Offer Accepted", 'message': "Something went wrong"},

View File

@ -62,7 +62,8 @@ EMAIL = "email"
STUDENT = 'student' STUDENT = 'student'
ADMIN = 'admin' ADMIN = 'admin'
COMPANY = '' SUPER_ADMIN = 'super_admin'
COMPANY = 'company'
TIER = 'tier' TIER = 'tier'
# To be Configured Properly # To be Configured Properly
FOURTH_YEAR = '2019' FOURTH_YEAR = '2019'