Ejemplo n.º 1
0
    def update_user(self):
        # checks the other fields and updates data
        if super(UserLineEditor, self).commit((), ('corporation_id', 'direction_id', 'site_id', 'service_id', 'fi_uid', 'enabled')):

            # FIXME: use the OrganizationRepository
            get_orga = lambda id: OrganizationData.get(
                id) if id != -1 else None

            u = self.user_repository.get_by_uid(self.uid)
            u.corporation = get_orga(self.corporation_id())
            u.direction = get_orga(self.direction_id())
            u.service = get_orga(self.service_id())
            u.site = get_orga(self.site_id())
            u.subsite = get_orga(self.subsite_id())
            u.enabled = self.enabled()
            u.fi_uid = self.fi_uid()

            session.flush()

            self.orig_corp_id = u.corporation_id or -1L
            self.orig_dir_id = u.direction_id or -1L
            self.orig_service_id = u.service_id or -1L
            self.orig_site_id = u.site_id or -1L
            self.orig_subsite_id = u.subsite_id or -1L
            self.orig_enabled = u.enabled
            self.orig_fi_uid = u.fi_uid

            flashmessage.set_flash(_(u'User modified'))

            return True
Ejemplo n.º 2
0
    def update_user(self):
        # checks the other fields and updates data
        if super(UserLineEditor, self).commit(
            (), ('corporation_id', 'direction_id', 'site_id', 'service_id',
                 'fi_uid', 'enabled')):

            # FIXME: use the OrganizationRepository
            get_orga = lambda id: OrganizationData.get(id
                                                       ) if id != -1 else None

            u = self.user_repository.get_by_uid(self.uid)
            u.corporation = get_orga(self.corporation_id())
            u.direction = get_orga(self.direction_id())
            u.service = get_orga(self.service_id())
            u.site = get_orga(self.site_id())
            u.subsite = get_orga(self.subsite_id())
            u.enabled = self.enabled()
            u.fi_uid = self.fi_uid()

            session.flush()

            self.orig_corp_id = u.corporation_id or -1L
            self.orig_dir_id = u.direction_id or -1L
            self.orig_service_id = u.service_id or -1L
            self.orig_site_id = u.site_id or -1L
            self.orig_subsite_id = u.subsite_id or -1L
            self.orig_enabled = u.enabled
            self.orig_fi_uid = u.fi_uid

            flashmessage.set_flash(_(u'User modified'))

            return True
Ejemplo n.º 3
0
    def commit(self):
        if not super(UserEditor, self).commit(
                (),
                ('login', 'email', 'roles', 'fi_uid', 'work_phone',
                 'mobile_phone', 'firstname', 'lastname', 'position',
                 'corporation_id', 'direction_id', 'site_id', 'service_id')):
            return False

        # FIXME: use the OrganizationRepository
        get_organization = lambda id: OrganizationData.get(
            id) if id != -1 else None

        corporation = get_organization(self.corporation_id.value)
        direction = get_organization(self.direction_id.value)
        service = get_organization(self.service_id.value)
        site = get_organization(self.site_id.value)
        subsite = get_organization(self.subsite_id.value)
        facilitator = self.user_repository.get_by_uid(self.fi_uid.value)

        # create or update the user
        updates = dict(
            email=self.email.value,
            firstname=self.firstname.value,
            lastname=self.lastname.value,
            enabled=self.enabled.value,
            position=self.position.value,
            corporation=corporation,
            direction=direction,
            service=service,
            site=site,
            incorporated=self.incorporated.value,
            work_phone=self.work_phone.value,
            mobile_phone=self.mobile_phone.value,
            fi=facilitator,
            subsite=subsite,
        )

        if self.user:
            u = self.user
            u.set(**updates)
        else:
            u = self.user_repository.create(uid=self.login.value, **updates)
            password = u.reset_password()
            u.send_welcome_email(password)

        # roles
        for role in self.assignable_roles:
            if role in self.roles():
                u.add_role(role)
            else:
                u.remove_role(role)

        return True
Ejemplo n.º 4
0
    def commit(self):
        if not super(UserEditor, self).commit(
            (), ('login', 'email', 'roles', 'fi_uid', 'work_phone',
                 'mobile_phone', 'firstname', 'lastname', 'position',
                 'corporation_id', 'direction_id', 'site_id', 'service_id')):
            return False

        # FIXME: use the OrganizationRepository
        get_organization = lambda id: OrganizationData.get(
            id) if id != -1 else None

        corporation = get_organization(self.corporation_id.value)
        direction = get_organization(self.direction_id.value)
        service = get_organization(self.service_id.value)
        site = get_organization(self.site_id.value)
        subsite = get_organization(self.subsite_id.value)
        facilitator = self.user_repository.get_by_uid(self.fi_uid.value)

        # create or update the user
        updates = dict(
            email=self.email.value,
            firstname=self.firstname.value,
            lastname=self.lastname.value,
            enabled=self.enabled.value,
            position=self.position.value,
            corporation=corporation,
            direction=direction,
            service=service,
            site=site,
            incorporated=self.incorporated.value,
            work_phone=self.work_phone.value,
            mobile_phone=self.mobile_phone.value,
            fi=facilitator,
            subsite=subsite,
        )

        if self.user:
            u = self.user
            u.set(**updates)
        else:
            u = self.user_repository.create(uid=self.login.value, **updates)
            password = u.reset_password()
            u.send_welcome_email(password)

        # roles
        for role in self.assignable_roles:
            if role in self.roles():
                u.add_role(role)
            else:
                u.remove_role(role)

        return True
Ejemplo n.º 5
0
 def _get_organization_label(self, org_id):
     if org_id == -1:
         return None
         # FIXME: use the OrganizationRepository instead
     return OrganizationData.get(org_id).label
Ejemplo n.º 6
0
 def _get_organization_label(self, org_id):
     if org_id == -1:
         return None
         # FIXME: use the OrganizationRepository instead
     return OrganizationData.get(org_id).label