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

Switch to modern GenericSetup install #2

Open
wants to merge 1 commit 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
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
CHANGES
=======

1.7.2 - (unrelease)
1.8 - (unrelease)
-------------------

- Switch to modern GenericSetup install

- Fix Plone 5 CSRF issues
48 changes: 0 additions & 48 deletions Products/WebServerAuth/Extensions/Install.py

This file was deleted.

24 changes: 0 additions & 24 deletions Products/WebServerAuth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,6 @@
registerDirectory('skins', globals()) # Without this, portal_skins/webserverauth shows up, but it's empty.

def initialize(context):
# If we're running under Plone, register the GenericSetup profiles that let us replace login_form:
try:
from Products.GenericSetup import EXTENSION, profile_registry
from Products.CMFPlone.interfaces import IPloneSiteRoot
except ImportError:
pass # We're not running under Plone. Let the user use the PAS plugin without all the inapplicable login_form overriding.
else:
profile_registry.registerProfile(
"default",
"WebServerAuth",
"Delegates authentication to the web server.",
"profiles/default",
product="Products.WebServerAuth",
profile_type=EXTENSION,
for_=IPloneSiteRoot)
profile_registry.registerProfile(
"uninstall",
"WebServerAuth Uninstall",
"Removes the login_form redirection.",
"profiles/uninstall",
product="Products.WebServerAuth",
profile_type=EXTENSION,
for_=IPloneSiteRoot)

context.registerClass(MultiPlugin,
permission=add_user_folders,
constructors=(manage_addWebServerAuthForm,
Expand Down
41 changes: 41 additions & 0 deletions Products/WebServerAuth/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:plone="http://namespaces.plone.org/plone"
i18n_domain="resonate">

<five:registerPackage package="." initialize=".initialize" />

<genericsetup:importStep
name="Products.WebServerAuth: install"
title="WebServerAuth: Various steps"
description="Setup handlers for WebServerAuth"
handler="Products.WebServerAuth.setuphandlers.install">
<depends name="content"/>
</genericsetup:importStep>

<genericsetup:registerProfile
name="default"
title="WebServerAuth"
description="Installs the WebServerAuth package"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<genericsetup:importStep
name="Products.WebServerAuth: uninstall"
title="WebServerAuth: Various uninstall steps"
description="Uninstall setup handlers for WebServerAuth"
handler="Products.WebServerAuth.setuphandlers.uninstall">
<depends name="content"/>
</genericsetup:importStep>

<genericsetup:registerProfile
name="uninstall"
title="WebServerAuth"
description="Uninstalls the WebServerAuth package"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

</configure>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Install WebServerAuth
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Uninstall WebServerAuth
65 changes: 65 additions & 0 deletions Products/WebServerAuth/setuphandlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Install WebServerAuth into or uninstall from a given portal.
"""

from Products.CMFCore.utils import getToolByName

from Products.PluggableAuthService.interfaces.plugins import IChallengePlugin

from Products.WebServerAuth.plugin import MultiPlugin, implementedInterfaces
from Products.WebServerAuth.utils import firstIdOfClass
from Products.WebServerAuth import zmi


def install(context):
"""
Install WebServerAuth into a given portal.
"""
if context.readDataFile('WebServerAuth-install.txt') is None:
return
portal = context.getSite()

acl_users = getToolByName(portal, 'acl_users')

# Put a WebServerAuth multiplugin in the acl_users folder, if there isn't
# one:
id = firstIdOfClass(acl_users, MultiPlugin)
if not id:
id = 'web_server_auth'
zmi.manage_addWebServerAuth(
acl_users, id, title='WebServerAuth Plugin')

# Activate it:
plugins = acl_users['plugins']
for interface in implementedInterfaces:
plugins.activatePlugin(interface, id) # plugins is a PluginRegistry

# Make the Challenge plugin the first in the list:
for i in range(list(plugins.listPluginIds(IChallengePlugin)).index(id)):
plugins.movePluginsUp(IChallengePlugin, [id])

# Set up login link:
user_actions = getToolByName(portal, 'portal_actions')['user']
user_actions['login']._updateProperty(
'url_expr',
"python:here.acl_users.web_server_auth.loginUrl(request.ACTUAL_URL)")


def uninstall(context):
"""
Uninstall WebServerAuth from a given portal.
"""
if context.readDataFile('WebServerAuth-uninstall.txt') is None:
return
portal = context.getSite()

# Delete the multiplugin instance:
acl_users = getToolByName(portal, 'acl_users')
id = firstIdOfClass(acl_users, MultiPlugin)
if id:
acl_users.manage_delObjects(ids=[id]) # implicitly deactivates

# Revert login link to its stock setting:
user_actions = getToolByName(portal, 'portal_actions')['user']
user_actions['login']._updateProperty(
'url_expr', "string:${portal_url}/login_form")
2 changes: 1 addition & 1 deletion Products/WebServerAuth/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.1
1.8