From 0388be68027f04b490f9a6bf07dddc43520ff59c Mon Sep 17 00:00:00 2001 From: Rupika Date: Wed, 6 Mar 2019 16:39:34 -0800 Subject: [PATCH 1/2] added error message for submitting after review report, and fixed some variable names to avoid overshadowing from outer scope --- back/backend/views.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/back/backend/views.py b/back/backend/views.py index d9997a1..28fdf16 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -204,6 +204,9 @@ def report_detail(request, report_pk): # PUT: Submits a report to the administrator for review, # but is still allowed to make further changes elif request.method == 'PUT': + r = Report.objects.get(id=report_pk) + if r.submitted: + return JsonResponse({"message": "Cannot review a report that has already been submitted."}, status=409) # Send email send_report_to_admin(request, report_pk, status="REVIEW") return JsonResponse({"message": "Request for review is submitted."}) @@ -211,8 +214,8 @@ def report_detail(request, report_pk): # DELETE: Deletes a report from the user's account. elif request.method == 'DELETE': r = Report.objects.get(id=report_pk) - if r.submitted == True: - return JsonResponse({"message": "Cannot delete a report that has been submitted."}, status=409) + if r.submitted: + return JsonResponse({"message": "Cannot delete a report that has already been submitted."}, status=409) # get corresponding sections section_set = Section.objects.filter(report_id=report_pk) for i in section_set: @@ -248,13 +251,13 @@ def finalize_report(request, report_pk): return JsonResponse({"message": "Final report submitted."}) -def user_owns_section(user, section): +def user_owns_section(user, section_id): """ Returns true if the specified user is owner of the section. section -- ID of the section to check. """ - section_to_check = Section.objects.filter(id=section) + section_to_check = Section.objects.filter(id=section_id) if len(section_to_check) < 1: return False report_to_check = section_to_check[0].report_id @@ -268,7 +271,7 @@ def section(request, report_pk, section_pk): section_pk -- Section for which the data should be updated. """ # Check that the user owns the report - if not user_owns_section(user=request.user, section=section_pk): + if not user_owns_section(user=request.user, section_id=section_pk): return JsonResponse({"message": "Current user does not own the specified section."}, status=401) # Check that the report isn't submitted @@ -411,7 +414,7 @@ def send_report_to_admin(request, report_pk, status): message = None if params['reference_number'] == '': message = EmailMultiAlternatives( - "{} ({})".format(params['title'], status), + "[Reimbursinator {}] ({})".format(params['title'], status), msg_plain, from_email, [to_email], From 3dd95a1b12c5e2996b61dee087307c2d21833ec2 Mon Sep 17 00:00:00 2001 From: Rupika Date: Wed, 6 Mar 2019 16:44:44 -0800 Subject: [PATCH 2/2] modified db --- back/db.sqlite3 | Bin 119808 -> 119808 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 8b0f51b2e61a82f933665095c2a306dc755edbe7..15729b1a43cf3ad23d2de756ef6081d0b087ae98 100644 GIT binary patch delta 2446 zcmd6oYiv}<702(H8Qa%hZ2U;T#;;xQ`?0?JzIWH&%^HJW>|#^=SVtsY@2>H#*N=b= zc%v4Wl9Z&OGPzRbLt6=|v>|CfxNL;ornCr9ONpftB~8;dO4=aNC{sNHpW}|=>``p|8P8-*JLjiaU)EG zBh#_j=)(tM^K%Cl#F8T1{OR1mSY#nSH|tBkpI1_AK$irB$^=w~18I|(kJK{ja|PVw zDdBjdU);R8yjfI_+e+12*8S=w>r|1;C`oR+&26!p6^B!@D5_#}pSP1FX+i4(d-_`- z8?ghMaXmKTGF*%en4pi*hv={9UGzuvJM=1AR}0TPp1yVF797pSfP7%rVbfvNVbLM! zXwzZV(W;|GN3)J59gP~i(4eDUN1cvZ9W@#{U|aUl47X~-b};EM>ZsOHrNIN08r)E! zqg=-p9c4O7H7KxI$0i;3>$p!xi3S;pbrfY|r#39qhZ}Vi=*ZWxL5D#{o(31>o`04U zW&{36z#paaUc8O7voHV>&#zs~>6~y$(MVKw$WF(EbyAjNVcVqL9+`|qVveZYX;s3q zq$sjvpUQ9qI5b>)OuGOA#I0cP-!9g#Vc@LLiIge{DzRr(@Kfv$fckw&; zP5e5(fv>BD>pkg-^(p*-c2v=qQEx^>NR|Pe$DtRWd4P)RoUI1HLTa%jvuuYq+Cb z6oqXzTW%2qcZ?YK>=@X+XRqngkT{K!?B;1M-HXz_DMd-&eHBQJc4&k@;3~}O8%D>F z9f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