Skip to content

Commit

Permalink
Staff: show spam info (#362)
Browse files Browse the repository at this point in the history
* Staff: show spam info

Allow us to quickly know the spam score of the project and what are their
matching rules.

* Add rule description

* Use a modal to show debug information

* HTML layout

* Feedback from review

* Remove tooltip since it doesn't work
  • Loading branch information
humitos authored Jun 10, 2024
1 parent 0026e37 commit 74ba2e5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
47 changes: 46 additions & 1 deletion readthedocsext/theme/templates/projects/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% load privacy_tags %}
{% load core_tags %}
{% load gravatar %}
{% load ext_theme_tags %}

{% comment %}

Expand Down Expand Up @@ -167,7 +168,6 @@
</a>
{% endif %}
{% endblock project_header_repository %}

</div>
{% endblock project_header_metadata_right %}

Expand All @@ -188,13 +188,58 @@
</a>
{% if request.user|is_admin:project %}
<div class="right menu">
{% if user.is_staff %}
<a class="item" data-bind="click: $root.show_modal('project-debug')">
<i class="fa-duotone fa-microscope icon"></i>
{% trans "Debug" %}
</a>
{% endif %}
<a class="item {{ edit_active }}" href="{% url "projects_edit" project.slug %}">
<i class="fa-duotone fa-gears icon"></i>
{% trans "Settings" %}
</a>
</div>
{% endif %}
</div>


<div class="ui mini modal" data-modal-id="project-debug">
<div class="header">
{% trans "Debug information" %}
</div>
{% comment %}
Show spam information on community instance.
Allows us to quickly understand what's the spam score,
and also know what rules are matching this project.
{% endcomment %}
<div class="content">
{% if not USE_ORGANIZATIONS %}
<h3>{% trans "Spam" %}</h3>
<div class="ui sub header">
{% trans "Spam score" %}
</div>
<span>{{ project|get_spam_score }} </span>
{% if project.spam_rules.exists %}
<div class="ui sub header">
{% trans "Spam matching rules" %}
</div>
<div class="ui vertical list">
{% for rule in project.spam_rules.all %}
<div class="item">
<a href="{{ ADMIN_URL }}/spamfighting/spamrule/{{ rule.pk }}/change/"
target="_blank">
{{ rule.spam_rule_type|cut:"readthedocsext.spamfighting.rules." }}
</a>
</div>
{% endfor %}
</div>
{% endif %}
{% endif %}
</div>
<div class="actions">
<a href="#" class="ui negative button">{% trans "Close" %}</a>
</div>
</div>
{% endblock project_header_navigation %}

{% endblock project_header %}
10 changes: 10 additions & 0 deletions readthedocsext/theme/templatetags/ext_theme_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,13 @@ def get_account_username(socialaccount):
provider = socialaccount.get_provider()
extra_fields = provider.extract_common_fields(socialaccount.extra_data)
return extra_fields.get("username") or extra_fields.get("email")


@register.filter
def get_spam_score(project):
try:
from readthedocsext.spamfighting.utils import spam_score
except ImportError:
return 0

return spam_score(project)

0 comments on commit 74ba2e5

Please sign in to comment.