feat: Can now provide receipts for censuresz
parent
da33975c61
commit
6fd6fdf35c
|
@ -46,6 +46,7 @@ class Models:
|
||||||
})
|
})
|
||||||
self.response_model_instances_censured = api.inherit('CensuredInstanceDetails', self.response_model_instances, {
|
self.response_model_instances_censured = api.inherit('CensuredInstanceDetails', self.response_model_instances, {
|
||||||
'censure_reasons': fields.List(fields.String(description="The reasons instances have given for censuring this instance")),
|
'censure_reasons': fields.List(fields.String(description="The reasons instances have given for censuring this instance")),
|
||||||
|
'censure_evidence': fields.List(fields.String(description="Evidence justifying this censure, typically should be one or more URLs.")),
|
||||||
'censure_count': fields.Integer(description="The amount of censures this instance has received from the reference instances"),
|
'censure_count': fields.Integer(description="The amount of censures this instance has received from the reference instances"),
|
||||||
})
|
})
|
||||||
self.response_model_model_Censures_get = api.model('CensuredInstances', {
|
self.response_model_model_Censures_get = api.model('CensuredInstances', {
|
||||||
|
@ -55,6 +56,7 @@ class Models:
|
||||||
})
|
})
|
||||||
self.input_censures_modify = api.model('ModifyCensure', {
|
self.input_censures_modify = api.model('ModifyCensure', {
|
||||||
'reason': fields.String(required=False, description="The reason for this censure. No profanity or hate speech allowed!", example="csam"),
|
'reason': fields.String(required=False, description="The reason for this censure. No profanity or hate speech allowed!", example="csam"),
|
||||||
|
'evidence': fields.String(required=False, description="The evidence for this censure. Typically URL but can be a long form of anything you feel appropriate.", example="https://link.to/your/evidence"),
|
||||||
})
|
})
|
||||||
self.response_model_api_key_reset = api.model('ApiKeyReset', {
|
self.response_model_api_key_reset = api.model('ApiKeyReset', {
|
||||||
"message": fields.String(default='OK',required=True, description="The result of this operation."),
|
"message": fields.String(default='OK',required=True, description="The result of this operation."),
|
||||||
|
|
|
@ -49,6 +49,7 @@ class CensuresGiven(Resource):
|
||||||
if skip_instance:
|
if skip_instance:
|
||||||
continue
|
continue
|
||||||
c_instance_details["censure_reasons"] = [censure.reason for censure in censures]
|
c_instance_details["censure_reasons"] = [censure.reason for censure in censures]
|
||||||
|
c_instance_details["censure_evidence"] = [censure.evidence for censure in censures if censure.evidence is not None]
|
||||||
c_instance_details["censure_count"] = censure_count
|
c_instance_details["censure_count"] = censure_count
|
||||||
instance_details.append(c_instance_details)
|
instance_details.append(c_instance_details)
|
||||||
if self.args.csv:
|
if self.args.csv:
|
||||||
|
@ -82,6 +83,7 @@ class Censures(Resource):
|
||||||
c_instance_details = c_instance.get_details()
|
c_instance_details = c_instance.get_details()
|
||||||
if len(censures) > 0:
|
if len(censures) > 0:
|
||||||
c_instance_details["censure_reasons"] = [censure.reason for censure in censures]
|
c_instance_details["censure_reasons"] = [censure.reason for censure in censures]
|
||||||
|
c_instance_details["censure_evidence"] = [censure.evidence for censure in censures if censure.evidence is not None]
|
||||||
instance_details.append(c_instance_details)
|
instance_details.append(c_instance_details)
|
||||||
if self.args.csv:
|
if self.args.csv:
|
||||||
return {"csv": ",".join([instance["domain"] for instance in instance_details])},200
|
return {"csv": ",".join([instance["domain"] for instance in instance_details])},200
|
||||||
|
@ -93,6 +95,7 @@ class Censures(Resource):
|
||||||
put_parser.add_argument("apikey", type=str, required=True, help="The sending instance's API key.", location='headers')
|
put_parser.add_argument("apikey", type=str, required=True, help="The sending instance's API key.", location='headers')
|
||||||
put_parser.add_argument("Client-Agent", default="unknown:0:unknown", type=str, required=False, help="The client name and version.", location="headers")
|
put_parser.add_argument("Client-Agent", default="unknown:0:unknown", type=str, required=False, help="The client name and version.", location="headers")
|
||||||
put_parser.add_argument("reason", default=None, type=str, required=False, location="json")
|
put_parser.add_argument("reason", default=None, type=str, required=False, location="json")
|
||||||
|
put_parser.add_argument("evidence", default=None, type=str, required=False, location="json")
|
||||||
|
|
||||||
|
|
||||||
@api.expect(put_parser,models.input_censures_modify, validate=True)
|
@api.expect(put_parser,models.input_censures_modify, validate=True)
|
||||||
|
@ -131,10 +134,14 @@ class Censures(Resource):
|
||||||
reason = self.args.reason
|
reason = self.args.reason
|
||||||
if reason is not None:
|
if reason is not None:
|
||||||
reason = sanitize_string(reason)
|
reason = sanitize_string(reason)
|
||||||
|
evidence = self.args.evidence
|
||||||
|
if evidence is not None:
|
||||||
|
evidence = sanitize_string(evidence)
|
||||||
new_censure = Censure(
|
new_censure = Censure(
|
||||||
censuring_id=instance.id,
|
censuring_id=instance.id,
|
||||||
censured_id=target_instance.id,
|
censured_id=target_instance.id,
|
||||||
reason=reason,
|
reason=reason,
|
||||||
|
evidence=evidence,
|
||||||
)
|
)
|
||||||
db.session.add(new_censure)
|
db.session.add(new_censure)
|
||||||
new_report = Report(
|
new_report = Report(
|
||||||
|
@ -153,6 +160,7 @@ class Censures(Resource):
|
||||||
patch_parser.add_argument("apikey", type=str, required=True, help="The sending instance's API key.", location='headers')
|
patch_parser.add_argument("apikey", type=str, required=True, help="The sending instance's API key.", location='headers')
|
||||||
patch_parser.add_argument("Client-Agent", default="unknown:0:unknown", type=str, required=False, help="The client name and version.", location="headers")
|
patch_parser.add_argument("Client-Agent", default="unknown:0:unknown", type=str, required=False, help="The client name and version.", location="headers")
|
||||||
patch_parser.add_argument("reason", default=None, type=str, required=False, location="json")
|
patch_parser.add_argument("reason", default=None, type=str, required=False, location="json")
|
||||||
|
patch_parser.add_argument("evidence", default=None, type=str, required=False, location="json")
|
||||||
|
|
||||||
|
|
||||||
@api.expect(patch_parser,models.input_censures_modify, validate=True)
|
@api.expect(patch_parser,models.input_censures_modify, validate=True)
|
||||||
|
@ -176,13 +184,21 @@ class Censures(Resource):
|
||||||
censure = database.get_censure(target_instance.id,instance.id)
|
censure = database.get_censure(target_instance.id,instance.id)
|
||||||
if not censure:
|
if not censure:
|
||||||
raise e.BadRequest(f"No censure found for {domain} from {instance.domain}")
|
raise e.BadRequest(f"No censure found for {domain} from {instance.domain}")
|
||||||
|
changed = False
|
||||||
reason = self.args.reason
|
reason = self.args.reason
|
||||||
if reason is not None:
|
if reason is not None:
|
||||||
reason = sanitize_string(reason)
|
reason = sanitize_string(reason)
|
||||||
logger.debug([censure.reason,reason])
|
if censure.reason != reason:
|
||||||
if censure.reason == reason:
|
|
||||||
return {"message":'OK'}, 200
|
|
||||||
censure.reason = reason
|
censure.reason = reason
|
||||||
|
changed = True
|
||||||
|
evidence = self.args.evidence
|
||||||
|
if evidence is not None:
|
||||||
|
evidence = sanitize_string(evidence)
|
||||||
|
if censure.evidence != evidence:
|
||||||
|
censure.evidence = evidence
|
||||||
|
changed = True
|
||||||
|
if changed is False:
|
||||||
|
return {"message":'OK'}, 200
|
||||||
new_report = Report(
|
new_report = Report(
|
||||||
source_domain=instance.domain,
|
source_domain=instance.domain,
|
||||||
target_domain=target_instance.domain,
|
target_domain=target_instance.domain,
|
||||||
|
|
|
@ -53,6 +53,7 @@ class Censure(db.Model):
|
||||||
__table_args__ = (UniqueConstraint('censuring_id', 'censured_id', name='censures_censuring_id_censured_id'),)
|
__table_args__ = (UniqueConstraint('censuring_id', 'censured_id', name='censures_censuring_id_censured_id'),)
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
reason = db.Column(db.String(255), unique=False, nullable=True, index=False)
|
reason = db.Column(db.String(255), unique=False, nullable=True, index=False)
|
||||||
|
evidence = db.Column(db.Text, unique=False, nullable=True, index=False)
|
||||||
censuring_id = db.Column(db.Integer, db.ForeignKey("instances.id", ondelete="CASCADE"), nullable=False)
|
censuring_id = db.Column(db.Integer, db.ForeignKey("instances.id", ondelete="CASCADE"), nullable=False)
|
||||||
censuring_instance = db.relationship("Instance", back_populates="censures_given", foreign_keys=[censuring_id])
|
censuring_instance = db.relationship("Instance", back_populates="censures_given", foreign_keys=[censuring_id])
|
||||||
censured_id = db.Column(db.Integer, db.ForeignKey("instances.id", ondelete="CASCADE"), nullable=False)
|
censured_id = db.Column(db.Integer, db.ForeignKey("instances.id", ondelete="CASCADE"), nullable=False)
|
||||||
|
|
|
@ -99,7 +99,10 @@ def get_all_censure_reasons_for_censured_id(censured_id, censuring_ids):
|
||||||
Censure.censured_id == censured_id,
|
Censure.censured_id == censured_id,
|
||||||
Censure.censuring_id.in_(censuring_ids),
|
Censure.censuring_id.in_(censuring_ids),
|
||||||
)
|
)
|
||||||
).with_entities(Censure.reason)
|
).with_entities(
|
||||||
|
Censure.reason,
|
||||||
|
Censure.evidence,
|
||||||
|
)
|
||||||
return query.all()
|
return query.all()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue