def METHOD_NAME(request, *args, **kwargs):
    domain = args[0] if len(args) > 0 else kwargs["domain"]
    app_id = args[1] if len(args) > 1 else kwargs["app_id"]
    latest = True if request.GET.get('latest') == 'true' else False
    # target is used update to latest build/saved state/release of the app
    target = request.GET.get('target') or None
    # make endpoints that call the user fail hard
    from django.contrib.auth.models import AnonymousUser
    request.user = AnonymousUser()
    username = request.GET.get('username')
    if request.GET.get('username'):
        request.GET = request.GET.copy()
        request.GET.pop('username')
    location_flag_enabled = toggles.MANAGE_RELEASES_PER_LOCATION.enabled(domain)
    latest_enabled_build = None
    if latest and location_flag_enabled:
        if not username:
            content_response = dict(error="app.update.not.allowed.user.logged_out",
                                    default_response=_("Please log in to the app to check for an update."))
            return HttpResponse(status=406, content=json.dumps(content_response))
    if latest and not target:
        latest_enabled_build = _get_latest_enabled_build(domain, username, app_id, request.GET.get('profile'),
                                                         location_flag_enabled)
    try:
        if latest_enabled_build:
            request.app = latest_enabled_build
        else:
            request.app = get_app(domain, app_id, latest=latest, target=target)
        if not request.app.doc_type.endswith(DELETED_SUFFIX):
            response = f(request, *args, **kwargs)
            if request.app.copy_of is not None and request.app.is_released:
                if latest:
                    response._cache_max_age = 60
                response._always_allow_browser_caching = True
                response._remember_domain = False
            return response
        else:
            message = 'User attempted to install deleted application: {}'.format(app_id)
    except (AppEditingError, CaseError, ValueError) as e:
        message = e
    logging.exception(message)
    messages.error(request, "Problem downloading file: %s" % message)
    return HttpResponseRedirect(reverse("view_app", args=[domain, app_id]))