feat: Show visibilities

pull/32/head
db0 2023-09-18 15:55:24 +02:00
parent b0937782a8
commit 7678fe8294
5 changed files with 20 additions and 6 deletions

View File

@ -1,5 +1,10 @@
# Changelog
# 0.16.1
* Fix bug not returning reasons when seeing which instances censured/endorsed/hesitatated against a specific instance
* Whitelist endpoints now will return the visibility of an instance's lists
# 0.16.0
Allows instances to control the visibility of their endorsements, censures and hesitations by setting their visibility in PATCHing `api/b1/whitelist`

View File

@ -39,8 +39,13 @@ class Models:
'sysadmins': fields.Integer(required=False, default=None, description="The count of system administrators in this instance as reported by its admins."),
'moderators': fields.Integer(required=False, default=None, description="The count of community moderators in this instance as reported by its admins."),
})
self.response_model_instances_visibility = api.inherit('InstanceVisibilityDetails', self.response_model_instances, {
'visibility_endorsements': fields.String(required=True, enum=[e.name for e in enums.ListVisibility], description="If OPEN, this instance allows anyone to read this instance's endorsements. When set to ENDORSED, only endorsed instances can see their endorsements. If set to PRIVATE allow this instance's own admins can see their endorsements."),
'visibility_censures': fields.String(required=True, enum=[e.name for e in enums.ListVisibility], description="If OPEN, this instance allows anyone to read this instance's censures. When set to ENDORSED, only endorsed instances can see their censures. If set to PRIVATE allow this instance's own admins can see their censures."),
'visibility_hesitations': fields.String(required=True, enum=[e.name for e in enums.ListVisibility], description="If OPEN, this instance allows anyone to read this instance's hesitations. When set to ENDORSED, only endorsed instances can see their hesitations. If set to PRIVATE allow this instance's own admins can see their hesitations."),
})
self.response_model_model_Whitelist_get = api.model('WhitelistedInstances', {
'instances': fields.List(fields.Nested(self.response_model_instances)),
'instances': fields.List(fields.Nested(self.response_model_instances_visibility)),
'domains': fields.List(fields.String(description="The instance domains as a list.")),
'csv': fields.String(description="The instance domains as a csv."),
})

View File

@ -22,7 +22,7 @@ class Whitelist(Resource):
self.args = self.get_parser.parse_args()
instance_details = []
for instance in database.get_all_instances(self.args.endorsements,self.args.guarantors):
instance_details.append(instance.get_details())
instance_details.append(instance.get_details(show_visibilities=True))
if self.args.csv:
return {"csv": ",".join([instance["domain"] for instance in instance_details])},200
if self.args.domains:
@ -37,7 +37,7 @@ class WhitelistDomain(Resource):
@api.expect(get_parser)
@cache.cached(timeout=10, query_string=True)
@api.marshal_with(models.response_model_instances, code=200, description='Instances')
@api.marshal_with(models.response_model_instances_visibility, code=200, description='Instances')
def get(self, domain):
'''Display info about a specific instance
'''
@ -45,7 +45,7 @@ class WhitelistDomain(Resource):
instance, nodeinfo, admin_usernames = ensure_instance_registered(domain)
if not instance:
raise e.NotFound(f"Something went wrong trying to register this instance.")
return instance.get_details(),200
return instance.get_details(show_visibilities=True),200
put_parser = reqparse.RequestParser()

View File

@ -122,7 +122,7 @@ class Instance(db.Model):
db.session.add(self)
db.session.commit()
def get_details(self):
def get_details(self,show_visibilities=False):
ret_dict = {
"id": self.id,
"domain": self.domain,
@ -136,6 +136,10 @@ class Instance(db.Model):
"sysadmins": self.sysadmins,
"moderators": self.moderators,
}
if show_visibilities:
ret_dict["visibility_endorsements"] = self.visibility_endorsements.name
ret_dict["visibility_censures"] = self.visibility_censures.name
ret_dict["visibility_hesitations"] = self.visibility_hesitations.name
return ret_dict

View File

@ -1,4 +1,4 @@
FEDISEER_VERSION = "0.16.0"
FEDISEER_VERSION = "0.16.1"
SUPPORTED_SOFTWARE = {
"lemmy",
"mastodon",