From a22fad46cc1e9531bc5e813c4b306bd2186c4c22 Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Thu, 14 Dec 2023 11:03:17 +0300 Subject: [PATCH 1/7] Add plugin download event per country model --- REQUIREMENTS.txt | 1 + dockerize/docker/Dockerfile | 9 ++++++++ dockerize/docker/REQUIREMENTS.txt | 1 + dockerize/production/Dockerfile | 10 ++++++++ qgis-app/plugins/admin.py | 12 +++++++++- .../migrations/0005_plugindownloadevent.py | 23 +++++++++++++++++++ qgis-app/plugins/models.py | 11 +++++++++ qgis-app/plugins/tests/test_download.py | 20 +++++++++++++--- qgis-app/plugins/utils.py | 9 ++++++++ qgis-app/plugins/views.py | 18 ++++++++++++++- qgis-app/settings.py | 2 ++ qgis-app/settings_docker.py | 2 ++ 12 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 qgis-app/plugins/migrations/0005_plugindownloadevent.py diff --git a/REQUIREMENTS.txt b/REQUIREMENTS.txt index 6e4c7f04..9ef3cc4a 100644 --- a/REQUIREMENTS.txt +++ b/REQUIREMENTS.txt @@ -59,3 +59,4 @@ django-user-map djangorestframework==3.12.2 django-rest-auth==0.9.5 drf-yasg +geoip2==4.5.0 diff --git a/dockerize/docker/Dockerfile b/dockerize/docker/Dockerfile index 3bd21f73..2f1d85b8 100644 --- a/dockerize/docker/Dockerfile +++ b/dockerize/docker/Dockerfile @@ -10,10 +10,19 @@ RUN apt-get clean all RUN echo "deb http://archive.debian.org/debian stretch main contrib non-free" > /etc/apt/sources.list RUN apt-get update && apt-get install -y libsasl2-dev python-dev libldap2-dev libssl-dev +# Install C library for geoip2 +RUN apt-get install -y libmaxminddb0 libmaxminddb-dev mmdb-bin ADD REQUIREMENTS.txt /REQUIREMENTS.txt RUN pip install -r /REQUIREMENTS.txt RUN pip install uwsgi freezegun==1.3.1 +# GeoIp mmdb +RUN apt-get update && apt-get install -y curl && curl -LJO https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-City.mmdb && \ + mkdir /var/opt/maxmind && \ + mv GeoLite2-City.mmdb /var/opt/maxmind/GeoLite2-City.mmdb + +ENV GEOIP_PATH=/var/opt/maxmind/ + # https://docs.docker.com/examples/running_ssh_service/ # Sudo is needed by pycharm when it tries to pip install packages RUN apt-get install -y openssh-server sudo diff --git a/dockerize/docker/REQUIREMENTS.txt b/dockerize/docker/REQUIREMENTS.txt index 901d9427..774cd455 100644 --- a/dockerize/docker/REQUIREMENTS.txt +++ b/dockerize/docker/REQUIREMENTS.txt @@ -53,3 +53,4 @@ django-rest-multiple-models==2.1.3 django-preferences==1.0.0 PyWavefront==1.3.3 +geoip2==4.5.0 \ No newline at end of file diff --git a/dockerize/production/Dockerfile b/dockerize/production/Dockerfile index 7a57d864..040ea70f 100644 --- a/dockerize/production/Dockerfile +++ b/dockerize/production/Dockerfile @@ -13,12 +13,22 @@ RUN mkdir -p /usr/src; mkdir -p /home/web && \ rm -rf /home/web/django_project && \ ln -s /usr/src/plugins/qgis-app /home/web/django_project +# Install C library for geoip2 +RUN apt-get install -y libmaxminddb0 libmaxminddb-dev mmdb-bin + RUN cd /usr/src/plugins/dockerize/docker && \ pip install -r REQUIREMENTS.txt && \ pip install uwsgi && \ rm -rf /uwsgi.conf && \ ln -s ${PWD}/uwsgi.conf /uwsgi.conf +# GeoIp mmdb +RUN apt-get update && apt-get install -y curl && curl -LJO https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-City.mmdb && \ + mkdir /var/opt/maxmind && \ + mv GeoLite2-City.mmdb /var/opt/maxmind/GeoLite2-City.mmdb + +ENV GEOIP_PATH=/var/opt/maxmind/ + # Open port 8080 as we will be running our uwsgi socket on that EXPOSE 8080 diff --git a/qgis-app/plugins/admin.py b/qgis-app/plugins/admin.py index 81b5085d..5e14d9f4 100644 --- a/qgis-app/plugins/admin.py +++ b/qgis-app/plugins/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from plugins.models import Plugin, PluginVersion, PluginVersionDownload # , PluginCrashReport +from plugins.models import Plugin, PluginDownloadEvent, PluginVersion, PluginVersionDownload # , PluginCrashReport class PluginAdmin(admin.ModelAdmin): @@ -38,6 +38,15 @@ class PluginVersionDownloadAdmin(admin.ModelAdmin): "plugin_version", ) +class PluginDownloadEventAdmin(admin.ModelAdmin): + list_display = ( + "plugin_version", + "country_code", + "downloaded_on" + ) + raw_id_fields = ( + "plugin_version", + ) # class PluginCrashReportAdmin(admin.ModelAdmin): # pass @@ -45,4 +54,5 @@ class PluginVersionDownloadAdmin(admin.ModelAdmin): admin.site.register(Plugin, PluginAdmin) admin.site.register(PluginVersion, PluginVersionAdmin) admin.site.register(PluginVersionDownload, PluginVersionDownloadAdmin) +admin.site.register(PluginDownloadEvent, PluginDownloadEventAdmin) # admin.site.register(PluginCrashReport, PluginCrashReportAdmin) diff --git a/qgis-app/plugins/migrations/0005_plugindownloadevent.py b/qgis-app/plugins/migrations/0005_plugindownloadevent.py new file mode 100644 index 00000000..74829b86 --- /dev/null +++ b/qgis-app/plugins/migrations/0005_plugindownloadevent.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.25 on 2023-12-14 01:15 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('plugins', '0004_merge_20231122_0223'), + ] + + operations = [ + migrations.CreateModel( + name='PluginDownloadEvent', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('country_code', models.CharField(max_length=3)), + ('downloaded_on', models.DateTimeField(auto_now_add=True)), + ('plugin_version', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='plugins.PluginVersion')), + ], + ), + ] diff --git a/qgis-app/plugins/models.py b/qgis-app/plugins/models.py index eeba37d2..5d45f7b7 100644 --- a/qgis-app/plugins/models.py +++ b/qgis-app/plugins/models.py @@ -898,5 +898,16 @@ class Meta: ) +class PluginDownloadEvent(models.Model): + """ + Plugin version download per country + """ + plugin_version = models.ForeignKey(PluginVersion, on_delete=models.CASCADE) + country_code = models.CharField(max_length=3) + downloaded_on = models.DateTimeField( + auto_now_add=True, + editable=False + ) + models.signals.post_delete.connect(delete_version_package, sender=PluginVersion) models.signals.post_delete.connect(delete_plugin_icon, sender=Plugin) diff --git a/qgis-app/plugins/tests/test_download.py b/qgis-app/plugins/tests/test_download.py index f18f0874..5c37ea40 100644 --- a/qgis-app/plugins/tests/test_download.py +++ b/qgis-app/plugins/tests/test_download.py @@ -1,11 +1,11 @@ -from django.test import TestCase, RequestFactory +from django.test import Client, TestCase, RequestFactory from django.contrib.auth.models import User from django.utils import timezone from django.core.files.uploadedfile import SimpleUploadedFile -from plugins.models import Plugin, PluginVersion, PluginVersionDownload +from plugins.models import Plugin, PluginVersion, PluginVersionDownload, PluginDownloadEvent from plugins.views import version_download - +from django.urls import reverse class TestVersionDownloadView(TestCase): def setUp(self): @@ -50,3 +50,17 @@ def test_version_download(self): self.assertEqual(self.version.downloads, 1) self.assertEqual(self.plugin.downloads, 1) self.assertEqual(download_record.download_count, 1) + + def test_version_download_per_country(self): + download_url = reverse('version_download', args=[self.plugin.package_name, self.version.version]) + c = Client(REMOTE_ADDR='180.247.213.170') + response = c.get(download_url) + + self.version.refresh_from_db() + self.plugin.refresh_from_db() + download_event = PluginDownloadEvent.objects.get( + plugin_version=self.version + ) + + self.assertEqual(response.status_code, 200) + self.assertTrue(download_event.country_code == 'ID') \ No newline at end of file diff --git a/qgis-app/plugins/utils.py b/qgis-app/plugins/utils.py index e180e22b..521a5797 100644 --- a/qgis-app/plugins/utils.py +++ b/qgis-app/plugins/utils.py @@ -1,5 +1,6 @@ import requests import re +from django.http import HttpRequest def extract_version(tag): @@ -47,3 +48,11 @@ def get_qgis_versions(): if version not in all_versions: all_versions.append(version) return all_versions + + +def parse_remote_addr(request: HttpRequest) -> str: + """Extract client IP from request.""" + x_forwarded_for = request.headers.get("X-Forwarded-For", "") + if x_forwarded_for: + return x_forwarded_for.split(",")[0] + return request.META.get("REMOTE_ADDR", "") \ No newline at end of file diff --git a/qgis-app/plugins/views.py b/qgis-app/plugins/views.py index eeddbeba..8aaa8ade 100644 --- a/qgis-app/plugins/views.py +++ b/qgis-app/plugins/views.py @@ -30,8 +30,10 @@ # from sortable_listview import SortableListView from django.views.generic.list import ListView from plugins.forms import * -from plugins.models import Plugin, PluginVersion, PluginVersionDownload, vjust +from plugins.models import Plugin, PluginDownloadEvent, PluginVersion, PluginVersionDownload, vjust from plugins.validator import PLUGIN_REQUIRED_METADATA +from django.contrib.gis.geoip2 import GeoIP2 +from plugins.utils import parse_remote_addr try: from urllib import unquote, urlencode @@ -1254,6 +1256,20 @@ def version_download(request, package_name, version): ) download_record.save() + remote_addr = parse_remote_addr(request) + g = GeoIP2() + download_event = PluginDownloadEvent.objects.create( + plugin_version = version + ) + + if remote_addr: + try: + country_data = g.country(remote_addr) + download_event.country_code = country_data['country_code'] + except Exception as e: # AddressNotFoundErrors: + download_event.country_code = 'N/D' + download_event.save() + if not version.package.file.file.closed: version.package.file.file.close() zipfile = open(version.package.file.name, "rb") diff --git a/qgis-app/settings.py b/qgis-app/settings.py index 54d76a4a..2a0f4a50 100644 --- a/qgis-app/settings.py +++ b/qgis-app/settings.py @@ -329,3 +329,5 @@ RESULT_BACKEND = BROKER_URL CELERY_BROKER_URL = BROKER_URL CELERY_RESULT_BACKEND = CELERY_BROKER_URL + +GEOIP_PATH='/var/opt/maxmind/' \ No newline at end of file diff --git a/qgis-app/settings_docker.py b/qgis-app/settings_docker.py index afb1c9e9..f3a01d2d 100644 --- a/qgis-app/settings_docker.py +++ b/qgis-app/settings_docker.py @@ -120,3 +120,5 @@ REST_FRAMEWORK = { "TEST_REQUEST_DEFAULT_FORMAT": "json", } + +GEOIP_PATH='/var/opt/maxmind/' \ No newline at end of file From e94215395bd639d6a2cb06e76473e242ad717b52 Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Fri, 15 Dec 2023 08:49:27 +0300 Subject: [PATCH 2/7] Add country colums to PluginVersionDownload --- qgis-app/plugins/admin.py | 12 +------- .../migrations/0005_auto_20231214_2317.py | 23 ++++++++++++++ .../migrations/0005_plugindownloadevent.py | 23 -------------- qgis-app/plugins/models.py | 13 ++------ qgis-app/plugins/tests/test_download.py | 10 ++++--- qgis-app/plugins/views.py | 30 +++++++++---------- 6 files changed, 47 insertions(+), 64 deletions(-) create mode 100644 qgis-app/plugins/migrations/0005_auto_20231214_2317.py delete mode 100644 qgis-app/plugins/migrations/0005_plugindownloadevent.py diff --git a/qgis-app/plugins/admin.py b/qgis-app/plugins/admin.py index 5e14d9f4..81b5085d 100644 --- a/qgis-app/plugins/admin.py +++ b/qgis-app/plugins/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from plugins.models import Plugin, PluginDownloadEvent, PluginVersion, PluginVersionDownload # , PluginCrashReport +from plugins.models import Plugin, PluginVersion, PluginVersionDownload # , PluginCrashReport class PluginAdmin(admin.ModelAdmin): @@ -38,15 +38,6 @@ class PluginVersionDownloadAdmin(admin.ModelAdmin): "plugin_version", ) -class PluginDownloadEventAdmin(admin.ModelAdmin): - list_display = ( - "plugin_version", - "country_code", - "downloaded_on" - ) - raw_id_fields = ( - "plugin_version", - ) # class PluginCrashReportAdmin(admin.ModelAdmin): # pass @@ -54,5 +45,4 @@ class PluginDownloadEventAdmin(admin.ModelAdmin): admin.site.register(Plugin, PluginAdmin) admin.site.register(PluginVersion, PluginVersionAdmin) admin.site.register(PluginVersionDownload, PluginVersionDownloadAdmin) -admin.site.register(PluginDownloadEvent, PluginDownloadEventAdmin) # admin.site.register(PluginCrashReport, PluginCrashReportAdmin) diff --git a/qgis-app/plugins/migrations/0005_auto_20231214_2317.py b/qgis-app/plugins/migrations/0005_auto_20231214_2317.py new file mode 100644 index 00000000..8cd7045b --- /dev/null +++ b/qgis-app/plugins/migrations/0005_auto_20231214_2317.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.25 on 2023-12-14 23:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('plugins', '0004_merge_20231122_0223'), + ] + + operations = [ + migrations.AddField( + model_name='pluginversiondownload', + name='country_code', + field=models.CharField(default='N/D', max_length=3), + ), + migrations.AddField( + model_name='pluginversiondownload', + name='country_name', + field=models.CharField(default='N/D', max_length=100), + ), + ] diff --git a/qgis-app/plugins/migrations/0005_plugindownloadevent.py b/qgis-app/plugins/migrations/0005_plugindownloadevent.py deleted file mode 100644 index 74829b86..00000000 --- a/qgis-app/plugins/migrations/0005_plugindownloadevent.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 2.2.25 on 2023-12-14 01:15 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('plugins', '0004_merge_20231122_0223'), - ] - - operations = [ - migrations.CreateModel( - name='PluginDownloadEvent', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('country_code', models.CharField(max_length=3)), - ('downloaded_on', models.DateTimeField(auto_now_add=True)), - ('plugin_version', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='plugins.PluginVersion')), - ], - ), - ] diff --git a/qgis-app/plugins/models.py b/qgis-app/plugins/models.py index 5d45f7b7..3d6c36ed 100644 --- a/qgis-app/plugins/models.py +++ b/qgis-app/plugins/models.py @@ -888,6 +888,8 @@ class PluginVersionDownload(models.Model): download_date = models.DateField( default=timezone.now ) + country_code = models.CharField(max_length=3, default='N/D') + country_name = models.CharField(max_length=100, default='N/D') download_count = models.IntegerField( default=0 ) @@ -898,16 +900,5 @@ class Meta: ) -class PluginDownloadEvent(models.Model): - """ - Plugin version download per country - """ - plugin_version = models.ForeignKey(PluginVersion, on_delete=models.CASCADE) - country_code = models.CharField(max_length=3) - downloaded_on = models.DateTimeField( - auto_now_add=True, - editable=False - ) - models.signals.post_delete.connect(delete_version_package, sender=PluginVersion) models.signals.post_delete.connect(delete_plugin_icon, sender=Plugin) diff --git a/qgis-app/plugins/tests/test_download.py b/qgis-app/plugins/tests/test_download.py index 5c37ea40..34f204bd 100644 --- a/qgis-app/plugins/tests/test_download.py +++ b/qgis-app/plugins/tests/test_download.py @@ -3,7 +3,7 @@ from django.utils import timezone from django.core.files.uploadedfile import SimpleUploadedFile -from plugins.models import Plugin, PluginVersion, PluginVersionDownload, PluginDownloadEvent +from plugins.models import Plugin, PluginVersion, PluginVersionDownload from plugins.views import version_download from django.urls import reverse @@ -58,9 +58,11 @@ def test_version_download_per_country(self): self.version.refresh_from_db() self.plugin.refresh_from_db() - download_event = PluginDownloadEvent.objects.get( - plugin_version=self.version + download_record = PluginVersionDownload.objects.get( + plugin_version=self.version, + download_date=timezone.now().date() ) self.assertEqual(response.status_code, 200) - self.assertTrue(download_event.country_code == 'ID') \ No newline at end of file + self.assertTrue(download_record.country_code == 'ID') + self.assertTrue(download_record.country_name == 'Indonesia') \ No newline at end of file diff --git a/qgis-app/plugins/views.py b/qgis-app/plugins/views.py index 8aaa8ade..24cccef7 100644 --- a/qgis-app/plugins/views.py +++ b/qgis-app/plugins/views.py @@ -30,7 +30,7 @@ # from sortable_listview import SortableListView from django.views.generic.list import ListView from plugins.forms import * -from plugins.models import Plugin, PluginDownloadEvent, PluginVersion, PluginVersionDownload, vjust +from plugins.models import Plugin, PluginVersion, PluginVersionDownload, vjust from plugins.validator import PLUGIN_REQUIRED_METADATA from django.contrib.gis.geoip2 import GeoIP2 from plugins.utils import parse_remote_addr @@ -1245,8 +1245,22 @@ def version_download(request, package_name, version): plugin.downloads = plugin.downloads + 1 plugin.save(keep_date=True) + remote_addr = parse_remote_addr(request) + g = GeoIP2() + + if remote_addr: + try: + country_data = g.country(remote_addr) + country_code = country_data['country_code'] + country_name = country_data['country_name'] + except Exception as e: # AddressNotFoundErrors: + country_code = 'N/D' + country_name = 'N/D' + download_record, created = PluginVersionDownload.objects.get_or_create( plugin_version = version, + country_code = country_code, + country_name = country_name, download_date = now().date(), defaults = {'download_count': 1} ) @@ -1256,20 +1270,6 @@ def version_download(request, package_name, version): ) download_record.save() - remote_addr = parse_remote_addr(request) - g = GeoIP2() - download_event = PluginDownloadEvent.objects.create( - plugin_version = version - ) - - if remote_addr: - try: - country_data = g.country(remote_addr) - download_event.country_code = country_data['country_code'] - except Exception as e: # AddressNotFoundErrors: - download_event.country_code = 'N/D' - download_event.save() - if not version.package.file.file.closed: version.package.file.file.close() zipfile = open(version.package.file.name, "rb") From 5bd44bcd19fd665361e45522bf520e4b15699c97 Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Fri, 15 Dec 2023 10:47:45 +0300 Subject: [PATCH 3/7] Add the stats to the plugin page --- qgis-app/plugins/templates/plugins/plugin_detail.html | 10 ++++++++++ qgis-app/plugins/views.py | 2 ++ qgis-app/settings_docker.py | 6 +++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/qgis-app/plugins/templates/plugins/plugin_detail.html b/qgis-app/plugins/templates/plugins/plugin_detail.html index db7468c9..09b7a8bf 100644 --- a/qgis-app/plugins/templates/plugins/plugin_detail.html +++ b/qgis-app/plugins/templates/plugins/plugin_detail.html @@ -140,6 +140,7 @@

{{ object.name }}
  • {% trans "Versions" %}
  • {% if user.is_staff or user in object.editors %}
  • {% trans "Manage" %}
  • +
  • {% trans "Stats" %}
  • {% endif %} @@ -274,6 +275,15 @@

    {{ object.name }} +
    + +
    {% endif %} {# end admin #} diff --git a/qgis-app/plugins/views.py b/qgis-app/plugins/views.py index 24cccef7..d5cf21d0 100644 --- a/qgis-app/plugins/views.py +++ b/qgis-app/plugins/views.py @@ -518,8 +518,10 @@ def get_context_data(self, **kwargs): "%s metadata is missing, this metadata entry is required. Please add %s to metadata.txt." ) % (md, md) messages.error(self.request, msg, fail_silently=True) + stats_url = f"{settings.METABASE_DASHBOARD_URL}?package_name={plugin.package_name}#hide_parameters=package_name" context.update( { + "stats_url": stats_url, "rating": int(plugin.rating.get_rating()), "votes": plugin.rating.votes, } diff --git a/qgis-app/settings_docker.py b/qgis-app/settings_docker.py index f3a01d2d..0df4d1ed 100644 --- a/qgis-app/settings_docker.py +++ b/qgis-app/settings_docker.py @@ -121,4 +121,8 @@ "TEST_REQUEST_DEFAULT_FORMAT": "json", } -GEOIP_PATH='/var/opt/maxmind/' \ No newline at end of file +GEOIP_PATH='/var/opt/maxmind/' +METABASE_DASHBOARD_URL = os.environ.get( + "METABASE_DASHBOARD_URL", + "http://localhost:3000/public/dashboard/1d6c60d7-f855-40c3-a54c-06ba7f6c992a" +) \ No newline at end of file From 525c89e89f3ff7cf847a4d5d8684d76bd3eed564 Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Tue, 14 May 2024 10:08:06 +0300 Subject: [PATCH 4/7] Fix dockerfile --- dockerize/docker/Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/dockerize/docker/Dockerfile b/dockerize/docker/Dockerfile index 90cf705b..b635df70 100644 --- a/dockerize/docker/Dockerfile +++ b/dockerize/docker/Dockerfile @@ -24,11 +24,8 @@ RUN apt-get update && apt-get install -y curl && curl -LJO https://github.com/P3 mkdir /var/opt/maxmind && \ mv GeoLite2-City.mmdb /var/opt/maxmind/GeoLite2-City.mmdb -ADD REQUIREMENTS.txt /REQUIREMENTS.txt -RUN pip install -r /REQUIREMENTS.txt -RUN pip install uwsgi freezegun==1.3.1 - ENV GEOIP_PATH=/var/opt/maxmind/ + RUN rm -rf /uwsgi.conf ADD dockerize/docker/uwsgi.conf /uwsgi.conf ADD qgis-app /home/web/django_project From 2fb1a22895cc9de73322811db6ece095d1eb7190 Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Tue, 21 May 2024 13:30:55 +0300 Subject: [PATCH 5/7] Add stats url to the env variables --- dockerize/docker-compose.yml | 5 +++++ .../plugins/migrations/0010_merge_20240517_0729.py | 14 ++++++++++++++ qgis-app/plugins/views.py | 2 +- qgis-app/settings_docker.py | 6 +++--- 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 qgis-app/plugins/migrations/0010_merge_20240517_0729.py diff --git a/dockerize/docker-compose.yml b/dockerize/docker-compose.yml index 3b7c89db..dddecb09 100644 --- a/dockerize/docker-compose.yml +++ b/dockerize/docker-compose.yml @@ -44,6 +44,7 @@ services: - ENABLE_LDAP=${ENABLE_LDAP:-False} - RABBITMQ_HOST=${RABBITMQ_HOST:-rabbitmq} - BROKER_URL=amqp://rabbitmq:5672 + - METABASE_DOWNLOAD_STATS_URL=${METABASE_DOWNLOAD_STATS_URL:-/metabase} - EMAIL_BACKEND=${EMAIL_BACKEND} - EMAIL_HOST=${EMAIL_HOST} - EMAIL_PORT=${EMAIL_PORT} @@ -51,6 +52,7 @@ services: - EMAIL_HOST_USER=${EMAIL_HOST_USER:-automation} - EMAIL_HOST_PASSWORD=${EMAIL_HOST_PASSWORD} - DEFAULT_PLUGINS_SITE=${DEFAULT_PLUGINS_SITE:-https://plugins.qgis.org/} + volumes: - ../qgis-app:/home/web/django_project - ./docker/uwsgi.conf:/uwsgi.conf @@ -159,10 +161,13 @@ services: environment: - MB_DB_TYPE=postgres - MB_DB_CONNECTION_URI=jdbc:postgresql://${DATABASE_HOST:-db}:5432/metabase?user=${DATABASE_USERNAME:-docker}&password=${DATABASE_PASSWORD:-docker} + # - MB_DB_USER=tim@kartoza.com + # - MB_DB_PASS=newpassword links: - db expose: - "3000" + # command: bash -c 'java -jar app/metabase.jar reset-password tim@kartoza.com' certbot: image: certbot/certbot diff --git a/qgis-app/plugins/migrations/0010_merge_20240517_0729.py b/qgis-app/plugins/migrations/0010_merge_20240517_0729.py new file mode 100644 index 00000000..54355764 --- /dev/null +++ b/qgis-app/plugins/migrations/0010_merge_20240517_0729.py @@ -0,0 +1,14 @@ +# Generated by Django 4.2.13 on 2024-05-17 07:29 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('plugins', '0005_auto_20231214_2317'), + ('plugins', '0009_merge_20240321_0207'), + ] + + operations = [ + ] diff --git a/qgis-app/plugins/views.py b/qgis-app/plugins/views.py index 2d003cb6..9f8766a4 100644 --- a/qgis-app/plugins/views.py +++ b/qgis-app/plugins/views.py @@ -545,7 +545,7 @@ def get_context_data(self, **kwargs): "%s metadata is missing, this metadata entry is required. Please add %s to metadata.txt." ) % (md, md) messages.error(self.request, msg, fail_silently=True) - stats_url = f"{settings.METABASE_DASHBOARD_URL}?package_name={plugin.package_name}#hide_parameters=package_name" + stats_url = f"{settings.METABASE_DOWNLOAD_STATS_URL}?package_name={plugin.package_name}#hide_parameters=package_name" context.update( { "stats_url": stats_url, diff --git a/qgis-app/settings_docker.py b/qgis-app/settings_docker.py index 22d01068..9d8fcacf 100644 --- a/qgis-app/settings_docker.py +++ b/qgis-app/settings_docker.py @@ -135,9 +135,9 @@ } GEOIP_PATH='/var/opt/maxmind/' -METABASE_DASHBOARD_URL = os.environ.get( - "METABASE_DASHBOARD_URL", - "http://localhost:3000/public/dashboard/1d6c60d7-f855-40c3-a54c-06ba7f6c992a" +METABASE_DOWNLOAD_STATS_URL = os.environ.get( + "METABASE_DOWNLOAD_STATS_URL", + "/metabase" ) CELERY_RESULT_BACKEND = 'rpc://' CELERY_BROKER_URL = os.environ.get('BROKER_URL', 'amqp://rabbitmq:5672') From 2ac077745c40ac79a4217e8f094ee6610c5d9ece Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Tue, 21 May 2024 15:59:18 +0300 Subject: [PATCH 6/7] Fix docker-compose.yml --- dockerize/docker-compose.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/dockerize/docker-compose.yml b/dockerize/docker-compose.yml index dddecb09..cff6f3f0 100644 --- a/dockerize/docker-compose.yml +++ b/dockerize/docker-compose.yml @@ -161,13 +161,10 @@ services: environment: - MB_DB_TYPE=postgres - MB_DB_CONNECTION_URI=jdbc:postgresql://${DATABASE_HOST:-db}:5432/metabase?user=${DATABASE_USERNAME:-docker}&password=${DATABASE_PASSWORD:-docker} - # - MB_DB_USER=tim@kartoza.com - # - MB_DB_PASS=newpassword links: - db expose: - "3000" - # command: bash -c 'java -jar app/metabase.jar reset-password tim@kartoza.com' certbot: image: certbot/certbot From 51627f0345a2aee4c2a5ca8021f200d486419a67 Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Tue, 21 May 2024 18:43:55 +0300 Subject: [PATCH 7/7] Update env template file --- dockerize/.env.template | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dockerize/.env.template b/dockerize/.env.template index 43f8d6bb..38d4ca75 100644 --- a/dockerize/.env.template +++ b/dockerize/.env.template @@ -31,4 +31,7 @@ DEFAULT_PLUGINS_SITE='https://plugins.qgis.org/' QGISPLUGINS_ENV=debug # Ldap -ENABLE_LDAP=True \ No newline at end of file +ENABLE_LDAP=True + +# Download stats URL +METABASE_DOWNLOAD_STATS_URL='https://plugins.qgis.org/metabase/public/dashboard/' \ No newline at end of file