Example #1
0
 def _user_from_avatar(self, avatar, **kwargs):
     email = sanitize_email(
         convert_to_unicode(avatar.email).lower().strip())
     secondary_emails = {
         sanitize_email(convert_to_unicode(x).lower().strip())
         for x in avatar.secondaryEmails
     }
     secondary_emails = {
         x
         for x in secondary_emails
         if x and is_valid_mail(x, False) and x != email
     }
     # we handle deletion later. otherwise it might be set before secondary_emails which would
     # result in those emails not being marked as deleted
     is_deleted = kwargs.pop('is_deleted', False)
     user = User(
         id=int(avatar.id),
         email=email,
         first_name=convert_to_unicode(avatar.name).strip() or 'UNKNOWN',
         last_name=convert_to_unicode(avatar.surName).strip() or 'UNKNOWN',
         title=USER_TITLE_MAP.get(avatar.title, UserTitle.none),
         phone=convert_to_unicode(avatar.telephone[0]).strip(),
         affiliation=convert_to_unicode(avatar.organisation[0]).strip(),
         address=convert_to_unicode(avatar.address[0]).strip(),
         secondary_emails=secondary_emails,
         is_blocked=avatar.status == 'disabled',
         **kwargs)
     if is_deleted or not is_valid_mail(user.email):
         user.is_deleted = True
     return user
Example #2
0
 def _migrate_category(self, old_cat, position):
     # unlimited visibility is 999 but we have a 994 for some reason.. since nobody
     # has 900 levels of nesting we can just go for that threshold instead
     visibility = None if old_cat._visibility > 900 else old_cat._visibility
     if visibility == 0:
         self.print_warning("Raising visibility from 'invisible' to 'category-only'", event_id=old_cat.id)
         visibility = 1
     emails = re.split(r'[\s;,]+', convert_to_unicode(getattr(old_cat, '_notifyCreationList', '')))
     emails = {sanitize_email(email).lower() for email in emails}
     emails = sorted(email for email in emails if is_valid_mail(email, False))
     default_themes = self._process_default_themes(old_cat)
     title = self._fix_title(convert_to_unicode(old_cat.name), old_cat.id)
     cat = Category(id=int(old_cat.id), position=position, title=title,
                    description=convert_to_unicode(old_cat.description), visibility=visibility,
                    timezone=convert_to_unicode(old_cat._timezone), event_creation_notification_emails=emails,
                    default_event_themes=default_themes,
                    suggestions_disabled=getattr(old_cat, '_suggestions_disabled', False))
     if not self.quiet:
         self.print_success(cat.title, event_id=cat.id)
     if old_cat._icon:
         self._process_icon(cat, old_cat._icon)
     self._process_protection(cat, old_cat)
     cat.children = [(self._migrate_category(old_subcat, i))
                     for i, old_subcat in enumerate(sorted(old_cat.subcategories.itervalues(),
                                                           key=attrgetter('_order')), 1)]
     return cat
Example #3
0
    def _migrate_category(self, old_cat, position):
        # unlimited visibility is 999 but we have a 994 for some reason.. since nobody
        # has 900 levels of nesting we can just go for that threshold instead
        visibility = None if old_cat._visibility > 900 else old_cat._visibility
        if visibility == 0:
            self.print_warning(
                "Raising visibility from 'invisible' to 'category-only'",
                event_id=old_cat.id)
            visibility = 1
        emails = re.split(
            r'[\s;,]+',
            convert_to_unicode(getattr(old_cat, '_notifyCreationList', '')))
        emails = {sanitize_email(email).lower() for email in emails}
        emails = sorted(email for email in emails
                        if is_valid_mail(email, False))
        default_themes = self._process_default_themes(old_cat)
        title = self._fix_title(convert_to_unicode(old_cat.name), old_cat.id)

        if is_legacy_id(old_cat.id):
            # if category has a legacy (non-numeric) ID, generate a new ID
            # and establish a mapping (for URL redirection)
            new_id = self.gen_categ_id()
            db.session.add(
                LegacyCategoryMapping(legacy_category_id=old_cat.id,
                                      category_id=new_id))
            self.print_success('%[white!]{:6s}%[reset] -> %[cyan]{}'.format(
                old_cat.id, new_id))
        else:
            new_id = int(old_cat.id)

        if hasattr(old_cat, '_timezone'):
            tz_name = old_cat._timezone
        else:
            tz_name = self.makac_info._timezone
        cat = Category(id=int(new_id),
                       position=position,
                       title=title,
                       description=convert_to_unicode(old_cat.description),
                       visibility=visibility,
                       timezone=convert_to_unicode(tz_name),
                       event_creation_notification_emails=emails,
                       default_event_themes=default_themes,
                       suggestions_disabled=getattr(old_cat,
                                                    '_suggestions_disabled',
                                                    False))
        if not self.quiet:
            self.print_success(cat.title, event_id=cat.id)
        if old_cat._icon:
            self._process_icon(cat, old_cat._icon)
        self._process_protection(cat, old_cat)
        self.migrate_category_attachments(cat, old_cat)
        cat.children = [(self._migrate_category(old_subcat, i))
                        for i, old_subcat in enumerate(
                            sorted(old_cat.subcategories.itervalues(),
                                   key=attrgetter('_order')), 1)]
        # add to user favorites
        for user in self.global_ns.user_favorite_categories[old_cat.id]:
            user.favorite_categories.add(cat)
        self.global_ns.legacy_category_ids[old_cat.id] = cat
        return cat
Example #4
0
 def _process_principal_emails(self, principal_cls, principals, emails, name, read_access=None, full_access=None,
                               roles=None, allow_emails=True):
     emails = {sanitize_email(convert_to_unicode(email).lower()) for email in emails}
     emails = {email for email in emails if is_valid_mail(email, False)}
     for email in emails:
         self._process_principal(principal_cls, principals, email, name, read_access, full_access, roles,
                                 allow_emails=allow_emails)
Example #5
0
 def _process_args(self):
     SearchBase._process_args(self)
     self._surName = self._params.get("surName", "")
     self._name = self._params.get("name", "")
     self._organisation = self._params.get("organisation", "")
     self._email = sanitize_email(self._params.get("email", ""))
     self._exactMatch = self._params.get("exactMatch", False)
     self._confId = self._params.get("conferenceId", None)
     self._event = Event.get(self._confId, is_deleted=False) if self._confId else None
Example #6
0
 def _checkParams(self):
     SearchBase._checkParams(self)
     self._surName = self._params.get("surName", "")
     self._name = self._params.get("name", "")
     self._organisation = self._params.get("organisation", "")
     self._email = sanitize_email(self._params.get("email", ""))
     self._exactMatch = self._params.get("exactMatch", False)
     self._confId = self._params.get("conferenceId", None)
     self._event = Event.get(self._confId, is_deleted=False) if self._confId else None
Example #7
0
File: users.py Project: fph/indico
 def _user_from_avatar(self, avatar, **kwargs):
     email = sanitize_email(convert_to_unicode(avatar.email).lower().strip())
     secondary_emails = {sanitize_email(convert_to_unicode(x).lower().strip()) for x in avatar.secondaryEmails}
     secondary_emails = {x for x in secondary_emails if x and is_valid_mail(x, False) and x != email}
     # we handle deletion later. otherwise it might be set before secondary_emails which would
     # result in those emails not being marked as deleted
     is_deleted = kwargs.pop('is_deleted', False)
     user = User(id=int(avatar.id),
                 email=email,
                 first_name=convert_to_unicode(avatar.name).strip() or 'UNKNOWN',
                 last_name=convert_to_unicode(avatar.surName).strip() or 'UNKNOWN',
                 title=USER_TITLE_MAP.get(avatar.title, UserTitle.none),
                 phone=convert_to_unicode(avatar.telephone[0]).strip(),
                 affiliation=convert_to_unicode(avatar.organisation[0]).strip(),
                 address=convert_to_unicode(avatar.address[0]).strip(),
                 secondary_emails=secondary_emails,
                 is_blocked=avatar.status == 'disabled',
                 **kwargs)
     if is_deleted or not is_valid_mail(user.email):
         user.is_deleted = True
     return user
Example #8
0
 def process_emails(self,
                    principals,
                    emails,
                    name,
                    color,
                    full_access=None,
                    roles=None):
     emails = {
         sanitize_email(convert_to_unicode(email).lower())
         for email in emails
     }
     emails = {email for email in emails if is_valid_mail(email, False)}
     for email in emails:
         self.process_principal(principals, email, name, color, full_access,
                                roles)
Example #9
0
 def _migrate_category(self, old_cat, position):
     # unlimited visibility is 999 but we have a 994 for some reason.. since nobody
     # has 900 levels of nesting we can just go for that threshold instead
     visibility = None if old_cat._visibility > 900 else old_cat._visibility
     if visibility == 0:
         self.print_warning(
             "Raising visibility from 'invisible' to 'category-only'",
             event_id=old_cat.id)
         visibility = 1
     emails = re.split(
         r'[\s;,]+',
         convert_to_unicode(getattr(old_cat, '_notifyCreationList', '')))
     emails = {sanitize_email(email).lower() for email in emails}
     emails = sorted(email for email in emails
                     if is_valid_mail(email, False))
     default_themes = self._process_default_themes(old_cat)
     title = self._fix_title(convert_to_unicode(old_cat.name), old_cat.id)
     cat = Category(id=int(old_cat.id),
                    position=position,
                    title=title,
                    description=convert_to_unicode(old_cat.description),
                    visibility=visibility,
                    timezone=convert_to_unicode(old_cat._timezone),
                    event_creation_notification_emails=emails,
                    default_event_themes=default_themes,
                    suggestions_disabled=getattr(old_cat,
                                                 '_suggestions_disabled',
                                                 False))
     if not self.quiet:
         self.print_success(cat.title, event_id=cat.id)
     if old_cat._icon:
         self._process_icon(cat, old_cat._icon)
     self._process_protection(cat, old_cat)
     cat.children = [(self._migrate_category(old_subcat, i))
                     for i, old_subcat in enumerate(
                         sorted(old_cat.subcategories.itervalues(),
                                key=attrgetter('_order')), 1)]
     return cat
Example #10
0
def test_sanitize_email(input, output):
    assert sanitize_email(input) == output
Example #11
0
 def process_emails(self, event, principals, emails, name, color, full_access=None, roles=None):
     emails = {sanitize_email(convert_to_unicode(email).lower()) for email in emails}
     emails = {email for email in emails if is_valid_mail(email, False)}
     for email in emails:
         self.process_principal(event, principals, email, name, color, full_access, roles)
Example #12
0
def test_sanitize_email(input, output):
    assert sanitize_email(input) == output
Example #13
0
def strict_sanitize_email(email, fallback=None):
    return sanitize_email(convert_to_unicode(email).lower(),
                          require_valid=True) or fallback
Example #14
0
def strict_sanitize_email(email, fallback=None):
    return sanitize_email(convert_to_unicode(email).lower(), require_valid=True) or fallback