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

[Backport 4.2.x ] [Fixes #11912] GWC layers only cache default style after B/R restore … #11914

Merged
merged 3 commits into from
Feb 1, 2024
Merged
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
6 changes: 2 additions & 4 deletions create-envfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ def _get_vals_to_replace(args):
_vals_to_replace["letsencrypt_mode"] = (
"disabled"
if not _vals_to_replace.get("https_host")
else "staging"
if _jsfile.get("env_type", args.env_type) in ["test"]
else "production"
else "staging" if _jsfile.get("env_type", args.env_type) in ["test"] else "production"
)
_vals_to_replace["debug"] = False if _jsfile.get("env_type", args.env_type) in ["prod", "test"] else True
_vals_to_replace["email"] = _jsfile.get("email", args.email)
Expand Down Expand Up @@ -124,7 +122,7 @@ def _get_vals_to_replace(args):
prog="ENV file builder",
description="Tool for generate environment file automatically. The information can be passed or via CLI or via JSON file ( --file /path/env.json)",
usage="python create-envfile.py localhost -f /path/to/json/file.json",
allow_abbrev=False
allow_abbrev=False,
)
parser.add_argument(
"--noinput",
Expand Down
6 changes: 0 additions & 6 deletions geonode/api/resourcebase_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,6 @@ def hydrate_title(self, bundle):


class ResourceBaseResource(CommonModelApi):

"""ResourceBase api"""

class Meta(CommonMetaApi):
Expand All @@ -607,7 +606,6 @@ class Meta(CommonMetaApi):


class FeaturedResourceBaseResource(CommonModelApi):

"""Only the featured resourcebases"""

class Meta(CommonMetaApi):
Expand All @@ -620,7 +618,6 @@ class Meta(CommonMetaApi):


class LayerResource(CommonModelApi):

"""Dataset API"""

links = fields.ListField(attribute="links", null=True, use_in="all", default=[])
Expand Down Expand Up @@ -756,7 +753,6 @@ class Meta(CommonMetaApi):


class MapResource(CommonModelApi):

"""Maps API"""

def build_filters(self, filters=None, ignore_bad_filters=False, **kwargs):
Expand Down Expand Up @@ -822,7 +818,6 @@ class Meta(CommonMetaApi):


class GeoAppResource(CommonModelApi):

"""GeoApps API"""

def format_objects(self, objects):
Expand Down Expand Up @@ -874,7 +869,6 @@ class Meta(CommonMetaApi):


class DocumentResource(CommonModelApi):

"""Documents API"""

def build_filters(self, filters=None, ignore_bad_filters=False, **kwargs):
Expand Down
1 change: 0 additions & 1 deletion geonode/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ def test_tags_lockdown(self):


class SearchApiTests(ResourceTestCaseMixin, GeoNodeBaseTestSupport):

"""Test the search"""

# loading test thesausuri and initial data
Expand Down
5 changes: 0 additions & 5 deletions geonode/base/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@


class IsSelf(permissions.BasePermission):

"""Grant permission only if the current instance is the request user.
Used to allow users to edit their own account, nothing to others (even
superusers).
Expand All @@ -62,7 +61,6 @@ def has_object_permission(self, request, view, obj):


class IsSelfOrReadOnly(IsSelf):

"""Grant permissions if instance *IS* the request user, or read-only.
Used to allow users to edit their own account, and others to read.
"""
Expand All @@ -75,7 +73,6 @@ def has_object_permission(self, request, view, obj):


class IsSelfOrAdmin(IsSelf):

"""Grant R/W to self and superusers/staff members. Deny others."""

def has_permission(self, request, view):
Expand All @@ -94,7 +91,6 @@ def has_object_permission(self, request, view, obj):


class IsSelfOrAdminOrReadOnly(IsSelfOrAdmin):

"""Grant R/W to self and superusers/staff members, R/O to others."""

def has_permission(self, request, view):
Expand All @@ -111,7 +107,6 @@ def has_object_permission(self, request, view, obj):


class IsSelfOrAdminOrAuthenticatedReadOnly(IsSelfOrAdmin):

"""Grant R/W to self and superusers/staff members, R/O to auth."""

def has_object_permission(self, request, view, obj):
Expand Down
2 changes: 1 addition & 1 deletion geonode/base/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ class Meta:
"is_copyable",
"blob",
"metadata",
"executions"
"executions",
# TODO
# csw_typename, csw_schema, csw_mdsource, csw_insert_date, csw_type, csw_anytext, csw_wkt_geometry,
# metadata_uploaded, metadata_uploaded_preserve, metadata_xml,
Expand Down
6 changes: 3 additions & 3 deletions geonode/base/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,10 +1951,10 @@ def test_set_resource_thumbnail(self):
self.assertEqual(response.json(), "The url must be of an image with format (png, jpeg or jpg)")

# using Base64 data as an ASCII byte string
data[
"file"
] = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABHNCSVQICAgI\
data["file"] = (
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABHNCSVQICAgI\
fAhkiAAAABl0RVh0U29mdHdhcmUAZ25vbWUtc2NyZWVuc2hvdO8Dvz4AAAANSURBVAiZYzAxMfkPAALYAZzx61+bAAAAAElFTkSuQmCC"
)
with patch("geonode.base.models.is_monochromatic_image") as _mck:
_mck.return_value = False
response = self.client.put(url, data=data, format="json")
Expand Down
1 change: 0 additions & 1 deletion geonode/base/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ def build_attrs(self, base_attrs=None, extra_attrs=None, **kwargs):


class ResourceBaseForm(TranslationModelForm, LinkedResourceForm):

"""Base form for metadata, should be inherited by childres classes of ResourceBase"""

abstract = forms.CharField(label=_("Abstract"), required=False, widget=TinyMCE())
Expand Down
1 change: 0 additions & 1 deletion geonode/base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ def test_add_missing_metadata_author_or_poc(self):


class TestCreationOfContactRolesByDifferentInputTypes(ThumbnailTests):

"""
Test that contact roles can be set as people profile
"""
Expand Down
73 changes: 60 additions & 13 deletions geonode/br/management/commands/create_tile_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
</metaWidthHeight>
<mimeFormats>
<string>application/json;type=utfgrid</string>
<string>image/gif</string>
<string>image/jpeg</string>
<string>image/png</string>
<string>image/png8</string>
<string>image/vnd.jpeg-png</string>
<string>image/jpeg</string>
<string>image/vnd.jpeg-png8</string>
<string>image/gif</string>
<string>image/png8</string>
</mimeFormats>
<gridSubsets>
<gridSubset>
Expand All @@ -66,16 +66,48 @@
<gridSetName>EPSG:900913</gridSetName>
</gridSubset>
</gridSubsets>
<expireCache>0</expireCache>
<expireClients>0</expireClients>
<autoCacheStyles>true</autoCacheStyles>
<gutter>0</gutter>
<cacheWarningSkips/>
</GeoServerLayer>"""


class Command(BaseCommand):
help = "Create missing TileLayers in GWC"

def add_arguments(self, parser):
pass
parser.add_argument(

Check warning on line 81 in geonode/br/management/commands/create_tile_layers.py

View check run for this annotation

Codecov / codecov/patch

geonode/br/management/commands/create_tile_layers.py#L81

Added line #L81 was not covered by tests
'-f',
'--force',
dest="force",
action='store_true',
help="Force tile layer re-creation also if it already exists in GWC")

parser.add_argument(

Check warning on line 88 in geonode/br/management/commands/create_tile_layers.py

View check run for this annotation

Codecov / codecov/patch

geonode/br/management/commands/create_tile_layers.py#L88

Added line #L88 was not covered by tests
'-l',
'--layer',
dest="layers",
action='append',
help="Only process specified layers ")

parser.add_argument(

Check warning on line 95 in geonode/br/management/commands/create_tile_layers.py

View check run for this annotation

Codecov / codecov/patch

geonode/br/management/commands/create_tile_layers.py#L95

Added line #L95 was not covered by tests
'-d',
'--dry-run',
dest="dry-run",
action='store_true',
help="Do not actually perform any change on GWC")

def handle(self, **options):
force = options.get('force')
requested_layers = options.get('layers')
dry_run = options.get('dry-run')

Check warning on line 105 in geonode/br/management/commands/create_tile_layers.py

View check run for this annotation

Codecov / codecov/patch

geonode/br/management/commands/create_tile_layers.py#L103-L105

Added lines #L103 - L105 were not covered by tests

logger.debug(f"FORCE is {force}")
logger.debug(f"DRY-RUN is {dry_run}")
logger.debug(f"LAYERS is {requested_layers}")

Check warning on line 109 in geonode/br/management/commands/create_tile_layers.py

View check run for this annotation

Codecov / codecov/patch

geonode/br/management/commands/create_tile_layers.py#L107-L109

Added lines #L107 - L109 were not covered by tests

try:
baseurl = settings.OGC_SERVER["default"]["LOCATION"]
user = settings.OGC_SERVER["default"]["USER"]
Expand All @@ -91,24 +123,38 @@
cnt_old = 0
cnt_new = 0
cnt_bad = 0
cnt_skip = 0
cnt_force = 0

Check warning on line 127 in geonode/br/management/commands/create_tile_layers.py

View check run for this annotation

Codecov / codecov/patch

geonode/br/management/commands/create_tile_layers.py#L126-L127

Added lines #L126 - L127 were not covered by tests
for layer in layers:
i += 1
logger.info(f"- {i}/{tot} Processing layer: {layer.typename}")

if requested_layers and layer.typename not in requested_layers:
logger.info(" - Layer filtered out by args")
cnt_skip += 1
continue

Check warning on line 135 in geonode/br/management/commands/create_tile_layers.py

View check run for this annotation

Codecov / codecov/patch

geonode/br/management/commands/create_tile_layers.py#L133-L135

Added lines #L133 - L135 were not covered by tests

r = requests.get(f"{baseurl}gwc/rest/layers/{layer.typename}.xml", auth=HTTPBasicAuth(user, passwd))

if r.status_code == 200:
logger.info(" - Layer already configured")
cnt_old += 1
continue
if force:
logger.info(" - Forcing layer configuration in GWC")
cnt_force += 1

Check warning on line 142 in geonode/br/management/commands/create_tile_layers.py

View check run for this annotation

Codecov / codecov/patch

geonode/br/management/commands/create_tile_layers.py#L141-L142

Added lines #L141 - L142 were not covered by tests
else:
logger.info(" - Layer already configured in GWC")
cnt_old += 1
continue

Check warning on line 146 in geonode/br/management/commands/create_tile_layers.py

View check run for this annotation

Codecov / codecov/patch

geonode/br/management/commands/create_tile_layers.py#L144-L146

Added lines #L144 - L146 were not covered by tests
try:
data = REQ_TEMPLATE.format(layer.name)
url = f"{baseurl}gwc/rest/layers/{layer.typename}.xml"
logger.info(" - Configuring...")
response = requests.put(
url, data=data, headers={"Content-Type": "text/xml"}, auth=HTTPBasicAuth(user, passwd)
)

if response.status_code == 200:
if not dry_run:
response = requests.put(

Check warning on line 153 in geonode/br/management/commands/create_tile_layers.py

View check run for this annotation

Codecov / codecov/patch

geonode/br/management/commands/create_tile_layers.py#L153

Added line #L153 was not covered by tests
url, data=data, headers={"Content-Type": "text/xml"}, auth=HTTPBasicAuth(user, passwd)
)

if dry_run or response.status_code == 200:
logger.info(f" - Done {layer.name}")
cnt_new += 1
else:
Expand All @@ -121,6 +167,7 @@
raise e

logger.info("Work completed")
logger.info(f"- TileLayers configured: {cnt_new}")
logger.info(f"- TileLayers configured: {cnt_new}" + (f" (forced {cnt_force})" if cnt_force else ""))

Check warning on line 170 in geonode/br/management/commands/create_tile_layers.py

View check run for this annotation

Codecov / codecov/patch

geonode/br/management/commands/create_tile_layers.py#L170

Added line #L170 was not covered by tests
logger.info(f"- TileLayers in error : {cnt_bad}")
logger.info(f"- TileLayers found : {cnt_old}")
logger.info(f"- TileLayers untouched : {cnt_old}")
logger.info(f"- TileLayers skipped : {cnt_skip}")

Check warning on line 173 in geonode/br/management/commands/create_tile_layers.py

View check run for this annotation

Codecov / codecov/patch

geonode/br/management/commands/create_tile_layers.py#L172-L173

Added lines #L172 - L173 were not covered by tests
1 change: 0 additions & 1 deletion geonode/catalogue/metadataxsl/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@


class MetadataXSLTest(GeoNodeBaseTestSupport):

"""
Tests geonode.catalogue.metadataxsl app/module
"""
Expand Down
18 changes: 10 additions & 8 deletions geonode/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,17 @@ def resource_urls(request):
EXIF_ENABLED=getattr(settings, "EXIF_ENABLED", False),
FAVORITE_ENABLED=getattr(settings, "FAVORITE_ENABLED", False),
SEARCH_FILTERS=getattr(settings, "SEARCH_FILTERS", False),
THESAURI_FILTERS=[
t["name"]
for t in [
settings.THESAURUS,
THESAURI_FILTERS=(
[
t["name"]
for t in [
settings.THESAURUS,
]
if t.get("filter")
]
if t.get("filter")
]
if hasattr(settings, "THESAURUS")
else [t.identifier for t in thesaurus],
if hasattr(settings, "THESAURUS")
else [t.identifier for t in thesaurus]
),
MAP_CLIENT_USE_CROSS_ORIGIN_CREDENTIALS=getattr(settings, "MAP_CLIENT_USE_CROSS_ORIGIN_CREDENTIALS", False),
SHOW_PROFILE_EMAIL=getattr(settings, "SHOW_PROFILE_EMAIL", False),
OGC_SERVER=getattr(settings, "OGC_SERVER", None),
Expand Down
1 change: 0 additions & 1 deletion geonode/documents/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class DocumentDescriptionForm(forms.Form):


class DocumentCreateForm(TranslationModelForm):

"""
The document upload form.
"""
Expand Down
1 change: 0 additions & 1 deletion geonode/documents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@


class Document(ResourceBase):

"""
A document is any kind of information that can be attached to a map such as pdf, images, videos, xls...
"""
Expand Down
8 changes: 5 additions & 3 deletions geonode/documents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,11 @@ def document_metadata(
category_form = CategoryForm(
request.POST,
prefix="category_choice_field",
initial=int(request.POST["category_choice_field"])
if "category_choice_field" in request.POST and request.POST["category_choice_field"]
else None,
initial=(
int(request.POST["category_choice_field"])
if "category_choice_field" in request.POST and request.POST["category_choice_field"]
else None
),
)

if hasattr(settings, "THESAURUS"):
Expand Down
1 change: 0 additions & 1 deletion geonode/geoapps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@


class GeoApp(ResourceBase):

"""
A GeoApp it is a generic container for every client applications the
user might want to create or define.
Expand Down
1 change: 0 additions & 1 deletion geonode/geoapps/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@


class GeoAppTests(GeoNodeBaseTestSupport):

"""Tests geonode.geoapps module"""

fixtures = ["initial_data.json", "group_test_data.json", "default_oauth_apps.json"]
Expand Down
8 changes: 5 additions & 3 deletions geonode/geoapps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ def geoapp_metadata(
category_form = CategoryForm(
request.POST,
prefix="category_choice_field",
initial=int(request.POST["category_choice_field"])
if "category_choice_field" in request.POST and request.POST["category_choice_field"]
else None,
initial=(
int(request.POST["category_choice_field"])
if "category_choice_field" in request.POST and request.POST["category_choice_field"]
else None
),
)

if hasattr(settings, "THESAURUS"):
Expand Down
1 change: 0 additions & 1 deletion geonode/geoserver/createlayer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@


class CreateLayerCoreTest(GeoNodeBaseTestSupport):

"""
Test createlayer application.
"""
Expand Down
2 changes: 0 additions & 2 deletions geonode/geoserver/tests/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def _log(msg, *args):

@override_settings(SITEURL="http://localhost:8001/")
class GeoNodeGeoServerSync(GeoNodeLiveTestSupport):

"""
Tests GeoNode/GeoServer syncronization
"""
Expand Down Expand Up @@ -104,7 +103,6 @@ def test_set_attributes_from_geoserver(self):

@override_settings(SITEURL="http://localhost:8002/")
class GeoNodeGeoServerCapabilities(GeoNodeLiveTestSupport):

"""
Tests GeoNode/GeoServer GetCapabilities per layer, user, category and map
"""
Expand Down
Loading
Loading