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):
try:
# get assignment
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 \
len(assignment_list): #user.getCareerRole() == 'internal':
len(valid_assignment_list): #user.getCareerRole() == 'internal':
return login, login # use same for user_id and login
finally:
setSecurityManager(sm)
......
......@@ -42,6 +42,7 @@ try:
from Interface.Verify import verifyClass
except ImportError:
from zope.interface.verify import verifyClass
from DateTime import DateTime
class TestUserManagement(ERP5TypeTestCase):
"""Tests User Management in ERP5Security.
......@@ -95,13 +96,16 @@ class TestUserManagement(ERP5TypeTestCase):
self.failUnless(isinstance(self.getUserFolder(),
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
indexing is done. """
person_module = self.getPersonModule()
new_person = person_module.newContent(
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:
assignment.open()
get_transaction().commit()
......@@ -208,6 +212,30 @@ class TestUserManagement(ERP5TypeTestCase):
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):
"""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