Commit 9e26d2aa authored by Rafael Monnerat's avatar Rafael Monnerat

erp5_credential: Allow create assignments with infinite duration

See merge request nexedi/erp5!1537
parents e0351d72 5fcf7ef6
......@@ -33,7 +33,7 @@
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Validation duration for assignments created from a credential (Days)</string> </value>
<value> <string>Validity duration for assignments created from a credential request, in number of days. A value of 0 means an infinite duration.</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......@@ -53,7 +53,7 @@
</item>
<item>
<key> <string>property_default</string> </key>
<value> <string>python: 3650</string> </value>
<value> <string>python: 0</string> </value>
</item>
<item>
<key> <string>write_permission</string> </key>
......
......@@ -21,7 +21,13 @@ open_assignment_list = context.CredentialRequest_closePersonAssignment(old_role_
#Initialisation
assignment_duration = context.portal_preferences.getPreferredCredentialAssignmentDuration()
today = DateTime()
delay = today+assignment_duration
if assignment_duration <= 0:
delay = None
start_date = None
else:
delay = today+assignment_duration
start_date = today - 1
current_assignment_list = {}
for assignment in open_assignment_list:
......@@ -54,7 +60,7 @@ for role in context.getRoleList():
function = context.getFunctionList(),
group = context.getGroupList(),
destination = organisation_url,
start_date = today - 1,
start_date = start_date,
stop_date = delay)
assignment.open()
......@@ -263,6 +263,18 @@ class TestERP5Credential(ERP5TypeTestCase):
self.tic()
self.logout()
def stepSetCredentialAssignmentDurationProperty(self, sequence=None):
if sequence is None:
sequence = {}
assignment_duration = sequence.get("assignment_duration",
20)
self.login()
preference = self._getPreference()
preference.edit(preferred_credential_assignment_duration=assignment_duration)
self._enablePreference()
self.tic()
self.logout()
def stepSetOrganisationCredentialUpdateAutomaticApprovalPreferences(self,
sequence=None, sequence_list=None, **kw):
self.login()
......@@ -310,6 +322,27 @@ class TestERP5Credential(ERP5TypeTestCase):
assignment = assignment_list[0]
self.assertEqual(assignment.getFunction(), assignment_function)
self.assertEqual(assignment.getRole(), assignment_role)
def stepCheckAssignmentWithoutStopDate(self, sequence):
reference = sequence["reference"]
person = self.portal.acl_users.getUser(reference).getUserValue()
assignment_list = person.objectValues(portal_type="Assignment")
self.assertEqual(len(assignment_list), 1)
assignment = assignment_list[0]
self.assertEqual(assignment.getStartDate(), None)
self.assertEqual(assignment.getStopDate(), None)
def stepCheckAssignmentWithStopDate(self, sequence):
reference = sequence["reference"]
person = self.portal.acl_users.getUser(reference).getUserValue()
assignment_list = person.objectValues(portal_type="Assignment")
self.assertEqual(len(assignment_list), 1)
assignment = assignment_list[0]
self.assertNotEqual(assignment.getStartDate(), None)
self.assertTrue(assignment.getStartDate() < DateTime())
assignment_duration = sequence['assignment_duration']
self.assertTrue(assignment.getStopDate() < DateTime()+assignment_duration)
self.assertTrue(assignment.getStopDate() > DateTime()+assignment_duration-1)
def getUserFolder(self):
"""Returns the acl_users. """
......@@ -1096,6 +1129,36 @@ class TestERP5Credential(ERP5TypeTestCase):
assignment_role="client")
self.stepCheckAssignmentAfterActiveLogin(sequence)
def testAssignmentCreationUsingSystemPreferenceDurationProperty(self):
"""
Check that the category list are used correctly to create a new
assignment
"""
sequence = dict(automatic_call=False)
self.stepSetCredentialRequestAutomaticApprovalPreferences(sequence)
self.stepSetCredentialAssignmentPropertyList()
self.stepSetCredentialAssignmentDurationProperty(
dict(assignment_duration=0))
self._createCredentialRequest()
sequence = dict(reference="barney",
assignment_function="member",
assignment_role="internal")
self.stepCheckAssignmentAfterActiveLogin(sequence)
self.stepCheckAssignmentWithoutStopDate(sequence)
category_list = ["role/client", "function/agent"]
self.stepSetCredentialAssignmentPropertyList(
dict(category_list=category_list))
assignment_duration = 20
self.stepSetCredentialAssignmentDurationProperty(
dict(assignment_duration=assignment_duration))
self._createCredentialRequest(reference="credential_user")
sequence = dict(reference="credential_user",
assignment_function="agent",
assignment_role="client",
assignment_duration=assignment_duration)
self.stepCheckAssignmentAfterActiveLogin(sequence)
self.stepCheckAssignmentWithStopDate(sequence)
def testERP5Site_activeLogin(self):
"""
Test if the script WebSection_activeLogin will create one user
......
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