Skip to content

Commit

Permalink
fix djangocms-versioning draft deletion bug (#214) (#215)
Browse files Browse the repository at this point in the history
* fix djangocms-versioning draft deletion bug (#214)

Previously, `djangocms_alias.models.AliasContent.delete` deleted all plugins
related to `AliasContent.alias`, with the same language. Drafts and previously
published versions included.
This meant that the deletion of a draft resulted in plugins disappearing from
published pages.

This patch removes the mechanism entirely and instead adds a warning, notifying
the user that the last version or translation of a language got deleted.

Signed-off-by: Florian Scherf <[email protected]>

* ci: auto fixes from pre-commit hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: Florian Scherf <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
fscherf and pre-commit-ci[bot] authored Mar 10, 2024
1 parent 9288b16 commit fa45af8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 13 additions & 1 deletion djangocms_alias/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from cms.utils.permissions import get_model_permission_codename
from cms.utils.urlutils import admin_reverse
from django import forms
from django.contrib import admin
from django.contrib import admin, messages
from django.http import (
Http404,
HttpRequest,
Expand Down Expand Up @@ -190,3 +190,15 @@ def has_module_permission(self, request: HttpRequest) -> bool:
"""Hides admin class in admin site overview"""

return False

def delete_model(self, request: HttpRequest, obj: AliasContent):
if obj.alias._default_manager.filter(language=obj.language).count() == 1:
message = _(
"Alias content for language {} deleted. A new empty alias content will be created if needed."
).format(obj.language)
self.message_user(request, message, level=messages.WARNING)

return super().delete_model(
request=request,
obj=obj,
)
5 changes: 0 additions & 5 deletions djangocms_alias/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,6 @@ def get_placeholders(self):
def get_template(self):
return "djangocms_alias/alias_content.html"

@transaction.atomic
def delete(self, *args, **kwargs):
super().delete(*args, **kwargs)
self.alias.cms_plugins.filter(language=self.language).delete()

@transaction.atomic
def populate(self, replaced_placeholder=None, replaced_plugin=None, plugins=None):
if not replaced_placeholder and not replaced_plugin:
Expand Down

0 comments on commit fa45af8

Please sign in to comment.