Skip to content

Commit

Permalink
Merge branch 'master' into GITHUB-24538627-Add-bulk-delete-to-version…
Browse files Browse the repository at this point in the history
…s-djangocms-versioning
  • Loading branch information
fsbraun authored Sep 27, 2023
2 parents 1deb2b7 + 8e045dd commit 826d248
Show file tree
Hide file tree
Showing 26 changed files with 291 additions and 247 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Docs

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
name: build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- name: Cache dependencies
uses: actions/[email protected]
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- run: python -m pip install -r docs/requirements.txt
- name: Build docs
run: |
cd docs
make html
spelling:
runs-on: ubuntu-latest
name: spelling
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- name: Cache dependencies
uses: actions/[email protected]
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- run: python -m pip install -r docs/requirements.txt
- name: Check spelling
run: |
cd docs
make spelling
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog
Unreleased
==========
* feat: Reversable generic foreign key lookup from version
* fix: formatted files through ruff to fix tests
* fix: Remove version check when evaluating CMS PageContent objects

2.0.0rc1
========
Expand Down
5 changes: 5 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Security Policy

## Reporting a Vulnerability

As ever, we remind our users and contributors that all security reports, patches and concerns be addressed only to our security team by email, at [email protected].
56 changes: 13 additions & 43 deletions djangocms_versioning/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,7 @@ def _get_edit_link(self, obj, request, disabled=False):
disabled = True

url = reverse(
"admin:{app}_{model}_edit_redirect".format(
app=version._meta.app_label, model=version._meta.model_name
),
f"admin:{version._meta.app_label}_{version._meta.model_name}_edit_redirect",
args=(version.pk,),
)
return self.admin_action_button(
Expand Down Expand Up @@ -677,9 +675,7 @@ def _get_archive_link(self, obj, request, disabled=False):
# Don't display the link if it can't be archived
return ""
archive_url = reverse(
"admin:{app}_{model}_archive".format(
app=obj._meta.app_label, model=self.model._meta.model_name
),
f"admin:{obj._meta.app_label}_{self.model._meta.model_name}_archive",
args=(obj.pk,),
)
return self.admin_action_button(
Expand All @@ -697,9 +693,7 @@ def _get_publish_link(self, obj, request):
# Don't display the link if it can't be published
return ""
publish_url = reverse(
"admin:{app}_{model}_publish".format(
app=obj._meta.app_label, model=self.model._meta.model_name
),
f"admin:{obj._meta.app_label}_{self.model._meta.model_name}_publish",
args=(obj.pk,),
)
return self.admin_action_button(
Expand All @@ -719,9 +713,7 @@ def _get_unpublish_link(self, obj, request, disabled=False):
# Don't display the link if it can't be unpublished
return ""
unpublish_url = reverse(
"admin:{app}_{model}_unpublish".format(
app=obj._meta.app_label, model=self.model._meta.model_name
),
f"admin:{obj._meta.app_label}_{self.model._meta.model_name}_unpublish",
args=(obj.pk,),
)
return self.admin_action_button(
Expand Down Expand Up @@ -758,9 +750,7 @@ def _get_edit_link(self, obj, request, disabled=False):
keepsideframe = obj.versionable.content_model_is_sideframe_editable

edit_url = reverse(
"admin:{app}_{model}_edit_redirect".format(
app=obj._meta.app_label, model=self.model._meta.model_name
),
f"admin:{obj._meta.app_label}_{self.model._meta.model_name}_edit_redirect",
args=(obj.pk,),
)
return self.admin_action_button(
Expand All @@ -781,9 +771,7 @@ def _get_revert_link(self, obj, request, disabled=False):
return ""

revert_url = reverse(
"admin:{app}_{model}_revert".format(
app=obj._meta.app_label, model=self.model._meta.model_name
),
f"admin:{obj._meta.app_label}_{self.model._meta.model_name}_revert",
args=(obj.pk,),
)
return self.admin_action_button(
Expand All @@ -802,9 +790,7 @@ def _get_discard_link(self, obj, request, disabled=False):
return ""

discard_url = reverse(
"admin:{app}_{model}_discard".format(
app=obj._meta.app_label, model=self.model._meta.model_name
),
f"admin:{obj._meta.app_label}_{self.model._meta.model_name}_discard",
args=(obj.pk,),
)
return self.admin_action_button(
Expand All @@ -829,9 +815,7 @@ def _get_unlock_link(self, obj, request):
if request.user.has_perm("djangocms_versioning.delete_versionlock"):
disabled = False

unlock_url = reverse("admin:{app}_{model}_unlock".format(
app=obj._meta.app_label, model=self.model._meta.model_name,
), args=(obj.pk,))
unlock_url = reverse(f"admin:{obj._meta.app_label}_{self.model._meta.model_name}_unlock", args=(obj.pk,))
return self.admin_action_button(
unlock_url,
icon="unlock",
Expand Down Expand Up @@ -885,9 +869,7 @@ def compare_versions(self, request, queryset):

# Build the link for the version comparison of the two selected versions
url = reverse(
"admin:{app}_{model}_compare".format(
app=self.model._meta.app_label, model=self.model._meta.model_name
),
f"admin:{self.model._meta.app_label}_{self.model._meta.model_name}_compare",
args=(queryset[0].pk,),
)
url += "?compare_to=%d" % queryset[1].pk
Expand Down Expand Up @@ -947,10 +929,7 @@ def archive_view(self, request, object_id):
"version_number": version.number,
"object_id": object_id,
"archive_url": reverse(
"admin:{app}_{model}_archive".format(
app=self.model._meta.app_label,
model=self.model._meta.model_name,
),
f"admin:{self.model._meta.app_label}_{self.model._meta.model_name}_archive",
args=(version.content.pk,),
),
"back_url": self.back_link(request, version),
Expand Down Expand Up @@ -1027,10 +1006,7 @@ def unpublish_view(self, request, object_id):
"version_number": version.number,
"object_id": object_id,
"unpublish_url": reverse(
"admin:{app}_{model}_unpublish".format(
app=self.model._meta.app_label,
model=self.model._meta.model_name,
),
f"admin:{self.model._meta.app_label}_{self.model._meta.model_name}_unpublish",
args=(version.content.pk,),
),
"back_url": self.back_link(request, version),
Expand Down Expand Up @@ -1145,10 +1121,7 @@ def revert_view(self, request, object_id):
"draft_version": draft_version,
"object_id": object_id,
"revert_url": reverse(
"admin:{app}_{model}_revert".format(
app=self.model._meta.app_label,
model=self.model._meta.model_name,
),
f"admin:{self.model._meta.app_label}_{self.model._meta.model_name}_revert",
args=(version.content.pk,),
),
"back_url": self.back_link(request, version),
Expand Down Expand Up @@ -1187,10 +1160,7 @@ def discard_view(self, request, object_id):
"draft_version": version,
"object_id": object_id,
"revert_url": reverse(
"admin:{app}_{model}_revert".format(
app=self.model._meta.app_label,
model=self.model._meta.model_name,
),
f"admin:{self.model._meta.app_label}_{self.model._meta.model_name}_revert",
args=(version.content.pk,),
),
"back_url": self.back_link(request, version),
Expand Down
22 changes: 6 additions & 16 deletions djangocms_versioning/cms_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections

from cms.app_base import CMSAppConfig, CMSAppExtension
from cms.extensions.models import BaseExtension
from cms.models import PageContent, Placeholder
from cms.utils import get_language_from_request
from cms.utils.i18n import get_language_list, get_language_tuple
Expand Down Expand Up @@ -83,9 +84,7 @@ def handle_versioning_setting(self, cms_config):
for versionable in cms_config.versioning:
if not isinstance(versionable, BaseVersionableItem):
raise ImproperlyConfigured(
"{!r} is not a subclass of djangocms_versioning.datastructures.BaseVersionableItem".format(
versionable
)
f"{versionable!r} is not a subclass of djangocms_versioning.datastructures.BaseVersionableItem"
)
# NOTE: Do not use the cached property here as this is
# still changing and needs to be calculated on the fly
Expand All @@ -107,9 +106,7 @@ def handle_versioning_add_to_confirmation_context_setting(self, cms_config):
for key, value in add_to_context.items():
if key not in supported_keys:
raise ImproperlyConfigured(
"{!r} is not a supported dict key in the versioning_add_to_confirmation_context setting".format(
key
)
f"{key!r} is not a supported dict key in the versioning_add_to_confirmation_context setting"
)
if key not in self.add_to_context:
self.add_to_context[key] = collections.OrderedDict()
Expand Down Expand Up @@ -228,17 +225,12 @@ def copy_page_content(original_content):
new_placeholders.append(new_placeholder)
new_content.placeholders.add(*new_placeholders)

# If pagecontent has an associated title or page extension, also copy this!
# If pagecontent has an associated content or page extension, also copy this!
for field in PageContent._meta.related_objects:
if hasattr(original_content, field.name):
extension = getattr(original_content, field.name)
extension_fields = {
field.name: getattr(extension, field.name)
for field in extension._meta.fields
if field.name not in (PageContent._meta.pk.name, "extended_object")
}
extension_fields["extended_object"] = new_content
field.related_model.objects.create(**extension_fields)
if isinstance(extension, BaseExtension):
extension.copy(new_content, new_content.language)

return new_content

Expand All @@ -263,7 +255,6 @@ def on_page_content_publish(version):
page._update_url_path_recursive(language)
page.clear_cache(menu=True)


def on_page_content_unpublish(version):
"""Url path and cache operations to do when a PageContent obj is unpublished"""
page = version.content.page
Expand Down Expand Up @@ -419,4 +410,3 @@ class VersioningCMSConfig(CMSAppConfig):
cms_toolbar_mixin = CMSToolbarVersioningMixin
PageContent.add_to_class("is_editable", indicators.is_editable)
PageContent.add_to_class("content_indicator", indicators.content_indicator)
PageContent.add_to_class("__bool__", lambda self: self.versions.exists())
31 changes: 12 additions & 19 deletions djangocms_versioning/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ def _add_publish_button(self):
proxy_model = self._get_proxy_model()
version = Version.objects.get_for_content(self.toolbar.obj)
publish_url = reverse(
"admin:{app}_{model}_publish".format(
app=proxy_model._meta.app_label, model=proxy_model.__name__.lower()
),
f"admin:{proxy_model._meta.app_label}_{proxy_model.__name__.lower()}_publish",
args=(version.pk,),
)
item.add_button(
Expand Down Expand Up @@ -103,9 +101,7 @@ def _add_edit_button(self, disabled=False):
version = Version.objects.get_for_content(self.toolbar.obj)
if version.check_edit_redirect.as_bool(self.request.user):
edit_url = reverse(
"admin:{app}_{model}_edit_redirect".format(
app=proxy_model._meta.app_label, model=proxy_model.__name__.lower()
),
f"admin:{proxy_model._meta.app_label}_{proxy_model.__name__.lower()}_edit_redirect",
args=(version.pk,),
)
pks_for_grouper = version.versionable.for_content_grouping_values(
Expand All @@ -132,9 +128,7 @@ def _add_unlock_button(self):
version = Version.objects.get_for_content(self.toolbar.obj)
if version.check_unlock.as_bool(self.request.user):
unlock_url = reverse(
"admin:{app}_{model}_unlock".format(
app=proxy_model._meta.app_label, model=proxy_model.__name__.lower()
),
f"admin:{proxy_model._meta.app_label}_{proxy_model.__name__.lower()}_unlock",
args=(version.pk,),
)
can_unlock = self.request.user.has_perm("djangocms_versioning.delete_versionlock")
Expand Down Expand Up @@ -176,10 +170,7 @@ def _add_revert_button(self, disabled=False):
version = Version.objects.get_for_content(self.toolbar.obj)
if version.check_revert.as_bool(self.request.user):
revert_url = reverse(
"admin:{app}_{model}_revert".format(
app=proxy_model._meta.app_label,
model=proxy_model._meta.model_name,
),
f"admin:{proxy_model._meta.app_label}_{proxy_model._meta.model_name}_revert",
args=(version.pk,),
)
item.add_button(
Expand Down Expand Up @@ -218,9 +209,10 @@ def _add_versioning_menu(self):
if version.source:
name = _("Compare to {source}").format(source=_(version.source.short_name()))
proxy_model = self._get_proxy_model()
url = reverse("admin:{app}_{model}_compare".format(
app=proxy_model._meta.app_label, model=proxy_model.__name__.lower()
), args=(version.source.pk,))
url = reverse(
f"admin:{proxy_model._meta.app_label}_{proxy_model.__name__.lower()}_compare",
args=(version.source.pk,)
)

url += "?" + urlencode({
"compare_to": version.pk,
Expand All @@ -232,9 +224,10 @@ def _add_versioning_menu(self):
versioning_menu.add_item(Break())
versioning_menu.add_link_item(
_("Discard Changes"),
url=reverse("admin:{app}_{model}_discard".format(
app=proxy_model._meta.app_label, model=proxy_model.__name__.lower()
), args=(version.pk,))
url=reverse(
f"admin:{proxy_model._meta.app_label}_{proxy_model.__name__.lower()}_discard",
args=(version.pk,)
)
)

def _get_published_page_version(self):
Expand Down
Loading

0 comments on commit 826d248

Please sign in to comment.