django-cms / djangocms-alias

Other
8 stars 23 forks source link

djangocms-versioning draft deletion causes plugins to disappear from pages #214

Closed fscherf closed 4 months ago

fscherf commented 7 months ago

When I use djangocms-alias with djangocms-versioning and I delete a draft of an alias, the alias does not get reset to the previous version on the pages using it. Instead, it gets removed entirely from all pages.

Steps to reproduce:

  1. Create a Page and publish it
  2. Create a Content Alias on that page and publish it
  3. Create a new draft for the Content Alias
  4. Delete the draft

I think the problem is rooted in this line in models.AliasContent.delete. From the code, it looks like this is wanted behavior because it deliberately deletes all plugins using the deleted Alias Content. Hence I am not sure how to fix it (just removing it works for me).

I use django-cms 4.1, and I was able to reproduces this behavior in all djangocms-alias versions I tried, including the latest master.

fsbraun commented 7 months ago

Just to clarify: how do you delete the draft alias?

fscherf commented 7 months ago

@fsbraun: i went to the preview of the alias, clicked on "Versions" in the top-bar, and clicked on the trash icon of the draft in the table of listed versions

fsbraun commented 7 months ago

From the code I fear the plugins are even deleted if there are alias contents available in other languages. To me it only makes sense to delete thos plugins if the whole Alias is deleted.

fsbraun commented 7 months ago

Hm, I think this is a serious bug. It would also imply that an alias plugin is removed from a published page. I can only assume that the following happened:

One solution for me would be to remove the mechanism and to add a warning message (using the message framework) which would trigger if the last alias content of a language was deleted.

@fscherf Would you be interested to create a pull request?

fscherf commented 7 months ago

@fsbraun: Yes! Alias plugins are disappearing from published pages definitely.

Ok. That would mean, the deletion of an AliasContent object wouldn't trigger the deletion of cms plugins anymore. What do we do with orphaned cms plugins that point to no longer existing AliasContents then?

Yes, I would be interested in opening a pull-request, once we decided on how to fix this issue.

fsbraun commented 7 months ago

They'll point to an Alias object (which is still there). Upon rendering the alias plugins with no AliasContent for the selected language, they should be treated as empty.

Deleting Alias objects should automatically trigger a cascade to either also delete the alias plugins (if possible) or deny deleting the alias.

For now, I would be fine with the warning through the message framework. In the alias's admin delete view:

    if <last content object of language deleted>:
        message = _('Draft deleted. A new empty draft will be created automatically if needed.')  # Or something better
        self.message_user(request, message, level=messages.WARNING)
fscherf commented 5 months ago

@fsbraun Thanks for merging! When will the fix be released?

fsbraun commented 5 months ago

I hope within the next 2 weeks.

fsbraun commented 4 months ago

Published with 2.0.1