def remember(self, result): """remember user as valid result is authomatic result data. """ do_notify_created = False # lookup user by useridentities = self.lookup_identities(result) if useridentities is None: # new/unknown user useridentities = self.remember_identity(result) do_notify_created = True logger.info('New User: {0}'.format(useridentities.userid)) else: useridentities.update_userdata(result) logger.info('Updated Userdata: {0}'.format(useridentities.userid)) # login (get new security manager) logger.info('Login User: {0}'.format(useridentities.userid)) aclu = api.portal.get_tool('acl_users') user = aclu._findUser(aclu.plugins, useridentities.userid) accessed, container, name, value = aclu._getObjectContext( self.REQUEST['PUBLISHED'], self.REQUEST) user = aclu._authorizeUser(user, accessed, container, name, value, _noroles) if do_notify_created: # be a good citizen in PAS world and notify user creation notify(PrincipalCreated(user)) # do login post-processing self.REQUEST['__ac_password'] = useridentities.secret mt = api.portal.get_tool('portal_membership') logger.info('Login Postprocessing: {0}'.format(useridentities.userid)) mt.loginUser(self.REQUEST)
def test_user_created(self): event = PrincipalCreated('foo') with LogCapture('collective.fingerpointing', level=INFO) as log: notify(event) log.check( ('collective.fingerpointing', 'INFO', 'user=test_user_1_ ip=None action=create principal=foo' ), # noqa: E501 )
def test_susbcriber_ignored_when_package_not_installed(self): # authentication events should not raise errors # if package is not installed self.uninstall() # BBB: QI compatibility event = UserLoggedInEvent(self.request) notify(event) event = UserLoggedOutEvent(self.request) notify(event) event = PrincipalCreated('foo') notify(event) event = PrincipalDeleted('foo') notify(event)
def test_default_personalportlet_created_for_new_user(self): col = getUtility(IPortletManager, name='plone.rightcolumn') user_portlets = col[USER_CATEGORY] self.failIf('fakeuser' in user_portlets) # This would normally happen when a user is created notify(PrincipalCreated(PropertiedUser('fakeuser'))) # We would expect some portlets to have been created after the # event handler has finished processing self.failUnless('fakeuser' in user_portlets) self.assertEqual(len(user_portlets['fakeuser']), 1)
def test_default_dashboard_created_for_new_user(self): col = getUtility(IPortletManager, name='plone.dashboard1') user_portlets = col[USER_CATEGORY] self.assertFalse('fakeuser' in user_portlets) # This would normally happen when a user is created notify(PrincipalCreated(PropertiedUser('fakeuser'))) # We would expect some portlets to have been created after the # event handler has finished processing self.assertTrue('fakeuser' in user_portlets) self.assertTrue(len(user_portlets['fakeuser']) > 0)
def test_susbcriber_ignored_when_package_not_installed(self): # authentication events should not raise errors # if package is not installed portal = self.layer['portal'] qi = portal['portal_quickinstaller'] with api.env.adopt_roles(['Manager']): qi.uninstallProducts(products=[PROJECTNAME]) event = UserLoggedInEvent(self.request) notify(event) event = UserLoggedOutEvent(self.request) notify(event) event = PrincipalCreated('foo') notify(event) event = PrincipalDeleted('foo') notify(event)
def remember(self, result): """remember user as valid result is authomatic result data. """ # first fetch provider specific user-data result.user.update() do_notify_created = False # lookup user by useridentities = self.lookup_identities(result) if useridentities is None: # new/unknown user useridentities = self.remember_identity(result) do_notify_created = True logger.info(f"New User: {useridentities.userid}") else: useridentities.update_userdata(result) logger.info(f"Updated Userdata: {useridentities.userid}") # login (get new security manager) logger.info(f"Login User: {useridentities.userid}") aclu = api.portal.get_tool("acl_users") user = aclu._findUser(aclu.plugins, useridentities.userid) accessed, container, name, value = aclu._getObjectContext( self.REQUEST["PUBLISHED"], self.REQUEST) # Add the user to the SM stack aclu._authorizeUser(user, accessed, container, name, value, _noroles) if do_notify_created: # be a good citizen in PAS world and notify user creation notify(PrincipalCreated(user)) # do login post-processing self.REQUEST["__ac_password"] = useridentities.secret mt = api.portal.get_tool("portal_membership") logger.info(f"Login Postprocessing: {useridentities.userid}") mt.loginUser(self.REQUEST)