Skip to content

Commit

Permalink
[Fixes #6918] Removal of QGIS support (#6919)
Browse files Browse the repository at this point in the history
* [Cleanup and Refactor] Remove QGIS server backend dependencies

* [Cleanup and Refactor] Remove QGIS server backend dependencies

* - Fix LGTM issues
  • Loading branch information
Alessio Fabiani committed Feb 3, 2021
1 parent 9f49bd3 commit 30c1453
Show file tree
Hide file tree
Showing 77 changed files with 103 additions and 7,813 deletions.
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
geonode/uploaded
geonode/qgis_layer
geonode/qgis_tiles
geonode/static_root
geonode/static/.components
geonode/static/node_modules
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ geonode/local_settings.py

# Uploaded files
geonode/uploaded
geonode/qgis_layer
geonode/qgis_tiles

#Testing output
.coverage
Expand Down
60 changes: 0 additions & 60 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,40 +71,6 @@ jobs:
- MONITORING_ENABLED: 'False'
- SESSION_EXPIRED_CONTROL_ENABLED: 'True'

- stage: unit-tests
name: "QGis Server-backend Core Modules Smoke Tests"
virtualenv:
system_site_packages: false
env:
- BACKEND: 'geonode.qgis_server'
- DJANGO_SETTINGS_MODULE: 'geonode.local_settings'
- DOCKER_COMPOSE_VERSION: 1.19.0
- QGIS_SERVER_URL: http://localhost:9000/
- SITEURL: http://localhost:8000/
- QGIS_SERVER_PORT: 9000
- ON_TRAVIS: 'True'
- TEST_RUN_CORE: 'True'
- MONITORING_ENABLED: 'False'
- SESSION_EXPIRED_CONTROL_ENABLED: 'True'
- CELERY_ALWAYS_EAGER: 'True'

- stage: unit-tests
name: "QGis Server-backend Contrib Apps Smoke Tests"
virtualenv:
system_site_packages: false
env:
- BACKEND: 'geonode.qgis_server'
- DJANGO_SETTINGS_MODULE: 'geonode.local_settings'
- DOCKER_COMPOSE_VERSION: 1.19.0
- QGIS_SERVER_URL: http://localhost:9000/
- SITEURL: http://localhost:8000/
- QGIS_SERVER_PORT: 9000
- ON_TRAVIS: 'True'
- TEST_RUN_INTERNAL_APPS: 'True'
- MONITORING_ENABLED: 'False'
- SESSION_EXPIRED_CONTROL_ENABLED: 'True'
- CELERY_ALWAYS_EAGER: 'True'

- stage: integration-tests
name: "Backend Integration Tests"
virtualenv:
Expand Down Expand Up @@ -150,27 +116,6 @@ jobs:
- GEODATABASE_URL: 'postgis://geonode:geonode@localhost:5432/upload_test'
- DEFAULT_BACKEND_DATASTORE: 'datastore'

- stage: integration-tests
name: "QGis Server Integration Tests"
virtualenv:
system_site_packages: false
env:
- BACKEND: 'geonode.qgis_server'
- DJANGO_SETTINGS_MODULE: 'geonode.local_settings'
- DOCKER_COMPOSE_VERSION: 1.19.0
- QGIS_SERVER_URL: http://localhost:9000/
- SITEURL: http://localhost:8000/
- QGIS_SERVER_PORT: 9000
- ON_TRAVIS: 'True'
- TEST_RUNNER_KEEPDB: 'True'
- TEST_RUN_INTEGRATION: 'True'
- TEST_RUN_INTEGRATION_SERVER: 'True'
- MONITORING_ENABLED: 'False'
- SESSION_EXPIRED_CONTROL_ENABLED: 'True'
- CELERY_ALWAYS_EAGER: 'True'
- DATABASE_URL: 'postgis://geonode:geonode@localhost:5432/upload_test'
- GEONODE_CLIENT_LAYER_PREVIEW_LIBRARY: 'leaflet'

- stage: frontend-tests
name: "BDD Tests"
virtualenv:
Expand Down Expand Up @@ -215,7 +160,6 @@ before_install:
sudo apt-get update;
mkdir -p $HOME/buildout-cache/{eggs,downloads};
scripts/misc/geoserver_server_setup.sh before_install;
scripts/misc/qgis_server_setup.sh before_install;
sudo apt-get autoremove sqlite3;
sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/12/main/postgresql.conf;
sudo sed -i 's/peer/trust/' /etc/postgresql/12/main/pg_hba.conf;
Expand Down Expand Up @@ -268,8 +212,6 @@ before_script:
scripts/misc/create_dbs_travis.sh before_script;
echo "For GeoServer Server Travis steps";
scripts/misc/geoserver_server_setup.sh before_script;
echo "For QGIS Server Travis steps";
scripts/misc/qgis_server_setup.sh before_script;
echo "Start NGINX server";
sudo nginx -s stop;
sudo nginx -c `pwd`/scripts/misc/nginx_integration.conf;
Expand All @@ -296,8 +238,6 @@ after_script:
else
echo "For GeoServer Server Travis steps";
scripts/misc/geoserver_server_setup.sh after_script;
echo "For QGIS Server Travis steps";
scripts/misc/qgis_server_setup.sh after_script;
echo "Stop NGINX server";
sudo nginx -c `pwd`/scripts/misc/nginx_integration.conf -s stop;
echo "Cleanup";
Expand Down
22 changes: 0 additions & 22 deletions docker-compose-qgis-server.yml

This file was deleted.

185 changes: 2 additions & 183 deletions geonode/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,14 @@
from django.contrib.contenttypes.models import ContentType
from django.conf import settings
from django.db.models import Count
from django.http.response import HttpResponse
from django.template.response import TemplateResponse
from django.utils.translation import get_language

from avatar.templatetags.avatar_tags import avatar_url
from tastypie import http
from tastypie.exceptions import BadRequest

from geonode import qgis_server, geoserver
from geonode import geoserver
from geonode.api.paginator import CrossSiteXHRPaginator
from geonode.api.authorization import GeoNodeStyleAuthorization, ApiLockdownAuthorization, \
GroupAuthorization, GroupProfileAuthorization
from geonode.qgis_server.models import QGISServerStyle
from guardian.shortcuts import get_objects_for_user
from tastypie.bundle import Bundle

Expand Down Expand Up @@ -600,178 +595,6 @@ class Meta:
authorization = ApiLockdownAuthorization()


class QGISStyleResource(ModelResource):
"""Styles API for QGIS Server backend."""

body = fields.CharField(attribute='body', use_in='detail')
name = fields.CharField(attribute='name')
title = fields.CharField(attribute='title')
layer = fields.ForeignKey(
'geonode.api.resourcebase_api.LayerResource',
attribute='layer',
null=True)
style_url = fields.CharField(attribute='style_url')
type = fields.CharField(attribute='type')

class Meta:
paginator_class = CrossSiteXHRPaginator
queryset = QGISServerStyle.objects.all()
resource_name = 'styles'
detail_uri_name = 'id'
allowed_methods = ['get', 'post', 'delete']
authorization = GeoNodeStyleAuthorization()
filtering = {
'id': ALL,
'title': ALL,
'name': ALL,
'layer': ALL_WITH_RELATIONS
}

def populate_object(self, style):
"""Populate results with necessary fields
:param style: Style objects
:type style: QGISServerStyle
:return:
"""
try:
qgis_layer = style.layer_styles.first()
""":type: geonode.qgis_server.QGISServerLayer"""
style.layer = qgis_layer.layer
style.type = 'qml'
except Exception:
pass
return style

def build_filters(self, filters=None, **kwargs):
"""Apply custom filters for layer."""
filters = super(QGISStyleResource, self).build_filters(
filters, **kwargs)
# Convert layer__ filters into layer_styles__layer__
updated_filters = {}
for key, value in filters.items():
key = key.replace('layer__', 'layer_styles__layer__')
updated_filters[key] = value
return updated_filters

def build_bundle(self, obj=None, data=None, request=None, **kwargs):
"""Override build_bundle method to add additional info."""

if obj is None and self._meta.object_class:
obj = self._meta.object_class()

elif obj:
obj = self.populate_object(obj)

return Bundle(
obj=obj,
data=data,
request=request,
**kwargs)

def post_list(self, request, **kwargs):
"""Attempt to redirect to QGIS Server Style management.
A post method should have the following field:
name: Slug name of style
title: Title of style
style: the style file uploaded
Also, should have kwargs:
layername or layer__name: The layer name associated with the style
or
layer__id: The layer id associated with the style
"""
from geonode.qgis_server.views import qml_style

# Extract layer name information
POST = request.POST
FILES = request.FILES
layername = POST.get('layername') or POST.get('layer__name')
if not layername:
layer_id = POST.get('layer__id')
layer = Layer.objects.get(id=layer_id)
layername = layer.name

# move style file
FILES['qml'] = FILES['style']

response = qml_style(request, layername)

if isinstance(response, TemplateResponse):
if response.status_code == 201:
obj = QGISServerStyle.objects.get(
layer_styles__layer__name=layername,
name=POST['name'])
updated_bundle = self.build_bundle(obj=obj, request=request)
location = self.get_resource_uri(updated_bundle)

if not self._meta.always_return_data:
return http.HttpCreated(location=location)
else:
updated_bundle = self.full_dehydrate(updated_bundle)
updated_bundle = self.alter_detail_data_to_serialize(
request, updated_bundle)
return self.create_response(
request, updated_bundle,
response_class=http.HttpCreated,
location=location)
else:
context = response.context_data
# Check form valid
style_upload_form = context['style_upload_form']
if not style_upload_form.is_valid():
raise BadRequest(style_upload_form.errors.as_text())
alert_message = context['alert_message']
raise BadRequest(alert_message)
elif isinstance(response, HttpResponse):
response_class = None
if response.status_code == 403:
response_class = http.HttpForbidden
return self.error_response(
request, response.content,
response_class=response_class)

def delete_detail(self, request, **kwargs):
"""Attempt to redirect to QGIS Server Style management."""
from geonode.qgis_server.views import qml_style
style_id = kwargs.get('id')

qgis_style = QGISServerStyle.objects.get(id=style_id)
layername = qgis_style.layer_styles.first().layer.name

response = qml_style(request, layername, style_name=qgis_style.name)

if isinstance(response, TemplateResponse):
if response.status_code == 200:
# style deleted
return http.HttpNoContent()
else:
context = response.context_data
# Check form valid
style_upload_form = context['style_upload_form']
if not style_upload_form.is_valid():
raise BadRequest(style_upload_form.errors.as_text())
alert_message = context['alert_message']
raise BadRequest(alert_message)
elif isinstance(response, HttpResponse):
response_class = None
if response.status_code == 403:
response_class = http.HttpForbidden
return self.error_response(
request, response.content,
response_class=response_class)

def delete_list(self, request, **kwargs):
"""Do not allow delete list"""
return http.HttpForbidden()


class GeoserverStyleResource(ModelResource):
"""Styles API for Geoserver backend."""
body = fields.CharField(
Expand Down Expand Up @@ -844,11 +667,7 @@ def build_bundle(self, obj=None, data=None, request=None, **kwargs):
**kwargs)


if check_ogc_backend(qgis_server.BACKEND_PACKAGE):
class StyleResource(QGISStyleResource):
"""Wrapper for Generic Style Resource"""
pass
elif check_ogc_backend(geoserver.BACKEND_PACKAGE):
if check_ogc_backend(geoserver.BACKEND_PACKAGE):
class StyleResource(GeoserverStyleResource):
"""Wrapper for Generic Style Resource"""
pass
Expand Down
5 changes: 1 addition & 4 deletions geonode/api/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from django.conf import settings

from geonode import geoserver, qgis_server
from geonode import geoserver
from geonode.utils import check_ogc_backend


Expand Down Expand Up @@ -133,9 +133,6 @@ def filter_by_resource_ids(self, object_list, permitted_ids):
"""Filter Style queryset by permitted resource ids."""
if check_ogc_backend(geoserver.BACKEND_PACKAGE):
return object_list.filter(layer_styles__id__in=permitted_ids)
elif check_ogc_backend(qgis_server.BACKEND_PACKAGE):
return object_list.filter(
layer_styles__layer__id__in=permitted_ids)

def read_list(self, object_list, bundle):
permitted_ids = get_objects_for_user(
Expand Down
Loading

0 comments on commit 30c1453

Please sign in to comment.