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

Plone 6 compatibility #34

Merged
merged 10 commits into from
Nov 3, 2023
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
11 changes: 6 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ jobs:
strategy:
matrix:
python-version:
- "3.7"
- "3.8"
- ["3.7", "py37-Plone52"]
- ["3.8", "py38-Plone52"]
- ["3.8", "py38-Plone60"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-version[0] }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python-version[0] }}
- name: Pip cache
uses: actions/cache@v2
with:
Expand All @@ -35,4 +36,4 @@ jobs:
python -m pip install --upgrade pip
python -m pip install tox
- name: Run tox
run: tox
run: tox -e ${{ matrix.python-version[1] }}
26 changes: 1 addition & 25 deletions collective/auditlog/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@
import logging


try:
from plone.app.iterate.relation import WorkingCopyRelation
except ImportError:
# Import will fail if we do not have Products.Archetypes
WorkingCopyRelation = None


logger = logging.getLogger("collective.auditlog")


Expand Down Expand Up @@ -189,24 +182,7 @@ def getLogEntry(self):
return True

if IWorkingCopy.providedBy(obj):
# if working copy, iterate, check if Track Working Copies is
# enabled
if not self.trackWorkingCopies:
# if not enabled, we only care about checked messages
if "check" not in action:
return True
# if enabled in control panel, use original object and move
# working copy path to working_copy
data["working_copy"] = "/".join(obj.getPhysicalPath())
if WorkingCopyRelation:
relationships = obj.getReferences(WorkingCopyRelation.relationship)
else:
relationships = []
# check relationships, if none, something is wrong, not logging
# action
if len(relationships) <= 0:
return True
obj = relationships[0]
return True

data.update(self._getObjectInfo(obj))
data["action"] = action
Expand Down
9 changes: 7 additions & 2 deletions collective/auditlog/asyncqueue.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from collective.auditlog import db
from collective.auditlog import td
from collective.auditlog.models import LogEntry
from Products.CMFPlone.utils import safe_unicode


try:
from plone.base.utils import safe_text
except ImportError:
# BBB Plone 5.2
from Products.CMFPlone.utils import safe_text

try:
from celery.utils.log import get_task_logger
from collective.auditlog.tasks import queue_job
Expand All @@ -28,7 +33,7 @@ def runJob(context, **data):
for key in data:
value = data[key]
if isinstance(value, str):
data[key] = safe_unicode(value)
data[key] = safe_text(value)

log = LogEntry(**data)
session.add(log)
Expand Down
9 changes: 0 additions & 9 deletions collective/auditlog/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,17 @@
try:
from plone.app.contentrules.handlers import execute
from plone.app.contentrules.handlers import execute_rules
from plone.app.contentrules.handlers import is_portal_factory
except ImportError:
from Acquisition import aq_inner
from Acquisition import aq_parent
from plone.app.contentrules.handlers import execute
from plone.app.contentrules.handlers import is_portal_factory

# copied from plone.app.iterate 2.0:

def execute_rules(event):
"""When an action is invoked on an object,
execute rules assigned to its parent.
Base action executor handler"""

if is_portal_factory(event.object):
return

execute(aq_parent(aq_inner(event.object)), event)


Expand Down Expand Up @@ -73,9 +67,6 @@ def moved_event(event):
def created_event(event):
obj = event.object

if is_portal_factory(obj):
return

if IObjectCopiedEvent.providedBy(event):
return # ignore this event since we're listening to cloned instead
if IContentish.providedBy(obj) or IComment.providedBy(obj):
Expand Down
12 changes: 10 additions & 2 deletions collective/auditlog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
def is_installed():
try:
site = getSite()
installer = get_installer(site)
try:
installer = get_installer(site)
except Exception:
return False
installed = installer.is_product_installed("collective.auditlog")
registry = queryUtility(IRegistry, context=site)
installed = (
Expand All @@ -39,7 +42,12 @@ def getUID(context):
return uid

if hasattr(context, "UID"):
return context.UID()
try:
return context.UID()
except TypeError:
# Happens when running Plone 6 code before running
# the migration steps from Plone 5 to Plone6
pass

try:
return "/".join(context.getPhysicalPath())
Expand Down
Empty file added news/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions news/33.breaking
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Complete the removal of Archetypes code: ``is_portal_factory`` and ``WorkingCopyRelation`` are gone for good.
[ale-rt]
File renamed without changes.
1 change: 1 addition & 0 deletions requirements-60.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-r https://dist.plone.org/release/6.0-latest/requirements.txt
11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
"Development Status :: 5 - Production/Stable",
"Framework :: Plone",
"Framework :: Plone :: 5.2",
"Framework :: Plone :: 6.0",
"Framework :: Plone :: Addon",
"Framework :: Zope",
"Framework :: Zope :: 4",
"Framework :: Zope :: 5",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
Expand All @@ -34,7 +38,12 @@
keywords="Plone Audit Log",
author="rain2o",
author_email="[email protected]",
url="http://svn.plone.org/svn/collective/",
url="https://github.com/collective/collective.auditlog/",
project_urls={
"PyPI": "https://pypi.org/project/collective.auditlog/",
"Source": "https://github.com/collective/collective.auditlog",
"Tracker": "https://github.com/collective/collective.auditlog/issues",
},
license="GPL",
packages=find_packages(),
namespace_packages=["collective"],
Expand Down
7 changes: 7 additions & 0 deletions test_plone60.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[buildout]
extends =
https://dist.plone.org/release/6.0-latest/versions.cfg
base.cfg

find-links +=
https://dist.plone.org/release/6.0-latest/
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[tox]
envlist =
py{37,38}-Plone{52},
py38-Plone{60},

skip_missing_interpreters = True

Expand All @@ -16,7 +17,9 @@ extras =
commands =
ln -rsf {toxinidir}/base.cfg base.cfg
Plone52: ln -rsf {toxinidir}/test_plone52.cfg buildout.cfg
Plone52: pip install -r https://dist.plone.org/release/5.2-latest/requirements.txt
Plone52: pip install -r {toxinidir}/requirements-52.txt
Plone60: ln -rsf {toxinidir}/test_plone52.cfg buildout.cfg
Plone60: pip install -r {toxinidir}/requirements-60.txt
{envbindir}/buildout buildout:develop={toxinidir} install test coverage
coverage run {envbindir}/test -v1 --auto-color --all {posargs}

Expand Down