Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disproof API implemented #672

Merged
merged 2 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions project/backend/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
path('update_content_status/', update_content_status, name='update_content_status'),
path('set_workspace_theorem/', set_workspace_theorem, name='set_workspace_theorem'),
path('set_workspace_proof/', set_workspace_proof, name='set_workspace_proof'),
path('set_workspace_disproof/', set_workspace_disproof, name='set_workspace_disproof'),
path('remove_workspace_theorem/', remove_workspace_theorem, name='remove_workspace_theorem'),
path('remove_workspace_proof/', remove_workspace_proof, name='remove_workspace_proof'),
path('remove_workspace_disproof/', remove_workspace_disproof, name='remove_workspace_disproof'),
path('change_workspace_title/', change_workspace_title, name='change_workspace_title'),
path('promote_contributor/', promote_contributor, name='promote_contributor'),
path('demote_reviewer/', demote_reviewer, name='demote_reviewer'),
Expand Down
83 changes: 83 additions & 0 deletions project/backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,89 @@ def remove_workspace_proof(request):
return JsonResponse({'message': 'Proof entry is successfully removed.'}, status=200)




@csrf_exempt
def set_workspace_disproof(request):
entry_id = request.POST.get("entry_id")
workspace_id = request.POST.get("workspace_id")
if entry_id == None or entry_id == '':
return JsonResponse({'message': 'entry_id field can not be empty'}, status=400)
try:
entry_id = int(entry_id)
except:
return JsonResponse({'message': 'entry_id field has to be a integer'}, status=400)
if workspace_id == None or workspace_id == '':
return JsonResponse({'message': 'workspace_id field can not be empty'}, status=400)
try:
workspace_id = int(workspace_id)
except:
return JsonResponse({'message': 'workspace_id field has to be a integer'}, status=400)
entry = Entry.objects.filter(entry_id=entry_id)
if entry.count() == 0:
return JsonResponse({'message': 'There is no entry with this id.'}, status=404)
workspace = Workspace.objects.filter(workspace_id=workspace_id)
if workspace.count() == 0:
return JsonResponse({'message': 'There is no workspace with this id.'}, status=404)
res = BasicUserDetailAPI.as_view()(request)
if not IsContributor().has_permission(request, delete_entry):
return JsonResponse({'message': 'User is not a Contributor'}, status=403)
if not is_cont_workspace(request):
return JsonResponse({'message': 'User does not have access to this workspace'}, status=403)
workspace = Workspace.objects.get(workspace_id=workspace_id)
if entry[0] not in workspace.entries.all():
return JsonResponse({'message': 'There is no entry with this id in this workspace.'}, status=404)
if workspace.is_finalized:
return JsonResponse({'message': 'Workspace is already finalized'}, status=403)
entry = entry[0]
if entry.is_theorem_entry:
return JsonResponse({'message': 'This Entry is already a theorem entry.'}, status=400)
if entry.is_proof_entry:
return JsonResponse({'message': 'This Entry is already a proof entry.'}, status=400)
if workspace.disproof_entry != None:
workspace.disproof_entry.is_disproof_entry = False
workspace.disproof_entry = entry
entry.is_disproof_entry = True
entry.save()
workspace.save()
return JsonResponse({'message': 'Disproof entry is successfully set.'}, status=200)






@csrf_exempt
def remove_workspace_disproof(request):
workspace_id = request.POST.get("workspace_id")
if workspace_id == None or workspace_id == '':
return JsonResponse({'message': 'workspace_id field can not be empty'}, status=400)
try:
workspace_id = int(workspace_id)
except:
return JsonResponse({'message': 'workspace_id field has to be a integer'}, status=400)
workspace = Workspace.objects.filter(workspace_id=workspace_id)
if workspace.count() == 0:
return JsonResponse({'message': 'There is no workspace with this id.'}, status=404)
res = BasicUserDetailAPI.as_view()(request)
if not IsContributor().has_permission(request, delete_entry):
return JsonResponse({'message': 'User is not a Contributor'}, status=403)
if not is_cont_workspace(request):
return JsonResponse({'message': 'User does not have access to this workspace'}, status=403)
workspace = Workspace.objects.get(workspace_id=workspace_id)
if workspace.is_finalized:
return JsonResponse({'message': 'Workspace is already finalized'}, status=403)
if workspace.disproof_entry != None:
workspace.disproof_entry.is_disproof_entry = False
workspace.disproof_entry = None
workspace.save()
return JsonResponse({'message': 'Disproof entry is successfully removed.'}, status=200)






@csrf_exempt
def set_workspace_theorem(request):
entry_id = request.POST.get("entry_id")
Expand Down
1 change: 1 addition & 0 deletions project/backend/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Workspace(models.Model): #Node and Review Requests may be added later
created_at = models.DateTimeField(auto_now_add=True)
theorem_entry = models.ForeignKey('Entry',null=True,blank=True,on_delete=models.CASCADE,related_name='workspace_theorem')
proof_entry = models.ForeignKey('Entry',null=True, blank=True, on_delete=models.CASCADE,related_name='workspace_proof')
disproof_entry = models.ForeignKey('Entry', null=True, blank=True, on_delete=models.CASCADE,related_name='workspace_disproof')
# theorem_entry = models.ManyToManyField(Entry,related_name='TheoremEntry')
# final_entry = models.ForeignKey(Entry,null=True, on_
# delete=models.CASCADE,related_name='FinalEntry')
Expand Down