Commit 0cfbc8ca authored by Jérome Perrin's avatar Jérome Perrin

Ingestion: only consider group from user login and only consider the higher group levels

parent e94ce2d1
...@@ -56,11 +56,22 @@ User would be usually the current user, but sometimes the name has to be given e ...@@ -56,11 +56,22 @@ User would be usually the current user, but sometimes the name has to be given e
if e.g. the doc is contributed by email, and the script is run by zope user.\n if e.g. the doc is contributed by email, and the script is run by zope user.\n
"""\n """\n
assignment_dict = context.ERP5Site_getPersonAssignmentDict(user_name=user_name)\n assignment_dict = context.ERP5Site_getPersonAssignmentDict(user_name=user_name)\n
group_list = assignment_dict[\'group_list\']\n
\n \n
# XXX: make list of properties configurable through preferences\n if group_list:\n
return {\'group_list\': assignment_dict[\'group_list\'],\n group_level_dict = {}\n
\'site_list\': assignment_dict[\'site_list\'],\n for group in group_list:\n
\'function_list\': assignment_dict[\'function_list\']}\n group_level = len(group.split("/"))\n
group_level_dict[group] = group_level\n
\n
#Get the highest levels groups of the assignments\n
##if group_list = [\'g1\', \'g1/g1.1\', \'g1/g1.2\'] returns [\'g1\']\n
##if group_list = [\'g1/g1.1\', \'g1/g1.2\'] returns [\'g1/g1.1\', \'g1/g1.2\']\n
highest_level_group_value = min(group_level_dict.itervalues())\n
highest_level_group_list = [k for k in group_level_dict if group_level_dict[k] == highest_level_group_value]\n
return {\'group_list\': highest_level_group_list}\n
\n
return {}\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
...@@ -187,6 +187,12 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -187,6 +187,12 @@ class TestIngestion(ERP5TypeTestCase):
,{'path' : 'group/anybody' ,{'path' : 'group/anybody'
,'title': 'Anybody' ,'title': 'Anybody'
} }
,{'path' : 'group/anybody/a1'
,'title': 'Anybody 1'
}
,{'path' : 'group/anybody/a2'
,'title': 'Anybody 2'
}
,{'path' : 'publication_section/cop' ,{'path' : 'publication_section/cop'
,'title': 'COPs' ,'title': 'COPs'
} }
...@@ -1464,9 +1470,36 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -1464,9 +1470,36 @@ class TestIngestion(ERP5TypeTestCase):
document.discoverMetadata(document.getFilename(), 'contributor1') document.discoverMetadata(document.getFilename(), 'contributor1')
self.tic() self.tic()
self.assertEqual(document.getFilename(), 'TEST-en-002.doc') self.assertEqual(document.getFilename(), 'TEST-en-002.doc')
self.assertEqual('musician/wind/saxophone', document.getFunction())
self.assertEqual('anybody', document.getGroup()) self.assertEqual('anybody', document.getGroup())
self.assertEqual('arctic/spitsbergen', document.getSite()) self.assertEqual(None, document.getFunction())
self.assertEqual(None, document.getSite())
def test_TestMetadataDiscoveryFromUserLoginHigherGroup(self):
portal = self.portal
contribution_tool = getToolByName(portal, 'portal_contributions')
user = self.createUser(reference='contributor3')
self.createUserAssignment(user, dict(group='anybody/a1',))
self.createUserAssignment(user, dict(group='anybody/a2',))
self.createUserAssignment(user, dict(group='anybody',))
other_user = self.createUser(reference='contributor2')
self.createUserAssignment(other_user, dict(group='anybody/a1',))
self.createUserAssignment(other_user, dict(group='anybody/a2',))
portal.document_module.manage_setLocalRoles('contributor2', ['Assignor',])
self.tic()
file_object = makeFileUpload('TEST-en-002.doc')
document = contribution_tool.newContent(file=file_object)
# We only consider the higher group of assignments
document.discoverMetadata(document.getFilename(), user.getReference())
self.tic()
self.assertEqual(document.getFilename(), 'TEST-en-002.doc')
self.assertEqual(['anybody'], document.getGroupList())
document.discoverMetadata(document.getFilename(), other_user.getReference())
self.assertEqual(['anybody/a1', 'anybody/a2'], document.getGroupList())
def test_IngestionConfigurationByTypeBasedMethod_usecase1(self): def test_IngestionConfigurationByTypeBasedMethod_usecase1(self):
"""How to configure meta data discovery so that each time a file """How to configure meta data discovery so that each time a file
......
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