From 46181dfd9aeec4f1482bbb54b144f26ccbfa73c5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 1 Jul 2023 06:25:34 +0200 Subject: [PATCH] Continued: - update 'nsfw' to 'media_nsfw': UPDATE blocks SET block_level='media_nsfw' WHERE block_level='nsfw'; - don't allow block_level='nsfw' --- fba/models/blocks.py | 8 ++++---- fba/networks/pleroma.py | 9 +++++---- fba/utils.py | 3 +++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/fba/models/blocks.py b/fba/models/blocks.py index ec4fed2..a439084 100644 --- a/fba/models/blocks.py +++ b/fba/models/blocks.py @@ -47,7 +47,7 @@ def update_reason(reason: str, blocker: str, blocked: str, block_level: str): raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not 'str'") elif block_level == "": raise ValueError("Parameter 'block_level' is empty") - elif block_level in ["accept", "suspend", "silence"]: + elif block_level in ["accept", "suspend", "silence", "nsfw"]: raise ValueError(f"block_level='{block_level}' is not wanted.") logger.debug("Updating block reason='%s',blocker='%s',blocked='%s',block_level='%s'", reason, blocker, blocked, block_level) @@ -81,7 +81,7 @@ def update_last_seen(blocker: str, blocked: str, block_level: str): raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not 'str'") elif block_level == "": raise ValueError("Parameter 'block_level' is empty") - elif block_level in ["accept", "suspend", "silence"]: + elif block_level in ["accept", "suspend", "silence", "nsfw"]: raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'") database.cursor.execute( @@ -113,7 +113,7 @@ def is_instance_blocked(blocker: str, blocked: str, block_level: str = None) -> raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'") elif block_level == "": raise ValueError("Parameter 'block_level' is empty") - elif block_level in ["accept", "suspend", "silence"]: + elif block_level in ["accept", "suspend", "silence", "nsfw"]: raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'") if block_level is None: @@ -152,7 +152,7 @@ def add_instance(blocker: str, blocked: str, reason: str, block_level: str): raise Exception(f"blocker='{blocker}' is blacklisted but function invoked") elif blacklist.is_blacklisted(blocked): raise Exception(f"blocked='{blocked}' is blacklisted but function invoked") - elif block_level in ["accept", "suspend", "silence"]: + elif block_level in ["accept", "suspend", "silence", "nsfw"]: raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'") if reason is not None: diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index 42ec809..82d3e4e 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -41,12 +41,12 @@ language_mapping = { "followers-only" : "followers_only", "media removal" : "media_removal", "media_removal" : "media_removal", - "media force-set as sensitive": "nsfw", - "nsfw" : "nsfw", + "media force-set as sensitive": "media_nsfw", + "nsfw" : "media_nsfw", "reject" : "reject", "suspended servers": "reject", "silenced servers" : "silenced", - "removal from \"the whole known network\" timeline": " federated_timeline_removal", + "removal from \"the whole known network\" timeline": "federated_timeline_removal", } def fetch_blocks(domain: str, nodeinfo_url: str) -> list: @@ -349,8 +349,9 @@ def fetch_blocks_from_about(domain: str) -> dict: "filtered_media": [], "followers_only": [], "silenced" : [], - "nsfw" : [], + "media_nsfw" : [], "media_removal" : [], + "federated_timeline_removal": [], } logger.debug("doc[]='%s'", type(doc)) diff --git a/fba/utils.py b/fba/utils.py index 5d794ff..1775353 100644 --- a/fba/utils.py +++ b/fba/utils.py @@ -258,6 +258,9 @@ def alias_block_level(block_level: str) -> str: elif block_level == "suspend": logger.debug("Block level 'suspend' has been changed to 'suspended'") block_level = "suspended" + elif block_level == "nsfw": + logger.debug("Block level 'nsfw' has been changed to 'media_nsfw'") + block_level = "media_nsfw" logger.debug("block_level='%s' - EXIT!", block_level) return block_level -- 2.39.5