From 0665774fa3e17261d3b896d53a5780fe6bcc2bfa Mon Sep 17 00:00:00 2001 From: kthouky Date: Tue, 8 Aug 2023 13:13:09 +0200 Subject: [PATCH] ensorsements mutually exclusive with censures --- fediseer/apis/v1/censures.py | 4 +++- fediseer/apis/v1/endorsements.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fediseer/apis/v1/censures.py b/fediseer/apis/v1/censures.py index 0ac7000..4293cb7 100644 --- a/fediseer/apis/v1/censures.py +++ b/fediseer/apis/v1/censures.py @@ -1,5 +1,5 @@ from fediseer.apis.v1.base import * -from fediseer.classes.instance import Censure +from fediseer.classes.instance import Censure,Endorsement class CensuresGiven(Resource): get_parser = reqparse.RequestParser() @@ -89,6 +89,8 @@ class Censures(Resource): raise e.NotFound(f"Something went wrong trying to register this instance.") if not target_instance: raise e.BadRequest("Instance to censure not found") + if database.get_endorsement(target_instance.id,instance.id): + raise e.BadRequest("You can't censure an instance you've endorsed! Please withdraw the endorsement first.") if database.get_censure(target_instance.id,instance.id): return {"message":'OK'}, 200 new_censure = Censure( diff --git a/fediseer/apis/v1/endorsements.py b/fediseer/apis/v1/endorsements.py index c515145..ec1450e 100644 --- a/fediseer/apis/v1/endorsements.py +++ b/fediseer/apis/v1/endorsements.py @@ -1,5 +1,5 @@ from fediseer.apis.v1.base import * -from fediseer.classes.instance import Endorsement +from fediseer.classes.instance import Endorsement,Censure class Approvals(Resource): get_parser = reqparse.RequestParser() @@ -91,6 +91,8 @@ class Endorsements(Resource): raise e.Forbidden("Not Guaranteed instances can be endorsed. Please guarantee for them, or find someone who will.") if not target_instance: raise e.BadRequest("Instance to endorse not found") + if database.get_censure(target_instance.id,instance.id): + raise e.BadRequest("You can't endorse an instance you've censured! Please withdraw the censure first.") if database.get_endorsement(target_instance.id,instance.id): return {"message":'OK'}, 200 new_endorsement = Endorsement(