示例#1
0
 def _user_from_legacy(self, legacy_user, janitor=False):
     if isinstance(legacy_user, AvatarUserWrapper):
         user = legacy_user.user
         email = convert_to_unicode(legacy_user.__dict__.get(
             'email', '')).lower() or None
     elif legacy_user.__class__.__name__ == 'Avatar':
         user = AvatarUserWrapper(legacy_user.id).user
         email = convert_to_unicode(legacy_user.email).lower()
     else:
         self.importer.print_error(
             cformat('%{red!}Invalid legacy user: {}').format(legacy_user),
             event_id=self.event.id)
         return self.importer.janitor_user if janitor else None
     if user is None:
         user = self.importer.all_users_by_email.get(
             email) if email else None
         if user is not None:
             msg = 'Using {} for {} (matched via {})'.format(
                 user, legacy_user, email)
         else:
             msg = cformat('%{yellow}Invalid legacy user: {}').format(
                 legacy_user)
         self.importer.print_warning(
             msg,
             event_id=self.event.id,
             always=(msg not in self.legacy_warnings_shown))
         self.legacy_warnings_shown.add(msg)
     return user or (self.importer.janitor_user if janitor else None)
示例#2
0
    def as_avatar(self):
        # TODO: remove this after DB is free of Avatars
        from indico.modules.users.legacy import AvatarUserWrapper
        avatar = AvatarUserWrapper(self.id)

        # avoid garbage collection
        avatar.user
        return avatar
示例#3
0
def convert_principal(principal):
    """Converts a legacy principal to PrincipalMixin style"""
    if isinstance(principal, AvatarUserWrapper):
        return principal.user
    elif isinstance(principal, GroupWrapper):
        return principal.group
    elif principal.__class__.__name__ == 'Avatar':
        return AvatarUserWrapper(principal.id).user
    elif principal.__class__.__name__ == 'Group':
        return GroupProxy(principal.id)
    elif principal.__class__.__name__ in {'CERNGroup', 'LDAPGroup', 'NiceGroup'}:
        return GroupProxy(principal.id, multipass.default_group_provider.name)