def claim_invitations(user):
    invitation_user_id = '%s:%s' % (
        models.User.EMAIL_INVITATION, user.email_address)
    invitation_user = models.User.query.get(invitation_user_id)
    if invitation_user:
        invited_build_list = list(invitation_user.builds)
        if not invited_build_list:
            return
        db.session.add(user)
        logging.debug('Found %d build admin invitations for id=%r, user=%r',
                      len(invited_build_list), invitation_user_id, user)
        for build in invited_build_list:
            build.owners.remove(invitation_user)
            if not build.is_owned_by(user.id):
                build.owners.append(user)
                logging.debug('Claiming invitation for build_id=%r', build.id)
                save_admin_log(build, invite_accepted=True)
            else:
                logging.debug('User already owner of build. '
                              'id=%r, build_id=%r', user.id, build.id)
            db.session.add(build)
        db.session.delete(invitation_user)
        db.session.commit()
        db.session.add(current_user)