Commit b118fbf2 authored by Aurel's avatar Aurel

check assignment date at login if defined

add unit test for this


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18690 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c36eee74
...@@ -101,8 +101,20 @@ class ERP5UserManager(BasePlugin): ...@@ -101,8 +101,20 @@ class ERP5UserManager(BasePlugin):
try: try:
# get assignment # get assignment
assignment_list = [x for x in user.contentValues(portal_type="Assignment") if x.getValidationState() == "open"] assignment_list = [x for x in user.contentValues(portal_type="Assignment") if x.getValidationState() == "open"]
valid_assignment_list = []
# check dates if exist
login_date = DateTime()
for assignment in assignment_list:
if assignment.getStartDate() is not None and \
assignment.getStartDate() > login_date:
continue
if assignment.getStopDate() is not None and \
assignment.getStopDate() < login_date:
continue
valid_assignment_list.append(assignment)
if pw_validate(user.getPassword(), password) and \ if pw_validate(user.getPassword(), password) and \
len(assignment_list): #user.getCareerRole() == 'internal': len(valid_assignment_list): #user.getCareerRole() == 'internal':
return login, login # use same for user_id and login return login, login # use same for user_id and login
finally: finally:
setSecurityManager(sm) setSecurityManager(sm)
......
...@@ -42,6 +42,7 @@ try: ...@@ -42,6 +42,7 @@ try:
from Interface.Verify import verifyClass from Interface.Verify import verifyClass
except ImportError: except ImportError:
from zope.interface.verify import verifyClass from zope.interface.verify import verifyClass
from DateTime import DateTime
class TestUserManagement(ERP5TypeTestCase): class TestUserManagement(ERP5TypeTestCase):
"""Tests User Management in ERP5Security. """Tests User Management in ERP5Security.
...@@ -95,13 +96,16 @@ class TestUserManagement(ERP5TypeTestCase): ...@@ -95,13 +96,16 @@ class TestUserManagement(ERP5TypeTestCase):
self.failUnless(isinstance(self.getUserFolder(), self.failUnless(isinstance(self.getUserFolder(),
PluggableAuthService.PluggableAuthService)) PluggableAuthService.PluggableAuthService))
def _makePerson(self, open_assignment=1, **kw): def _makePerson(self, open_assignment=1, assignment_start_date=None,
assignment_stop_date=None, **kw):
"""Creates a person in person module, and returns the object, after """Creates a person in person module, and returns the object, after
indexing is done. """ indexing is done. """
person_module = self.getPersonModule() person_module = self.getPersonModule()
new_person = person_module.newContent( new_person = person_module.newContent(
portal_type='Person', **kw) portal_type='Person', **kw)
assignment = new_person.newContent(portal_type = 'Assignment') assignment = new_person.newContent(portal_type = 'Assignment',
start_date=assignment_start_date,
stop_date=assignment_stop_date,)
if open_assignment: if open_assignment:
assignment.open() assignment.open()
get_transaction().commit() get_transaction().commit()
...@@ -208,6 +212,30 @@ class TestUserManagement(ERP5TypeTestCase): ...@@ -208,6 +212,30 @@ class TestUserManagement(ERP5TypeTestCase):
self._assertUserDoesNotExists('the_user', 'secret') self._assertUserDoesNotExists('the_user', 'secret')
def test_AssignmentWithDate(self):
"""Tests a person with an assignment with correct date is a valid user."""
date = DateTime()
p = self._makePerson(reference='the_user', password='secret',
assignment_start_date=date-5,
assignment_stop_date=date+5)
self._assertUserExists('the_user', 'secret')
def test_AssignmentWithBadStartDate(self):
"""Tests a person with an assignment with bad start date is not a valid user."""
date = DateTime()
p = self._makePerson(reference='the_user', password='secret',
assignment_start_date=date+1,
assignment_stop_date=date+5)
self._assertUserDoesNotExists('the_user', 'secret')
def test_AssignmentWithBadStopDate(self):
"""Tests a person with an assignment with bad stop date is not a valid user."""
date = DateTime()
p = self._makePerson(reference='the_user', password='secret',
assignment_start_date=date-5,
assignment_stop_date=date-1)
self._assertUserDoesNotExists('the_user', 'secret')
class TestLocalRoleManagement(ERP5TypeTestCase): class TestLocalRoleManagement(ERP5TypeTestCase):
"""Tests Local Role Management with ERP5Security. """Tests Local Role Management with ERP5Security.
......
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