Skip to content

Commit

Permalink
Handle invalid icon in plugins list and details (qgis#425)
Browse files Browse the repository at this point in the history
* Handle invalid icon in plugins list and details

* Add sentry rate into the environment variable
  • Loading branch information
Xpirix authored Jun 17, 2024
1 parent 7ffcc82 commit 0635b62
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions dockerize/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ ENABLE_LDAP=False
# SENTRY
SENTRY_DSN=''

# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
SENTRY_RATE=1.0

# Download stats URL
METABASE_DOWNLOAD_STATS_URL='https://plugins.qgis.org/metabase/public/dashboard/<dashboard_id>'

Expand Down
1 change: 1 addition & 0 deletions dockerize/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ services:
- EMAIL_HOST_PASSWORD=${EMAIL_HOST_PASSWORD}
- DEFAULT_PLUGINS_SITE=${DEFAULT_PLUGINS_SITE:-https://plugins.qgis.org/}
- SENTRY_DSN=${SENTRY_DSN}
- SENTRY_RATE=${SENTRY_RATE}
volumes:
- ../qgis-app:/home/web/django_project
- ./docker/uwsgi.conf:/uwsgi.conf
Expand Down
4 changes: 3 additions & 1 deletion qgis-app/plugins/templates/plugins/plugin_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ <h2>
<div class="span12">
{% endif %}
<h2>{{ object.name }}
{% if object.icon and object.icon.file %}
{% if object.icon and object.icon.file and object.icon|is_image_valid %}
{% with image_extension=object.icon.name|file_extension %}
{% if image_extension == 'svg' %}
<img class="pull-right plugin-icon" alt="{% trans "Plugin icon" %}" src="{{ object.icon.url }}" width="24" height="24" />
Expand All @@ -154,6 +154,8 @@ <h2>{{ object.name }}
{% endthumbnail %}
{% endif %}
{% endwith %}
{% else %}
<img height="32" width="32" class="pull-right plugin-icon" src="{% static "images/qgis-icon-32x32.png" %}" alt="{% trans "Plugin icon" %}" />
{% endif %}
</h2>
<div>
Expand Down
2 changes: 1 addition & 1 deletion qgis-app/plugins/templates/plugins/plugin_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h2>{% if title %}{{title}}{% else %}{% trans "All plugins" %}{% endif %}</h2>
{% for object in object_list %}
<tr class="pmain {% if object.deprecated %} error deprecated{% endif %}" id="pmain{{object.pk}}">
<td><a title="{% if object.deprecated %} [DEPRECATED] {% endif %}{% trans "Click here for plugin details" %}" href="{% url "plugin_detail" object.package_name %}">
{% if object.icon and object.icon.file %}
{% if object.icon and object.icon.file and object.icon|is_image_valid %}
{% with image_extension=object.icon.name|file_extension %}
{% if image_extension == 'svg' %}
<img class="pull-right plugin-icon" alt="{% trans "Plugin icon" %}" src="{{ object.icon.url }}" width="24" height="24" />
Expand Down
14 changes: 13 additions & 1 deletion qgis-app/plugins/templatetags/plugin_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django import template
from PIL import Image, UnidentifiedImageError

register = template.Library()

Expand Down Expand Up @@ -27,4 +28,15 @@ def plugin_title(context):

@register.filter
def file_extension(value):
return value.split('.')[-1].lower()
return value.split('.')[-1].lower()

@register.filter
def is_image_valid(image):
if not image:
return False
try:
img = Image.open(image.path)
img.verify()
return True
except (FileNotFoundError, UnidentifiedImageError):
return False
3 changes: 2 additions & 1 deletion qgis-app/settings_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@

# Sentry
SENTRY_DSN = os.environ.get("SENTRY_DSN", "")
SENTRY_RATE = os.environ.get("SENTRY_RATE", 1.0)

if SENTRY_DSN and SENTRY_DSN != "":
import sentry_sdk
Expand All @@ -181,5 +182,5 @@
dsn=SENTRY_DSN,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
traces_sample_rate=1.0,
traces_sample_rate=SENTRY_RATE,
)

0 comments on commit 0635b62

Please sign in to comment.