Skip to content

Commit

Permalink
moderation: added rule for excessive header tags
Browse files Browse the repository at this point in the history
  • Loading branch information
0einstein0 authored and slint committed Nov 6, 2024
1 parent 1fac29c commit a6e1e5b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion site/zenodo_rdm/moderation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"ham_link": -3,
"excess_links": 5,
"spam_emoji": 5,
"spam_header_tags": 2,
"spam_files": 2,
"ham_files": -5,
"unverified_user": 10,
Expand All @@ -37,7 +38,7 @@
MODERATION_MIN_HAM_FILE_SIZE = 15_000_000 # 15MB
"""Minimum file size for ham files."""

MODERATION_SPAM_FILE_EXTS = {"jpg", "jpeg", "pdf", "png", "jfif"}
MODERATION_SPAM_FILE_EXTS = {"jpg", "jpeg", "pdf", "png", "jfif", "docx", "webp"}
"""Frequest spam file extensions."""

MODERATION_RECORD_SCORE_RULES = [
Expand Down
14 changes: 12 additions & 2 deletions site/zenodo_rdm/moderation/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,18 @@ def links_rule(identity, draft=None, record=None):


def text_sanitization_rule(identity, draft=None, record=None):
"""Calculate a score for excessive emoji usage in metadata text."""
"""Calculate a score based on excessive emoji and HTML tag usage in metadata text."""
record_text = " ".join(map(str, record.metadata.values()))
return current_scores.spam_emoji if len(extract_emojis(record_text)) > 3 else 0
htag_count = len(re.findall(r"<h[1-9]\b[^>]*>", record_text, re.IGNORECASE))
score = 0

if len(extract_emojis(record_text)) > 3:
score += current_scores.spam_emoji

if htag_count > 4:
score += current_scores.spam_header_tags

return score


def verified_user_rule(identity, draft=None, record=None):
Expand Down Expand Up @@ -106,6 +115,7 @@ def files_rule(identity, draft=None, record=None):
spam_exts = len(
exts.intersection(current_app.config.get("MODERATION_SPAM_FILE_EXTS"))
)

if files_count <= 4 and data_size < max_spam_file_size and spam_exts > 0:
score += current_scores.spam_files

Expand Down

0 comments on commit a6e1e5b

Please sign in to comment.