Skip to content

Commit

Permalink
trigger PropertiesUpdated event when user properties are updated
Browse files Browse the repository at this point in the history
add simple test for properties updated event

make test imports consistent with existing style & re-order
  • Loading branch information
ezvirtual authored and ericof committed Nov 25, 2019
1 parent eaad89d commit ee4f778
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog
.. towncrier release notes start
6.0.2 (2019-04-29)
------------------

Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from setuptools import find_packages
import sys


version = '6.0.3.dev0'


longdescription = open("README.rst").read()
longdescription += '\n'
longdescription += open("CHANGES.rst").read()
Expand Down
19 changes: 19 additions & 0 deletions src/Products/PlonePAS/tests/test_memberdatatool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
from plone.app.testing import TEST_USER_ID as default_user
from Products.PlonePAS.tests import dummy
from Products.PlonePAS.testing import PRODUCTS_PLONEPAS_INTEGRATION_TESTING
from zope.component import getGlobalSiteManager
from zope.component import getMultiAdapter
from Products.CMFCore.interfaces import IMember
from Products.CMFCore.interfaces import IMemberData
from Products.PluggableAuthService.interfaces.events import \
IPropertiesUpdatedEvent

import unittest



class TestMemberDataTool(unittest.TestCase):

layer = PRODUCTS_PLONEPAS_INTEGRATION_TESTING
Expand Down Expand Up @@ -88,3 +93,17 @@ def testMemberDataAdapter(self):

wrapped_user = self.memberdata.wrapUser(member)
self.assertEqual(wrapped_user.__class__, MemberData)

def testPropertiesUpdatedEvent(self):

def event_handler(context, event):
self._properties_updated_handler_called = True

gsm = zope.component.getGlobalSiteManager()
gsm.registerHandler(event_handler,
(IMemberData, IPropertiesUpdatedEvent))

self._properties_updated_handler_called = False
self.addMember('ez', 'Ez Zy', 'ez@ezmail.net',
['Member'], '2018-01-01')
self.assertTrue(self._properties_updated_handler_called)
7 changes: 7 additions & 0 deletions src/Products/PlonePAS/tools/memberdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
from Products.PlonePAS.interfaces.memberdata import IMemberDataTool
from Products.PlonePAS.interfaces.plugins import IUserManagement
from Products.PlonePAS.interfaces.propertysheets import IMutablePropertySheet
from Products.PluggableAuthService.events import PropertiesUpdated
from Products.PluggableAuthService.interfaces.authservice import \
IPluggableAuthService
from Products.PluggableAuthService.interfaces.plugins import IPropertiesPlugin
from Products.PluggableAuthService.interfaces.plugins import \
IRoleAssignerPlugin
from zope.component import adapter
from zope.event import notify
from zope.interface import implementer

import six
Expand Down Expand Up @@ -275,6 +277,11 @@ def setMemberProperties(self, mapping, force_local=0, force_empty=False):
if modified:
self.notifyModified()

# Trigger PropertiesUpdated event when member properties are updated,
# excluding user login events
if set(mapping.keys()) != set(('login_time', 'last_login_time')):
notify(PropertiesUpdated(self, mapping))

def getProperty(self, id, default=_marker):
"""PAS-specific method to fetch a user's properties. Looks
through the ordered property sheets.
Expand Down

0 comments on commit ee4f778

Please sign in to comment.