diff --git a/project/backend/api/urls.py b/project/backend/api/urls.py index 4d06203c..bc3041bc 100644 --- a/project/backend/api/urls.py +++ b/project/backend/api/urls.py @@ -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'), diff --git a/project/backend/api/views.py b/project/backend/api/views.py index e6943322..a6d42c16 100644 --- a/project/backend/api/views.py +++ b/project/backend/api/views.py @@ -774,6 +774,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") diff --git a/project/backend/database/models.py b/project/backend/database/models.py index b2fa3b92..d51dd9df 100644 --- a/project/backend/database/models.py +++ b/project/backend/database/models.py @@ -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')