Skip to content

Commit

Permalink
When creating CAS plugin, load values from registry. This handles the…
Browse files Browse the repository at this point in the history
… use case of when the CAS plugin is being re-created.
  • Loading branch information
davidjb committed May 4, 2012
1 parent f56f564 commit f2b32b3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/collective/castle/control_panel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from StringIO import StringIO

from zope.component import adapter
from zope.component import adapter, getUtility
from zope.schema import getFields
from zope.app.component.hooks import getSite

Expand All @@ -10,7 +10,9 @@
from Products.statusmessages.interfaces import IStatusMessage

from plone.app.registry.browser import controlpanel
from plone.registry.interfaces import IRecordModifiedEvent
from plone.registry.interfaces import IRecordModifiedEvent, IRegistry

from Products.CAS4PAS.CASAuthHelper import CASAuthHelper

from collective.castle.interfaces import ICAS4PASPluginSchema

Expand All @@ -25,10 +27,17 @@ def updateCASSettings(settings, event):
cas4pas.addCASAuthHelper('cas', 'CAS Auth Helper')
cas = acl_users['cas']

registry = getUtility(IRegistry)
casSettings = registry.forInterface(ICAS4PASPluginSchema)

#Load defaults from fields
fields = getFields(ICAS4PASPluginSchema)
for field in fields:
setattr(cas, field, fields[field].default)
#Only set attributes the PAS plugin knows about
if hasattr(CASAuthHelper, field):
#Set from registry settings, which will pick up defaults
value = getattr(casSettings, field)
setattr(cas, field, value)

out = StringIO()
activatePluginInterfaces(portal, 'cas', out)
Expand All @@ -37,8 +46,10 @@ def updateCASSettings(settings, event):
else:
cas = cas_auth_helpers[0]

#Proxy the changed value to the CAS4PAS helper
setattr(cas, event.record.fieldName, event.newValue)
fieldName = event.record.fieldName
if hasattr(CASAuthHelper, fieldName):
#Proxy the changed value to the CAS4PAS helper if applicable
setattr(cas, fieldName, event.newValue)

class CASSettingsEditForm(controlpanel.RegistryEditForm):

Expand Down

0 comments on commit f2b32b3

Please sign in to comment.