Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
erp5
Commits
109dea6e
Commit
109dea6e
authored
Dec 23, 2011
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unify user reference verification scripts
Drop legacy code and unify/simplify the verification.
parent
56be84af
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
220 deletions
+46
-220
bt5/erp5_configurator/SkinTemplateItem/portal_skins/erp5_configurator/Base_isPersonReferenceUnique.xml
..._skins/erp5_configurator/Base_isPersonReferenceUnique.xml
+0
-124
bt5/erp5_configurator/SkinTemplateItem/portal_skins/erp5_configurator/BusinessConfiguration_validateCustomerUsername.xml
...urator/BusinessConfiguration_validateCustomerUsername.xml
+45
-4
bt5/erp5_configurator/SkinTemplateItem/portal_skins/erp5_configurator/ERP5Site_getPersonListByInsensitiveReference.xml
...igurator/ERP5Site_getPersonListByInsensitiveReference.xml
+0
-91
bt5/erp5_configurator/bt/revision
bt5/erp5_configurator/bt/revision
+1
-1
No files found.
bt5/erp5_configurator/SkinTemplateItem/portal_skins/erp5_configurator/Base_isPersonReferenceUnique.xml
deleted
100644 → 0
View file @
56be84af
<?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>
_body
</string>
</key>
<value>
<string
encoding=
"cdata"
>
<![CDATA[
"""\n
This method is to be called from remote Express instance to check\n
if in Express instance we can create a Person object with an unique \n
reference within Express services.\n
This method can also called when customer inputs its employees in Configurator.\n
This method will check as well if provided user name is a valid \n
one (doesn\'t contain reserved characters in it)\n
"""\n
request = context.REQUEST\n
portal = context.getPortalObject()\n
reference = kw.get(\'reference\', None)\n
ignore_users_from_same_instance = kw.get(\'ignore_users_from_same_instance\', 0)\n
if editor is not None:\n
# script is used as a form field\'s validator\n
reference = editor\n
\n
# get Business Configuration\n
business_configuration = context.restrictedTraverse(request.get(\'business_configuration_key\'))\n
\n
# as every instance has a hard coded \'admin\' user (owner of ERP5 Site instance)\n
# also check if reference is actually allowed (i.e. doesn\'t contain special symbols)?\n
# make sure we never allow it\n
if reference in ["admin"]:\n
return 0\n
\n
# first check if a Business Configuration has not already "reserved" it\n
# through a Person Configuration Item which when build will create a real\n
# Nexedi ERP5 account.\n
person_configurator_item_list = portal.ERP5Site_getPersonListByInsensitiveReference(\n
reference=reference,\n
portal_type=\'Person Configurator Item\')\n
\n
if business_configuration is not None:\n
# when in Configuratorm mode we the user may have created already Person Configurator Item\n
# in this business configuration. Make sure that going to Previous page will not stop\n
# validation of username uniqueness \n
# XXX: this should be done using a ZSQL Query rather than getting object\n
# there should not be a speed penalty of loading objects in RAM as in most cases\n
# it\'s either 0 (i.e. not used) or 1 (used)\n
person_configurator_item_list = filter(lambda x: x.getObject().getParentValue().getParentValue() == \n
business_configuration, \\\n
person_configurator_item_list)\n
\n
if len(person_configurator_item_list) >
0:\n
return 0\n
\n
# ... then check already created accounts\n
found_user_list = portal.ERP5Site_getPersonListByInsensitiveReference(reference=reference)\n
\n
if len(found_user_list):\n
# not unique\n
return 0\n
\n
return 1\n
]]>
</string>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
editor=None, request=None, **kw
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
Base_isPersonReferenceUnique
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
bt5/erp5_configurator/SkinTemplateItem/portal_skins/erp5_configurator/BusinessConfiguration_validateCustomerUsername.xml
View file @
109dea6e
...
...
@@ -50,16 +50,57 @@
</item>
<item>
<key>
<string>
_body
</string>
</key>
<value>
<string>
# check that customer did not enter in form repeating user names\n
<value>
<string
encoding=
"cdata"
>
<![CDATA[
# check that customer did not enter in form repeating user names\n
reference_list = REQUEST.get(\'_original_field_your_reference\', [])\n
for reference in reference_list:\n
if reference_list.count(reference) != 1:\n
# customer entered in form repeating user names\n
return 0\n
\n
# check that user name is not reserved\n
return context.Base_isPersonReferenceUnique(editor, REQUEST)\n
</string>
</value>
portal = context.getPortalObject()\n
reference = kw.get(\'reference\', None)\n
\n
if editor is not None:\n
# script is used as a form field\'s validator\n
reference = editor\n
\n
# get Business Configuration\n
business_configuration = context.restrictedTraverse(REQUEST.get(\'business_configuration_key\'))\n
\n
# ... then check already created accounts\n
if portal.portal_catalog.getResultValue(\n
reference=reference, \n
portal_type="Person") is not None:\n
return 0\n
\n
\n
# first check if a Business Configuration has not already "reserved" it\n
# through a Person Configuration Item which when build will create a real\n
# Nexedi ERP5 account.\n
person_configurator_item_list = [portal.portal_catalog.getResultValue(\n
reference=reference,\n
portal_type=\'Person Configurator Item\')]\n
\n
if business_configuration is not None:\n
# when in Configuratorm mode we the user may have created already Person Configurator Item\n
# in this business configuration. Make sure that going to Previous page will not stop\n
# validation of username uniqueness \n
# XXX: this should be done using a ZSQL Query rather than getting object\n
# there should not be a speed penalty of loading objects in RAM as in most cases\n
# it\'s either 0 (i.e. not used) or 1 (used)\n
person_configurator_item_list = filter(lambda x: x.getObject().getParentValue().getParentValue() == \n
business_configuration, \\\n
person_configurator_item_list)\n
\n
if len(person_configurator_item_list) >
0:\n
return 0\n
\n
return 1\n
]]>
</string>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
...
...
bt5/erp5_configurator/SkinTemplateItem/portal_skins/erp5_configurator/ERP5Site_getPersonListByInsensitiveReference.xml
deleted
100644 → 0
View file @
56be84af
<?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>
_body
</string>
</key>
<value>
<string
encoding=
"cdata"
>
<![CDATA[
"""\n
This script must return one Person object searching by the reference ignoring case-sensitivity.\n
"""\n
import string\n
ul=(string.upper, string.lower)\n
\n
# if we have the reference equals to \'toto\'\n
# we extract the first two caracters, in this case is \'to\' and then we generate one combination\n
# [\'to\', \'tO\', \'To\', \'TO\']\n
reference_prefix = reference[:2]\n
reference_combination_list = [\'\'.join(ul[(x>
>j)
&
1](c) for j, c in enumerate(reference_prefix)) for x in range(2**len(reference_prefix))]\n
\n
result = context.portal_catalog(portal_type=portal_type, \n
reference=[\'%s%%\' % reference_prefix for reference_prefix in reference_combination_list])\n
\n
# XXX(lucas): This can be improved, replacing by doing a binary search.\n
for person in result:\n
if person.getReference().lower() == reference.lower():\n
return [person.getObject()]\n
\n
return []\n
]]>
</string>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
reference, portal_type=[\'Person\']
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
ERP5Site_getPersonListByInsensitiveReference
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
bt5/erp5_configurator/bt/revision
View file @
109dea6e
522
\ No newline at end of file
523
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment