Esempio n. 1
0
 def delete_queryset(self, request, queryset):
     '''To delete firebase users on deleting users from admin panel- bulk delete action'''
     dict_uids = queryset.values('uid')
     uids = [item['uid'] for item in dict_uids]
     try:
         firebase_auth.delete_users(uids)
     except:
         pass
     queryset.delete()
Esempio n. 2
0
    def test_is_idempotent(self):
        uid = auth.create_user().uid

        delete_users_result = auth.delete_users([uid])
        assert delete_users_result.success_count == 1
        assert delete_users_result.failure_count == 0

        # Delete the user again, ensuring that everything still counts as a
        # success.
        delete_users_result = auth.delete_users([uid])
        assert delete_users_result.success_count == 1
        assert delete_users_result.failure_count == 0
Esempio n. 3
0
def delete_users():
    try:
        connection = mysql.connector.connect(
            host='db', database='migrate_users', user='******', password='******')
        if connection.is_connected():
            cursor = connection.cursor()
            query = "SELECT id, uid FROM user_migrate WHERE uid IS NOT NULL ORDER BY id ASC LIMIT 1000"
            cursor.execute(query)
            records = cursor.fetchall()
            users = []
            for row in records:
                users.append(row[1])
                update_query = "UPDATE user_migrate SET uid = NULL WHERE id = %s"
                cursor.execute(update_query % row[0])
                connection.commit()
            result = auth.delete_users(users)
            print('Successfully deleted {0} users'.format(result.success_count))
            print('Failed to delete {0} users'.format(result.failure_count))
            for err in result.errors:
                print('error #{0}, reason: {1}'.format(result.index, result.reason))
    except Error as e:
        print("Error while connecting to MySQL", e)
    finally:
        if (connection.is_connected()):
            cursor.close()
            connection.close()
Esempio n. 4
0
def prune_anonymous_users_in_firebase_and_django():
    """
    This job deletes all anonymous users that haven't used their account in a week from both Firebase and Django
    """
    page = auth.list_users()
    anonymous_users = []
    for user in page.users:
        user_last_refresh = date.fromtimestamp(
            user.user_metadata.last_refresh_timestamp / 1e3)
        logged_within_one_week = date.today() - timedelta(
            days=7) > user_last_refresh
        if user.email is None and logged_within_one_week:
            anonymous_users.append(user.uid)
    result = auth.delete_users(anonymous_users)

    if len(result.errors) == 0:
        profiles = Profile.objects.filter(is_anonymous=True)
        for profile in profiles:
            profile.user.delete()

    print('Successfully deleted {0} users'.format(result.success_count))
    print('Failed to delete {0} users'.format(result.failure_count))
    for err in result.errors:
        print('error #{0}, reason: {1}'.format(result.index, result.reason))

    db.connections.close_all()
Esempio n. 5
0
def bulk_delete_users():
    # [START bulk_delete_users]
    from firebase_admin import auth

    result = auth.delete_users(["uid1", "uid2", "uid3"])

    print('Successfully deleted {0} users'.format(result.success_count))
    print('Failed to delete {0} users'.format(result.failure_count))
    for err in result.errors:
        print('error #{0}, reason: {1}'.format(result.index, result.reason))
Esempio n. 6
0
    def test_delete_multiple_users(self):
        uid1 = auth.create_user(disabled=True).uid
        uid2 = auth.create_user(disabled=False).uid
        uid3 = auth.create_user(disabled=True).uid

        delete_users_result = auth.delete_users([uid1, uid2, uid3])
        assert delete_users_result.success_count == 3
        assert delete_users_result.failure_count == 0
        assert len(delete_users_result.errors) == 0

        get_users_results = auth.get_users([
            auth.UidIdentifier(uid1),
            auth.UidIdentifier(uid2),
            auth.UidIdentifier(uid3)
        ])
        assert len(get_users_results.users) == 0
Esempio n. 7
0
    def map(item):
        # The map() function must be static, so we manually create a "cls"
        # variable instead of changing the function into a classmethod.
        cls = SeedFirebaseOneOffJob

        if isinstance(item, cls.ASSOC_MODEL_TYPES):
            admin_ack = cls.get_admin_ack(item)
            if admin_ack is not None:
                yield admin_ack
            else:
                yield (cls.wipe_assoc_model(item), 1)
            return

        yield (cls.INFO_SEED_MODEL_ACK, item.id)

        for user_batch in cls.yield_firebase_user_batches():
            admins_to_ack, users_to_delete = utils.partition(
                user_batch,
                predicate=lambda user: user.email == feconf.ADMIN_EMAIL_ADDRESS
            )

            for user in admins_to_ack:
                yield ('%s in Firebase account' % cls.INFO_SUPER_ADMIN_ACK,
                       'firebase_auth_id=%s' % (user.uid))

            ids_to_delete = [user.uid for user in users_to_delete]
            try:
                result = firebase_auth.delete_users(ids_to_delete,
                                                    force_delete=True)
            except Exception as exception:
                yield (cls.ERROR_BATCH_DELETE, len(ids_to_delete))
                yield (cls.ERROR_BATCH_DELETE, 'reason=%r' % exception)
            else:
                for error in result.errors:
                    firebase_auth_id = ids_to_delete[error.index]
                    debug_info = 'firebase_auth_id=%s, reason=%s' % (
                        firebase_auth_id, error.reason)
                    yield (cls.ERROR_INDIVIDUAL_DELETE, debug_info)
                num_deleted = len(ids_to_delete) - len(result.errors)
                if num_deleted:
                    yield (cls.SUCCESS_DELETE_ACCOUNTS, num_deleted)
Esempio n. 8
0
 def _slow_delete_users(self, auth, uids):
     """The batchDelete endpoint has a rate limit of 1 QPS. Use this test
     helper to ensure you don't exceed the quota."""
     time.sleep(1)
     return auth.delete_users(uids)