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

Improve installation/deinstallation and add flag to disable scanning #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Changelog
3.0.1 (unreleased)
------------------

- Nothing changed yet.
- Fix querying the registry for the case when collective.clamav is not installed,
properly remove registry settings in uninstall step.
[tschorr]
- Add a flag to enable/disable virus scanning in the configlet.
[tschorr]


3.0.0 (2021-01-25)
Expand Down
4 changes: 2 additions & 2 deletions plone-5.2.x.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ virtualenv = 20.0.35
# Error: The requirement ('pep517>=0.9') is not allowed by your [versions] constraint (0.8.2)
pep517 = 0.9.1

# Error: The requirement ('importlib-metadata>=1') is not allowed by your [versions] constraint (0.23)
importlib-metadata = 2.0.0
# Error: The requirement ('importlib-metadata>=1') is not allowed by your [versions] constraint (2.0.0)
importlib-metadata = 3.10.1
1 change: 1 addition & 0 deletions src/collective/clamav/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<i18n:registerTranslations directory="locales" />

<include file="upgrades.zcml" />
<includeDependencies package="." />

<include package=".browser" />
Expand Down
6 changes: 6 additions & 0 deletions src/collective/clamav/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class ICollectiveClamavLayer(IDefaultBrowserLayer):
class IAVScannerSettings(Interface):
""" Schema for the clamav settings
"""
clamav_enabled = schema.Bool(
title=_(u'Enable Clamav virus scanning'),
description=_(u'If set to true virus scanning will be enabled '),
default=True,
required=True)

clamav_connection = schema.Choice(
title=_(u'Connection type to clamd'),
description=_(u'Choose whether clamd is accessible through local '
Expand Down
2 changes: 1 addition & 1 deletion src/collective/clamav/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>1000</version>
<version>1001</version>
<dependencies>
</dependencies>
</metadata>
1 change: 1 addition & 0 deletions src/collective/clamav/profiles/default/propertiestool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<object name="portal_properties">
<object name="clamav_properties" meta_type="Plone Property Sheet" purge="False">
<property name="title">clamav Properties</property>
<property name="clamav_enabled" type="boolean" purge="False">True</property>
<property name="clamav_connection" type="string" purge="False">net</property>
<property name="clamav_socket" type="string" purge="False">/var/run/clamd</property>
<property name="clamav_host" type="string" purge="False">localhost</property>
Expand Down
4 changes: 4 additions & 0 deletions src/collective/clamav/profiles/uninstall/registry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<registry>
<records interface="collective.clamav.interfaces.IAVScannerSettings" remove="true" />
</registry>
6 changes: 6 additions & 0 deletions src/collective/clamav/upgrades.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
default_profile = 'profile-collective.clamav:default'


def upgrade_site(setup):
setup.runImportStepFromProfile(default_profile, 'plone.app.registry')
17 changes: 17 additions & 0 deletions src/collective/clamav/upgrades.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
i18n_domain="collective.clamav">

<genericsetup:upgradeStep
title="Add clamav_enabled property"
description="Add a boolean property to the configlet that allows to disable virus scanning."
source="1000"
destination="1001"
handler="collective.clamav.upgrades.upgrade_site"
sortkey="1"
profile="collective.clamav:default"
/>

</configure>
7 changes: 5 additions & 2 deletions src/collective/clamav/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ def _scanBuffer(buffer):
return ''

registry = getUtility(IRegistry)
settings = registry.forInterface(IAVScannerSettings) # noqa: P001
if settings is None:
try:
settings = registry.forInterface(IAVScannerSettings) # noqa: P001
except KeyError: # Product is not installed
return ''
if not settings.clamav_enabled:
return ''
scanner = getUtility(IAVScanner)

Expand Down