Exemple #1
0
def merge_to_umail(ldap_conn, mailer, umail, other):
    umail = umail.lower()
    other_user = User.fetch_by(username=other)
    if not other_user:
        print('Invalid user: {}'.format(other))
        return

    name = helper.fetch_name(ldap_conn, umail)
    if not name:
        print('Invalid umail: {}'.format(umail))
        return

    to = '{} <{}>'.format(name, other)
    umail_user = User.fetch_by(username=umail)
    if umail_user:
        print('Merging {} with {}'.format(other_user, umail_user))
        helper.merge_users(umail_user, other_user)
        subject = 'submit.cs accounts merged'
        body = ('Your submit.cs account {old} has been merged with the account'
                ' {umail}. You will need to use {umail} and its associated '
                'password to login.\n\nIf you need to reset your password '
                'visit: https://submit.cs.ucsb.edu/password_reset'
                .format(old=other, umail=umail))
    else:
        print('Changing {} to {}'.format(other_user, umail))
        subject = 'submit.cs account username changed'
        body = ('Your submit.cs account name has been changed to {umail}. '
                'You will need to use this email to login on the submission '
                'system.'.format(umail=umail))
        other_user.name = name
        other_user.username = umail
    if mailer:
        body += '\n\nThank you,\nBryce Boe'
        message = Message(subject=subject, body=body, recipients=[to])
        mailer.send_immediately(message)
def merge_to_umail(ldap_conn, mailer, umail, other):
    umail = umail.lower()
    other_user = User.fetch_by(username=other)
    if not other_user:
        print('Invalid user: {}'.format(other))
        return

    name = helper.fetch_name(ldap_conn, umail)
    if not name:
        print('Invalid umail: {}'.format(umail))
        return

    to = '{} <{}>'.format(name, other)
    umail_user = User.fetch_by(username=umail)
    if umail_user:
        print('Merging {} with {}'.format(other_user, umail_user))
        helper.merge_users(umail_user, other_user)
        subject = 'submit.cs accounts merged'
        body = ('Your submit.cs account {old} has been merged with the account'
                ' {umail}. You will need to use {umail} and its associated '
                'password to login.\n\nIf you need to reset your password '
                'visit: https://submit.cs.ucsb.edu/password_reset'.format(
                    old=other, umail=umail))
    else:
        print('Changing {} to {}'.format(other_user, umail))
        subject = 'submit.cs account username changed'
        body = ('Your submit.cs account name has been changed to {umail}. '
                'You will need to use this email to login on the submission '
                'system.'.format(umail=umail))
        other_user.name = name
        other_user.username = umail
    if mailer:
        body += '\n\nThank you,\nBryce Boe'
        message = Message(subject=subject, body=body, recipients=[to])
        mailer.send_immediately(message)
Exemple #3
0
def main():
    if len(sys.argv) != 3:
        usage(sys.argv)
    config_uri = sys.argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    Session.configure(bind=engine)

    people = fetch_consent_data(sys.argv[2])
    by_email = {}
    for user in people:
        email = user['email']
        if email in by_email:
            if to_date(user) > by_email[email]:
                continue
        by_email[email] = to_date(user)
    matched = {}
    total = len(by_email)

    # Attempt to match by email
    for user in User.query_by().order_by(User.name).all():
        if user.username in by_email:
            matched[user.username] = by_email[user.username]
            if not user.consent_at or \
                    by_email[user.username] < user.consent_at:
                print 'updating'
                user.consent_at = by_email[user.username]
            del by_email[user.username]
    transaction.commit()
    print('Matched {} out of {} ({} remaining)'.format(len(matched), total,
                                                       len(by_email)))
def main():
    if len(sys.argv) != 3:
        usage(sys.argv)
    config_uri = sys.argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    Session.configure(bind=engine)

    people = fetch_consent_data(sys.argv[2])
    by_email = {}
    for user in people:
        email = user['email']
        if email in by_email:
            if to_date(user) > by_email[email]:
                continue
        by_email[email] = to_date(user)
    matched = {}
    total = len(by_email)

    # Attempt to match by email
    for user in User.query_by().order_by(User.name).all():
        if user.username in by_email:
            matched[user.username] = by_email[user.username]
            if not user.consent_at or \
                    by_email[user.username] < user.consent_at:
                print 'updating'
                user.consent_at = by_email[user.username]
            del by_email[user.username]
    transaction.commit()
    print('Matched {} out of {} ({} remaining)'
          .format(len(matched), total, len(by_email)))
Exemple #5
0
def match_to_umail():
    ldap_conn = helper.connect()
    for user in sorted(
        User.query_by().filter(
            not_(User.username.contains('@umail.ucsb.edu'))).all()):
        if user.admin_for or user.is_admin or '(' in user.name:
            continue
        match = helper.find_user(ldap_conn, user.name)
        if match:
            print match, user.username
Exemple #6
0
def update_umail_users():
    ldap_conn = helper.connect()
    for user in User.query_by().order_by(User.name).all():
        email = user.username
        if email.endswith('umail.ucsb.edu'):
            name = helper.fetch_name(ldap_conn, email)
            if name and name != user.name:
                user.name = name
            elif not name:
                print email, user.name
    transaction.commit()
Exemple #7
0
def delete_inactive_users():
    # Delete inactive users
    for user in User.query_by().order_by(User.created_at).all():
        msg = None
        if user.is_admin or len(user.admin_for) > 0:
            continue  # Admin for a class
        if not user.classes:
            msg = 'Delete user {} with no classes ({} files)'.format(
                user.name, len(user.files))
        elif not user.groups_assocs:
            msg = 'Delete user {} with no groups?'.format(user.name)
        elif not user.files:
            msg = 'Delete user {} with no files?'.format(user.name)
        if msg and prompt(msg):
            Session.delete(user)
    transaction.commit()