Commit bc67c2c4 authored by Jérome Perrin's avatar Jérome Perrin

base: ensure migrated persons have a user_id

Persons created before the introduction of ERP5 Login and user_id will only
have a user_id after migration if they were already user before migration,
otherwise they will not have a user_id and creating assignments and ERP5 Login
for this person creates a user which can not log in the system.

To make it possible for these persons to login anyway, we ensure person has a
user id when validating a login
parent 45d16764
......@@ -41,7 +41,7 @@
</chain>
<chain>
<type>ERP5 Login</type>
<workflow>edit_workflow, login_validation_workflow</workflow>
<workflow>edit_workflow, login_interaction_workflow, login_validation_workflow</workflow>
</chain>
<chain>
<type>Email</type>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="InteractionWorkflowDefinition" module="Products.ERP5.InteractionWorkflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>login_interaction_workflow</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Interaction" module="Products.ERP5.Interaction"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>interactions</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="InteractionDefinition" module="Products.ERP5.Interaction"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>activate_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>before_commit_script_name</string> </key>
<value>
<list>
<string>Workflow_ensureUserId</string>
</list>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>method_id</string> </key>
<value>
<list>
<string>validate</string>
</list>
</value>
</item>
<item>
<key> <string>once_per_transaction</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type_group_filter</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>temporary_document_disallowed</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Scripts" module="Products.DCWorkflow.Scripts"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>scripts</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
"""Make sure the user has a user id.
Persons that were created before user id were introduced may not have a user id already.
"""
user = state_change['object'].getParentValue()
  • @rafael this is the problem we discussed.

    I got confused, I thought that https://nexedijs.erp5.net/#/test_result_module/20200817-88B75137?page=form&view=view was a test result with these changes it was not.

    I see in the logs:

    2020-09-02 10:06:50,329 INFO     runTestSuite: ======================================================================
    2020-09-02 10:06:50,329 INFO     runTestSuite: FAIL: testFunctionalTestRunner (erp5.component.test.erp5_version.testFunctionalAdvancedECommerce.TestFunctionalAdvancedECommerce)
    2020-09-02 10:06:50,329 INFO     runTestSuite: ----------------------------------------------------------------------
    2020-09-02 10:06:50,329 INFO     runTestSuite: Traceback (most recent call last):
    2020-09-02 10:06:50,329 INFO     runTestSuite:   File "/srv/slapgrid/slappart0/srv/testnode/alf/soft/668ef097caecabd9e2d25a9f0f782f43/parts/erp5/product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py", line 401, in testFunctionalTestRunner
    2020-09-02 10:06:50,329 INFO     runTestSuite:     self.fail('\n'.join(error))
    2020-09-02 10:06:50,329 INFO     runTestSuite: AssertionError: test002Login
    2020-09-02 10:06:50,330 INFO     runTestSuite: test013SaleOrder
    2020-09-02 10:06:50,330 INFO     runTestSuite: test018LoyaltyPoint
    2020-09-02 10:06:50,330 INFO     runTestSuite: test019SaleWithLoyaltyPoint
    2020-09-02 10:06:50,330 INFO     runTestSuite: test020EnableDisableLoyaltyReward
    2020-09-02 10:06:50,330 INFO     runTestSuite: test021EnableDisableLoyaltyRewardOnProductView
    2020-09-02 10:06:50,330 INFO     runTestSuite: test022NoLoyaltyPointForAnonymous
    2020-09-02 10:06:50,330 INFO     runTestSuite: test023WechatPayment
    2020-09-02 10:06:50,330 INFO     runTestSuite: 
    2020-09-02 10:06:50,330 INFO     runTestSuite: ----------------------------------------------------------------------
    2020-09-02 10:06:50,330 INFO     runTestSuite: Ran 1 test in 594.126s
    2020-09-02 10:06:50,330 INFO     runTestSuite: 
    2020-09-02 10:06:50,330 INFO     runTestSuite: FAILED (failures=1)
    2020-09-02 10:06:51,335 INFO     runTestSuite: ====================
    2020-09-02 10:06:51,335 INFO     runTestSuite: ERROR ID : 1599033448.970.473923910374
    2020-09-02 10:06:51,336 INFO     runTestSuite: TRACEBACK :
    2020-09-02 10:06:51,336 INFO     runTestSuite: Traceback (innermost last):
    2020-09-02 10:06:51,336 INFO     runTestSuite:   Module Products.ERP5Type.patches.WSGIPublisher, line 270, in transaction_pubevents
    2020-09-02 10:06:51,336 INFO     runTestSuite:     tm.commit()
    2020-09-02 10:06:51,336 INFO     runTestSuite:   Module transaction._manager, line 123, in commit
    2020-09-02 10:06:51,336 INFO     runTestSuite:     return self.get().commit()
    2020-09-02 10:06:51,336 INFO     runTestSuite:   Module transaction._transaction, line 265, in commit
    2020-09-02 10:06:51,336 INFO     runTestSuite:     self._callBeforeCommitHooks()
    2020-09-02 10:06:51,337 INFO     runTestSuite:   Module transaction._transaction, line 336, in _callBeforeCommitHooks
    2020-09-02 10:06:51,337 INFO     runTestSuite:     hook(*args, **kws)
    2020-09-02 10:06:51,337 INFO     runTestSuite:   Module Products.ERP5.InteractionWorkflow, line 319, in _before_commit
    2020-09-02 10:06:51,337 INFO     runTestSuite:     self.scripts[script_name](sci)
    2020-09-02 10:06:51,337 INFO     runTestSuite:   Module Products.ERP5Type.patches.PythonScript, line 179, in __call__
    2020-09-02 10:06:51,337 INFO     runTestSuite:     return self._orig_bindAndExec(args, kw, None)
    2020-09-02 10:06:51,337 INFO     runTestSuite:   Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
    2020-09-02 10:06:51,337 INFO     runTestSuite:     return self._exec(bound_data, args, kw)
    2020-09-02 10:06:51,338 INFO     runTestSuite:   Module Products.ERP5Type.tests.ERP5TypeTestCase, line 1521, in _exec
    2020-09-02 10:06:51,338 INFO     runTestSuite:     return PythonScript_exec(self, *args)
    2020-09-02 10:06:51,338 INFO     runTestSuite:   Module Products.PythonScripts.PythonScript, line 344, in _exec
    2020-09-02 10:06:51,338 INFO     runTestSuite:     result = f(*args, **kw)
    2020-09-02 10:06:51,338 INFO     runTestSuite:   Module script, line 5, in Workflow_ensureUserId
    2020-09-02 10:06:51,338 INFO     runTestSuite:    - <PythonScript at /erp5_portal_7f1517681f85de9695ca475d69c4d66f/portal_workflow/login_interaction_workflow/scripts/Workflow_ensureUserId>
    2020-09-02 10:06:51,338 INFO     runTestSuite:    - Line 5
    2020-09-02 10:06:51,339 INFO     runTestSuite:     user = state_change['object'].getParentValue()
    2020-09-02 10:06:51,339 INFO     runTestSuite:   Module AccessControl.ZopeGuards, line 87, in guarded_getitem
    2020-09-02 10:06:51,339 INFO     runTestSuite:     if getSecurityManager().validate(object, object, None, v):
    2020-09-02 10:06:51,339 INFO     runTestSuite: Unauthorized: You are not allowed to access '2' in this context
    2020-09-02 10:06:51,339 INFO     runTestSuite: 

    for now let's revert this change.

Please register or sign in to reply
if user.getPortalType() == 'Person' and not user.hasUserId():
user.initUserId()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Workflow_ensureUserId</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Variables" module="Products.DCWorkflow.Variables"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>variables</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Worklists" module="Products.DCWorkflow.Worklists"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>worklists</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -22,6 +22,7 @@ Currency | validation_workflow
Delivery Type | base_type_interaction_workflow
Delivery Type | dynamic_class_generation_interaction_workflow
ERP5 Login | edit_workflow
ERP5 Login | login_interaction_workflow
ERP5 Login | login_validation_workflow
Email | coordinate_interaction_workflow
Email | edit_workflow
......
......@@ -9,6 +9,7 @@ document_conversion_interaction_workflow
document_security_interaction_workflow
embedded_workflow
local_permission_interaction_workflow
login_interaction_workflow
login_validation_workflow
movement_resource_interaction_workflow
notification_message_workflow
......
......@@ -5,6 +5,6 @@
</chain>
<chain>
<type>Facebook Login</type>
<workflow>edit_workflow, validation_workflow</workflow>
<workflow>edit_workflow, login_interaction_workflow, validation_workflow</workflow>
</chain>
</workflow_chain>
\ No newline at end of file
Facebook Connector | edit_workflow
Facebook Connector | validation_workflow
Facebook Login | edit_workflow
Facebook Login | login_interaction_workflow
Facebook Login | validation_workflow
\ No newline at end of file
......@@ -5,6 +5,6 @@
</chain>
<chain>
<type>Google Login</type>
<workflow>edit_workflow, validation_workflow</workflow>
<workflow>edit_workflow, login_interaction_workflow, validation_workflow</workflow>
</chain>
</workflow_chain>
\ No newline at end of file
Google Connector | edit_workflow
Google Connector | validation_workflow
Google Login | edit_workflow
Google Login | login_interaction_workflow
Google Login | validation_workflow
\ No newline at end of file
......@@ -887,6 +887,22 @@ class TestMigration(UserManagementTestCase):
self.portal.person_module.newContent,
portal_type='Person',)
def test_NonMigratedPersonCanBecomeUserLater(self):
self._enableERP5UsersPlugin()
non_migrated_person = self.portal.person_module.newContent(
portal_type='Person',
user_id=None,
)
self.tic()
self.portal.portal_templates.fixConsistency(filter={'constraint_type': 'post_upgrade'})
self.tic()
non_migrated_person.newContent(portal_type='Assignment').open()
non_migrated_person.newContent(portal_type='ERP5 Login', reference='login', password='password').validate()
self.tic()
self._assertUserExists('login', 'password')
self.assertTrue(non_migrated_person.getUserId())
class TestUserManagementExternalAuthentication(TestUserManagement):
def getTitle(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment