Beispiel #1
0
    def append_groups(self, account):
        settings = self.request.registry.settings
        use_ldap = False
        if 'pyvac.use_ldap' in settings:
            use_ldap = asbool(settings.get('pyvac.use_ldap'))
        if use_ldap:
            # update groups only for non LDAP users
            return

        exists = []
        group_ids = [int(id) for id in self.request.params.getall('groups')]

        if not group_ids:
            # ensure that account has at least user group otherwise
            # he cannot access anything
            group_ids = [Group.by_name(self.session, u'user').id]

        # only update if there is at least one group provided
        if group_ids:
            # cast as list because of iterator for will only loop on first one
            account_groups = list(account.groups)
            for group in account_groups:
                exists.append(group.id)
                if group.id not in group_ids:
                    if group.name != 'sudoer':
                        account.groups.remove(group)

            for group_id in group_ids:
                if group_id not in exists:
                    account.groups.append(Group.by_id(self.session, group_id))
Beispiel #2
0
 def setUp(self):
     super(AccountTestCase, self).setUp()
     import uuid
     from pyvac.models import User, Group, Countries
     fr_country = Countries.by_name(self.session, u'fr')
     self.account_login = unicode(uuid.uuid4())
     u = User(login=self.account_login, password=u'secret',
              _country=fr_country)
     u.groups.append(Group.by_name(self.session, u'user'))
     self.session.add(u)
     self.session.flush()
     self.account_id = u.id
     self.account_todelete = [self.account_id]
Beispiel #3
0
 def setUp(self):
     super(AccountTestCase, self).setUp()
     import uuid
     from pyvac.models import User, Group, Countries
     fr_country = Countries.by_name(self.session, u'fr')
     self.account_login = unicode(uuid.uuid4())
     u = User(login=self.account_login, password=u'secret',
              _country=fr_country)
     u.groups.append(Group.by_name(self.session, u'user'))
     self.session.add(u)
     self.session.flush()
     self.account_id = u.id
     self.account_todelete = [self.account_id]
Beispiel #4
0
    def append_groups(self, account):
        exists = []
        group_ids = [int(id) for id in self.request.params.getall('groups')]

        if not group_ids:
            group_ids = [Group.by_name(self.session, u'user').id]

        # only update if there is at least one group provided
        if group_ids:
            for group in account.groups:
                exists.append(group.id)
                if group.id not in group_ids:
                    account.groups.remove(group)

            for group_id in group_ids:
                if group_id not in exists:
                    account.groups.append(Group.by_id(self.session, group_id))
Beispiel #5
0
def setUpModule():

    engine = create_engine(settings)
    populate(engine)

    session = DBSession()
    user_group = Group.by_name(session, 'user')
    manager_group = Group.by_name(session, 'manager')
    sudoer_group = Group.by_name(session, 'sudoer')
    common_password = '******'

    cp_vacation = VacationType.by_name(session, 'CP')
    rtt_vacation = VacationType.by_name(session, 'RTT')
    recovery_vacation = VacationType.by_name(session, 'Récupération')
    sickness_vacation = VacationType.by_name(session, 'Maladie')
    exception_vacation = VacationType.by_name(session, 'Exceptionnel')

    fr_country = Countries.by_name(session, 'fr')
    us_country = Countries.by_name(session, 'us')
    lu_country = Countries.by_name(session, 'lu')

    manager1 = User(
        login='******',
        password=common_password,
        email='*****@*****.**',
        firstname='First',
        lastname='Manager',
        role='manager',
        _country=fr_country,
    )
    manager1.groups.append(manager_group)
    session.add(manager1)

    manager2 = User(
        login='******',
        password=common_password,
        email='*****@*****.**',
        firstname='Second',
        lastname='Manager',
        role='manager',
        _country=fr_country,
    )
    manager2.groups.append(manager_group)
    session.add(manager2)

    manager_us = User(
        login='******',
        password=common_password,
        email='*****@*****.**',
        firstname='Third',
        lastname='Manager',
        role='manager',
        _country=us_country,
    )
    manager_us.groups.append(manager_group)
    session.add(manager_us)

    user1 = User(
        login='******',
        password=common_password,
        email='*****@*****.**',
        manager=manager1,
        firstname='John',
        lastname='Doe',
        _country=fr_country,
        registration_number=1337,
    )
    user1.groups.append(user_group)
    session.add(user1)

    user2 = User(
        login='******',
        password=common_password,
        email='*****@*****.**',
        manager=manager2,
        firstname='Jane',
        lastname='Doe',
        _country=fr_country,
    )
    user2.groups.append(user_group)
    user2.groups.append(sudoer_group)
    session.add(user2)

    session.flush()
    sudoer = Sudoer(source_id=user2.id, target_id=1)
    session.add(sudoer)

    user3 = User(
        login='******',
        password=common_password,
        email='*****@*****.**',
        manager=manager1,
        firstname='Sarah',
        lastname='Doe',
        _country=lu_country,
    )
    user3.groups.append(user_group)
    session.add(user3)

    date_from = datetime.strptime('10/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('14/04/2015', '%d/%m/%Y')
    req1 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=cp_vacation,
                   status='PENDING',
                   user=user1,
                   notified=False)
    session.add(req1)

    date_from = datetime.strptime('10/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('21/04/2015', '%d/%m/%Y')
    req2 = Request(
        date_from=date_from,
        date_to=date_to,
        days=10,
        vacation_type=cp_vacation,
        status='PENDING',
        user=user2,
        notified=False,
    )
    session.add(req2)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req3 = Request(
        date_from=date_from,
        date_to=date_to,
        days=5,
        vacation_type=rtt_vacation,
        status='ACCEPTED_MANAGER',
        user=user1,
        notified=True,
    )
    session.add(req3)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req4 = Request(
        date_from=date_from,
        date_to=date_to,
        days=5,
        vacation_type=rtt_vacation,
        status='CANCELED',
        user=user1,
        notified=True,
    )
    session.add(req4)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req5 = Request(
        date_from=date_from,
        date_to=date_to,
        days=5,
        vacation_type=rtt_vacation,
        status='APPROVED_ADMIN',
        user=manager_us,
        notified=True,
    )
    session.add(req5)

    date_from = datetime.strptime('24/08/2011', '%d/%m/%Y')
    date_to = datetime.strptime('24/08/2011', '%d/%m/%Y')
    req6 = Request(date_from=date_from,
                   date_to=date_to,
                   days=0.5,
                   vacation_type=rtt_vacation,
                   status='APPROVED_ADMIN',
                   user=user1,
                   notified=True,
                   label='AM')
    session.add(req6)

    date_from = datetime.strptime('14/07/2014', '%d/%m/%Y')
    date_to = datetime.strptime('14/07/2014', '%d/%m/%Y')
    req7 = Request(date_from=date_from,
                   date_to=date_to,
                   days=0.5,
                   vacation_type=rtt_vacation,
                   status='APPROVED_ADMIN',
                   user=user1,
                   notified=True,
                   label='AM')
    session.add(req7)

    # used for rtt vacation checks

    date_from = datetime.strptime('01/04/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/04/2016', '%d/%m/%Y')
    req8 = Request(date_from=date_from,
                   date_to=date_to,
                   days=1,
                   vacation_type=rtt_vacation,
                   status='PENDING',
                   user=user1,
                   notified=True)
    session.add(req8)

    date_from = datetime.strptime('01/03/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/03/2016', '%d/%m/%Y')
    req9 = Request(date_from=date_from,
                   date_to=date_to,
                   days=1,
                   vacation_type=rtt_vacation,
                   status='ACCEPTED_MANAGER',
                   user=user1,
                   notified=True)
    session.add(req9)

    date_from = datetime.strptime('01/02/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/02/2016', '%d/%m/%Y')
    req10 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=rtt_vacation,
                    status='APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req10)

    date_from = datetime.strptime('01/06/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/06/2016', '%d/%m/%Y')
    req11 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=recovery_vacation,
                    status='APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req11)

    date_from = datetime.strptime('12/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('12/04/2015', '%d/%m/%Y')
    req12 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=rtt_vacation,
                    status='DENIED',
                    user=user1,
                    notified=True)
    session.add(req12)

    date_from = datetime.strptime('06/06/2016', '%d/%m/%Y')
    date_to = datetime.strptime('06/06/2016', '%d/%m/%Y')
    req13 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=sickness_vacation,
                    status='APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req13)

    date_from = datetime.strptime('13/06/2016', '%d/%m/%Y')
    date_to = datetime.strptime('13/06/2016', '%d/%m/%Y')
    req14 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=exception_vacation,
                    status='APPROVED_ADMIN',
                    user=user2,
                    message="I need to see Star Wars, I'm a huge fan",
                    notified=True)
    session.add(req14)

    session.commit()
Beispiel #6
0
 def test_by_name(self):
     from pyvac.models import Group
     grp = Group.by_name(self.session, u'admin')
     self.assertIsInstance(grp, Group)
     self.assertEqual(grp.name, u'admin')
Beispiel #7
0
def setUpModule():

    engine = create_engine(settings)
    populate(engine)

    session = DBSession()
    user_group = Group.by_name(session, u'user')
    manager_group = Group.by_name(session, u'manager')
    sudoer_group = Group.by_name(session, u'sudoer')
    common_password = u'changeme'

    cp_vacation = VacationType.by_name(session, u'CP')
    rtt_vacation = VacationType.by_name(session, u'RTT')
    recovery_vacation = VacationType.by_name(session, u'Récupération')
    sickness_vacation = VacationType.by_name(session, u'Maladie')
    exception_vacation = VacationType.by_name(session, u'Exceptionnel')

    fr_country = Countries.by_name(session, u'fr')
    us_country = Countries.by_name(session, u'us')

    manager1 = User(login=u'manager1',
                    password=common_password,
                    email=u'*****@*****.**',
                    firstname=u'First',
                    lastname=u'Manager',
                    role=u'manager',
                    _country=fr_country,
                    )
    manager1.groups.append(manager_group)
    session.add(manager1)

    manager2 = User(login=u'manager2',
                    password=common_password,
                    email=u'*****@*****.**',
                    firstname=u'Second',
                    lastname=u'Manager',
                    role=u'manager',
                    _country=fr_country,
                    )
    manager2.groups.append(manager_group)
    session.add(manager2)

    manager_us = User(login=u'manager3',
                      password=common_password,
                      email=u'*****@*****.**',
                      firstname=u'Third',
                      lastname=u'Manager',
                      role=u'manager',
                      _country=us_country,
                      )
    manager_us.groups.append(manager_group)
    session.add(manager_us)

    user1 = User(login=u'jdoe',
                 password=common_password,
                 email=u'*****@*****.**',
                 manager=manager1,
                 firstname=u'John',
                 lastname=u'Doe',
                 _country=fr_country,
                 )
    user1.groups.append(user_group)
    session.add(user1)

    user2 = User(login=u'janedoe',
                 password=common_password,
                 email=u'*****@*****.**',
                 manager=manager2,
                 firstname=u'Jane',
                 lastname=u'Doe',
                 _country=fr_country,
                 )
    user2.groups.append(user_group)
    user2.groups.append(sudoer_group)
    session.add(user2)

    session.flush()
    sudoer = Sudoer(source_id=user2.id, target_id=1)
    session.add(sudoer)

    date_from = datetime.strptime('10/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('14/04/2015', '%d/%m/%Y')
    req1 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=cp_vacation,
                   status=u'PENDING',
                   user=user1,
                   notified=False)
    session.add(req1)

    date_from = datetime.strptime('10/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('21/04/2015', '%d/%m/%Y')
    req2 = Request(date_from=date_from,
                   date_to=date_to,
                   days=10,
                   vacation_type=cp_vacation,
                   status=u'PENDING',
                   user=user2,
                   notified=False,)
    session.add(req2)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req3 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=rtt_vacation,
                   status=u'ACCEPTED_MANAGER',
                   user=user1,
                   notified=True,)
    session.add(req3)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req4 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=rtt_vacation,
                   status=u'CANCELED',
                   user=user1,
                   notified=True,)
    session.add(req4)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req5 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=rtt_vacation,
                   status=u'APPROVED_ADMIN',
                   user=manager_us,
                   notified=True,)
    session.add(req5)

    date_from = datetime.strptime('24/08/2011', '%d/%m/%Y')
    date_to = datetime.strptime('24/08/2011', '%d/%m/%Y')
    req6 = Request(date_from=date_from,
                   date_to=date_to,
                   days=0.5,
                   vacation_type=rtt_vacation,
                   status=u'APPROVED_ADMIN',
                   user=user1,
                   notified=True,
                   label=u'AM')
    session.add(req6)

    date_from = datetime.strptime('14/07/2014', '%d/%m/%Y')
    date_to = datetime.strptime('14/07/2014', '%d/%m/%Y')
    req7 = Request(date_from=date_from,
                   date_to=date_to,
                   days=0.5,
                   vacation_type=rtt_vacation,
                   status=u'APPROVED_ADMIN',
                   user=user1,
                   notified=True,
                   label=u'AM')
    session.add(req7)

    # used for rtt vacation checks

    date_from = datetime.strptime('01/04/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/04/2016', '%d/%m/%Y')
    req8 = Request(date_from=date_from,
                   date_to=date_to,
                   days=1,
                   vacation_type=rtt_vacation,
                   status=u'PENDING',
                   user=user1,
                   notified=True)
    session.add(req8)

    date_from = datetime.strptime('01/03/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/03/2016', '%d/%m/%Y')
    req9 = Request(date_from=date_from,
                   date_to=date_to,
                   days=1,
                   vacation_type=rtt_vacation,
                   status=u'ACCEPTED_MANAGER',
                   user=user1,
                   notified=True)
    session.add(req9)

    date_from = datetime.strptime('01/02/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/02/2016', '%d/%m/%Y')
    req10 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=rtt_vacation,
                    status=u'APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req10)

    date_from = datetime.strptime('01/06/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/06/2016', '%d/%m/%Y')
    req11 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=recovery_vacation,
                    status=u'APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req11)

    date_from = datetime.strptime('12/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('12/04/2015', '%d/%m/%Y')
    req12 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=rtt_vacation,
                    status=u'DENIED',
                    user=user1,
                    notified=True)
    session.add(req12)

    date_from = datetime.strptime('06/06/2016', '%d/%m/%Y')
    date_to = datetime.strptime('06/06/2016', '%d/%m/%Y')
    req13 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=sickness_vacation,
                    status=u'APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req13)

    date_from = datetime.strptime('13/06/2016', '%d/%m/%Y')
    date_to = datetime.strptime('13/06/2016', '%d/%m/%Y')
    req14 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=exception_vacation,
                    status=u'APPROVED_ADMIN',
                    user=user2,
                    message=u"I need to see Star Wars, I'm a huge fan",
                    notified=True)
    session.add(req14)

    session.commit()
Beispiel #8
0
 def test_by_name(self):
     from pyvac.models import Group
     grp = Group.by_name(self.session, u'admin')
     self.assertIsInstance(grp, Group)
     self.assertEqual(grp.name, u'admin')
Beispiel #9
0
def setUpModule():

    engine = create_engine(settings)
    populate(engine)

    session = DBSession()
    user_group = Group.by_name(session, u'user')
    manager_group = Group.by_name(session, u'manager')
    common_password = u'changeme'

    cp_vacation = VacationType.by_name(session, u'CP')
    rtt_vacation = VacationType.by_name(session, u'RTT')

    fr_country = Countries.by_name(session, u'fr')
    us_country = Countries.by_name(session, u'us')

    manager1 = User(login=u'manager1',
                    password=common_password,
                    email=u'*****@*****.**',
                    firstname=u'First',
                    lastname=u'Manager',
                    role=u'manager',
                    _country=fr_country,
                    )
    manager1.groups.append(manager_group)
    session.add(manager1)

    manager2 = User(login=u'manager2',
                    password=common_password,
                    email=u'*****@*****.**',
                    firstname=u'Second',
                    lastname=u'Manager',
                    role=u'manager',
                    _country=fr_country,
                    )
    manager2.groups.append(manager_group)
    session.add(manager2)

    manager_us = User(login=u'manager3',
                      password=common_password,
                      email=u'*****@*****.**',
                      firstname=u'Third',
                      lastname=u'Manager',
                      role=u'manager',
                      _country=us_country,
                      )
    manager_us.groups.append(manager_group)
    session.add(manager_us)

    user1 = User(login=u'jdoe',
                 password=common_password,
                 email=u'*****@*****.**',
                 manager=manager1,
                 firstname=u'John',
                 lastname=u'Doe',
                 _country=fr_country,
                 )
    user1.groups.append(user_group)
    session.add(user1)

    user2 = User(login=u'janedoe',
                 password=common_password,
                 email=u'*****@*****.**',
                 manager=manager2,
                 firstname=u'Jane',
                 lastname=u'Doe',
                 _country=fr_country,
                 )
    user2.groups.append(user_group)
    session.add(user2)

    date_from = datetime.strptime('10/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('14/04/2015', '%d/%m/%Y')
    req1 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=cp_vacation,
                   status=u'PENDING',
                   user=user1,
                   notified=False)
    session.add(req1)

    date_from = datetime.strptime('10/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('21/04/2015', '%d/%m/%Y')
    req2 = Request(date_from=date_from,
                   date_to=date_to,
                   days=10,
                   vacation_type=cp_vacation,
                   status=u'PENDING',
                   user=user2,
                   notified=False,)
    session.add(req2)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req3 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=rtt_vacation,
                   status=u'ACCEPTED_MANAGER',
                   user=user1,
                   notified=True,)
    session.add(req3)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req4 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=rtt_vacation,
                   status=u'CANCELED',
                   user=user1,
                   notified=True,)
    session.add(req4)

    date_from = datetime.strptime('24/04/2015', '%d/%m/%Y')
    date_to = datetime.strptime('28/04/2015', '%d/%m/%Y')
    req5 = Request(date_from=date_from,
                   date_to=date_to,
                   days=5,
                   vacation_type=rtt_vacation,
                   status=u'APPROVED_ADMIN',
                   user=manager_us,
                   notified=True,)
    session.add(req5)

    date_from = datetime.strptime('24/08/2011', '%d/%m/%Y')
    date_to = datetime.strptime('24/08/2011', '%d/%m/%Y')
    req6 = Request(date_from=date_from,
                   date_to=date_to,
                   days=0.5,
                   vacation_type=rtt_vacation,
                   status=u'APPROVED_ADMIN',
                   user=user1,
                   notified=True,
                   label=u'AM')
    session.add(req6)

    date_from = datetime.strptime('14/07/2014', '%d/%m/%Y')
    date_to = datetime.strptime('14/07/2014', '%d/%m/%Y')
    req7 = Request(date_from=date_from,
                   date_to=date_to,
                   days=0.5,
                   vacation_type=rtt_vacation,
                   status=u'APPROVED_ADMIN',
                   user=user1,
                   notified=True,
                   label=u'AM')
    session.add(req7)

    # used for rtt vacation checks

    date_from = datetime.strptime('01/04/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/04/2016', '%d/%m/%Y')
    req8 = Request(date_from=date_from,
                   date_to=date_to,
                   days=1,
                   vacation_type=rtt_vacation,
                   status=u'PENDING',
                   user=user1,
                   notified=True)
    session.add(req8)

    date_from = datetime.strptime('01/03/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/03/2016', '%d/%m/%Y')
    req9 = Request(date_from=date_from,
                   date_to=date_to,
                   days=1,
                   vacation_type=rtt_vacation,
                   status=u'ACCEPTED_MANAGER',
                   user=user1,
                   notified=True)
    session.add(req9)

    date_from = datetime.strptime('01/02/2016', '%d/%m/%Y')
    date_to = datetime.strptime('02/02/2016', '%d/%m/%Y')
    req10 = Request(date_from=date_from,
                    date_to=date_to,
                    days=1,
                    vacation_type=rtt_vacation,
                    status=u'APPROVED_ADMIN',
                    user=user1,
                    notified=True)
    session.add(req10)

    session.commit()