def filter_sorted_apps(admin_apps, request):
    sorted_apps = []
    for orig_app_spec in appsettings.DASHBOARD_SORTED_APPS:
        app_spec = orig_app_spec.copy()
        app_spec['models'] = _build_app_models(
            request, admin_apps, app_spec['models'], ensure_all_models=True
        )
        if app_spec['models']:
            sorted_apps.append(app_spec)
    used_models = []
    for app in sorted_apps:
        used_models += app['models']
    sorted_apps += _remove_app_models(admin_apps, used_models)
    return sorted_apps