Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for new plugin metadata keywords #484

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
run: |
docker compose exec -T devweb bash -c '
set -e # Exit immediately if any command fails
pip install pycountry~=24.6 &&
python manage.py makemigrations &&
python manage.py migrate &&
python manage.py test
Expand Down
2 changes: 2 additions & 0 deletions dockerize/docker/REQUIREMENTS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ uwsgi~=2.0
freezegun~=1.4

sentry-sdk~=2.2

pycountry~=24.6
4 changes: 3 additions & 1 deletion qgis-app/REQUIREMENTS_plugins.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ django-matomo==0.1.6
uwsgi~=2.0
freezegun~=1.4

sentry-sdk~=2.2
sentry-sdk~=2.2

pycountry~=24.6
34 changes: 34 additions & 0 deletions qgis-app/plugins/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"""
import codecs
import configparser
import locale
import mimetypes
import os
import pycountry
import re
import zipfile
from io import StringIO
Expand Down Expand Up @@ -46,6 +48,10 @@
"experimental",
"external_deps",
"server",
"payment",
"authentication",
"countries",
"languages",
),
)
PLUGIN_BOOLEAN_METADATA = getattr(
Expand Down Expand Up @@ -368,6 +374,34 @@ def validator(package):
if not re.match(r"^[^/]+$", dict(metadata)["author"]):
raise ValidationError(_("Author name cannot contain slashes."))

# Check payment
if "payment" in dict(metadata):
value = dict(metadata)["payment"].strip().lower()
if value not in ("true", "1", "false", "0", "partial"):
raise ValidationError(_("payment should be one of True, False or Partial"))

# Check authentication
if "authentication" in dict(metadata):
value = dict(metadata)["authentication"].strip().lower()
if value not in ("true", "1", "false", "0", "partial"):
raise ValidationError(_("authentication should be one of True, False or Partial"))

# Check countries
if "countries" in dict(metadata):
values = dict(metadata)["countries"].strip().lower().split(',')
known_countries = [x.alpha_2.lower() for x in pycountry.countries]
for value in values:
if value not in known_countries:
raise ValidationError(_("Country %s is unknown. Accepted values are %s") % (value, ",".join(known_countries)))

# Check languages
if "languages" in dict(metadata):
values = dict(metadata)["languages"].strip().split(',')
known_locales = [x[0] for x in locale.locale_alias.items()]
for value in values:
if value not in known_locales:
raise ValidationError(_("Language %s is unknown. Accepted values are %s") % (value, ",".join(known_locales)))

# strip and check
checked_metadata = []
for k, v in metadata:
Expand Down