ensorsements mutually exclusive with censures

pull/17/head
kthouky 2023-08-08 13:13:09 +02:00
parent e852a521be
commit 0665774fa3
2 changed files with 6 additions and 2 deletions

View File

@ -1,5 +1,5 @@
from fediseer.apis.v1.base import * from fediseer.apis.v1.base import *
from fediseer.classes.instance import Censure from fediseer.classes.instance import Censure,Endorsement
class CensuresGiven(Resource): class CensuresGiven(Resource):
get_parser = reqparse.RequestParser() get_parser = reqparse.RequestParser()
@ -89,6 +89,8 @@ class Censures(Resource):
raise e.NotFound(f"Something went wrong trying to register this instance.") raise e.NotFound(f"Something went wrong trying to register this instance.")
if not target_instance: if not target_instance:
raise e.BadRequest("Instance to censure not found") 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): if database.get_censure(target_instance.id,instance.id):
return {"message":'OK'}, 200 return {"message":'OK'}, 200
new_censure = Censure( new_censure = Censure(

View File

@ -1,5 +1,5 @@
from fediseer.apis.v1.base import * from fediseer.apis.v1.base import *
from fediseer.classes.instance import Endorsement from fediseer.classes.instance import Endorsement,Censure
class Approvals(Resource): class Approvals(Resource):
get_parser = reqparse.RequestParser() 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.") raise e.Forbidden("Not Guaranteed instances can be endorsed. Please guarantee for them, or find someone who will.")
if not target_instance: if not target_instance:
raise e.BadRequest("Instance to endorse not found") 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): if database.get_endorsement(target_instance.id,instance.id):
return {"message":'OK'}, 200 return {"message":'OK'}, 200
new_endorsement = Endorsement( new_endorsement = Endorsement(