Exemplo n.º 1
0
    def update_view(self, model, view):
        settings = self.request.registry.settings
        ldap = False
        if 'pyvac.use_ldap' in settings:
            ldap = asbool(settings.get('pyvac.use_ldap'))

        if view['errors']:
            self.request.session.flash('error;%s' % ','.join(view['errors']))

        view['groups'] = Group.all(self.session, order_by=Group.name)
        view['managers'] = User.by_role(self.session, 'manager')

        if ldap:
            ldap = LdapCache()
            login = self.get_model().login
            if login:
                view['ldap_user'] = ldap.search_user_by_login(login)
            else:
                view['ldap_user'] = {}
            view['managers'] = ldap.list_manager()
            view['units'] = ldap.list_ou()
            view['countries'] = Countries.all(self.session,
                                              order_by=Countries.name)
            # generate a random password for the user, he must change it later
            password = randomstring()
            log.info('temporary password generated: %s' % password)
            view['password'] = password
            view['view_name'] = self.__class__.__name__.lower()
            view['myself'] = (self.user.id == self.get_model().id)
Exemplo n.º 2
0
    def update_view(self, model, view):
        settings = self.request.registry.settings
        ldap = False
        if 'pyvac.use_ldap' in settings:
            ldap = asbool(settings.get('pyvac.use_ldap'))

        if view['errors']:
            self.request.session.flash('error;%s' % ','.join(view['errors']))

        view['groups'] = Group.all(self.session, order_by=Group.name)
        view['managers'] = User.by_role(self.session, 'manager')
        view['countries'] = Countries.all(self.session,
                                          order_by=Countries.name)
        if ldap:
            ldap = LdapCache()
            login = self.get_model().login
            view['ldap_user'] = {}
            if login:
                try:
                    view['ldap_user'] = ldap.search_user_by_login(login)
                except UnknownLdapUser:
                    msg = 'Unknown ldap user %s' % login
                    self.request.session.flash('error;%s' % msg)

            view['managers'] = ldap.list_manager()
            view['units'] = ldap.list_ou()

            view['teams'] = ldap.list_teams()
            uteams = {}
            for team, members in view['teams'].iteritems():
                for member in members:
                    uteams.setdefault(member, []).append(team)
            view['user_teams'] = uteams.get(view['ldap_user'].get('dn'), [])

            # generate a random password for the user, he must change it later
            password = randomstring()
            log.debug('temporary password generated: %s' % password)
            view['password'] = password
            view['view_name'] = self.__class__.__name__.lower()
            view['myself'] = (self.user.id == self.get_model().id)

            jpeg = view['ldap_user'].get('jpegPhoto')
            if jpeg:
                view['ldap_user']['photo'] = base64.b64encode(jpeg)

        partial_time_tooltip = """\
This value will be used to compute how much RTT you will acquire.
Example: If you use 2/5, you will acquire 0.4 RTT instead of 1 RTT.

This has no effect on CP acquisition.
"""
        view['partial_time_tooltip'] = partial_time_tooltip
Exemplo n.º 3
0
    def update_view(self, model, view):
        settings = self.request.registry.settings
        ldap = False
        if 'pyvac.use_ldap' in settings:
            ldap = asbool(settings.get('pyvac.use_ldap'))

        if view['errors']:
            self.request.session.flash('error;%s' % ','.join(view['errors']))

        view['groups'] = Group.all(self.session, order_by=Group.name)
        view['managers'] = User.by_role(self.session, 'manager')

        if ldap:
            ldap = LdapCache()
            login = self.get_model().login
            view['ldap_user'] = {}
            if login:
                try:
                    view['ldap_user'] = ldap.search_user_by_login(login)
                except UnknownLdapUser:
                    msg = 'Unknown ldap user %s' % login
                    self.request.session.flash('error;%s' % msg)

            view['managers'] = ldap.list_manager()
            view['units'] = ldap.list_ou()

            view['teams'] = ldap.list_teams()
            uteams = {}
            for team, members in view['teams'].iteritems():
                for member in members:
                    uteams.setdefault(member, []).append(team)
            view['user_teams'] = uteams.get(view['ldap_user'].get('dn'), [])

            view['countries'] = Countries.all(self.session,
                                              order_by=Countries.name)
            # generate a random password for the user, he must change it later
            password = randomstring()
            log.debug('temporary password generated: %s' % password)
            view['password'] = password
            view['view_name'] = self.__class__.__name__.lower()
            view['myself'] = (self.user.id == self.get_model().id)
Exemplo n.º 4
0
    def save_model(self, account):
        super(Edit, self).update_model(account)
        self.set_country(account)
        self.append_groups(account)

        r = self.request
        arrival_date = account.arrival_date
        if 'arrival_date' in r.params and r.params['arrival_date']:
            # cast to datetime
            arrival_date = datetime.strptime(r.params['arrival_date'],
                                             '%d/%m/%Y')

        if not account.pools and arrival_date:
            self.assign_pools(account)
        self.update_userpool(account)

        if 'disable_rtt' in self.request.params:
            account.add_feature('disable_rtt', save=True)
        else:
            account.del_feature('disable_rtt', save=True)

        settings = self.request.registry.settings
        ldap = False
        if 'pyvac.use_ldap' in settings:
            ldap = asbool(settings.get('pyvac.use_ldap'))

        if ldap:
            # update in ldap

            password = None
            if 'user.password' in r.params and r.params['user.password']:
                password = [hashPassword(r.params['user.password'])]

            unit = None
            if 'unit' in r.params and r.params['unit']:
                unit = r.params['unit']

            arrival_date = None
            if 'arrival_date' in r.params and r.params['arrival_date']:
                # cast to datetime
                arrival_date = datetime.strptime(r.params['arrival_date'],
                                                 '%d/%m/%Y')
            uid = None
            if 'user.uid' in r.params and r.params['user.uid']:
                uid = r.params['user.uid']

            if (r.params.get('remove_photo', 'no') == 'yes'):
                photo = ''
            else:
                try:
                    r.params['photofile'].file.seek(0)
                    photo = r.params['photofile'].file.read()
                except:
                    photo = None

            if photo:
                log.info('uploading photo size: %d' % len(photo))

            mobile = None
            if 'mobile' in r.params:
                mobile = r.params['mobile']

            ldap = LdapCache()
            try:
                ldap.search_user_by_login(account.login)
                ldap.update_user(account,
                                 password=password,
                                 unit=unit,
                                 arrival_date=arrival_date,
                                 uid=uid,
                                 photo=photo,
                                 mobile=mobile)
            except UnknownLdapUser:
                pass

            # only for admins
            if self.user.is_admin:
                # update teams
                uteams = {}
                for team, members in list(ldap.list_teams().items()):
                    for member in members:
                        uteams.setdefault(member, []).append(team)
                user_teams = uteams.get(account.dn, [])

                # add to new teams
                for team in r.params.getall('teams'):
                    members = ldap.get_team_members(team)
                    if account.dn not in members:
                        members.append(account.dn.encode('utf-8'))
                        ldap.update_team(team, members)

                # remove from old teams
                for team in user_teams:
                    if team not in r.params.getall('teams'):
                        members = ldap.get_team_members(team)
                        if account.dn in members:
                            members.remove(account.dn)
                        ldap.update_team(team, members)

                # update role for user in LDAP
                old_role = account.role
                if 'ldap_role' in r.params:
                    new_role = r.params['ldap_role']
                    if old_role != new_role:
                        log.info('LDAP role changed: %s -> %s' %
                                 (old_role, new_role))
                        if new_role == 'manager':
                            ldap.add_manager(account.dn)
                        elif old_role == 'manager':
                            ldap.remove_manager(account.dn)
                        if new_role == 'admin':
                            ldap.add_admin(account.dn)
                        elif old_role == 'admin':
                            ldap.remove_admin(account.dn)

        if self.user and not self.user.is_admin:
            self.redirect_route = 'list_request'