Skip to content

Commit

Permalink
Improve install/uninstall, add enable/disable flag, fix registry quer…
Browse files Browse the repository at this point in the history
…ying
  • Loading branch information
tschorr committed Apr 14, 2021
1 parent f95bde0 commit 6c71218
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 5 deletions.
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

0 comments on commit 6c71218

Please sign in to comment.