def _decorator(request: WSGIRequest) -> HttpResponse: if not user_manager.is_admin(request.user): return HttpResponseForbidden() response = func(request) update_state() if response is not None: return response return HttpResponse()
def remove_all(request: WSGIRequest) -> HttpResponse: """Empties the queue. Only admin is permitted to do this.""" if not user_manager.is_admin(request.user): return HttpResponseForbidden() with playback.mopidy_command() as allowed: if allowed: with transaction.atomic(): playback.queue.all().delete() return HttpResponse()
def context(request: WSGIRequest) -> Dict[str, Any]: """Returns the base context that is needed on every page. Increments the visitors counter.""" from core import urls _increment_counter() return { "base_urls": urls.base_paths, "interactivity": storage.get("interactivity"), "interactivities": { "fullControl": storage.Interactivity.full_control, "fullVoting": storage.Interactivity.full_voting, "upvotesOnly": storage.Interactivity.upvotes_only, "noControl": storage.Interactivity.no_control, }, "hashtag": _get_random_hashtag(), "demo": conf.DEMO, "controls_enabled": user_manager.has_controls(request.user) or storage.get("interactivity") == storage.Interactivity.full_control, "is_admin": user_manager.is_admin(request.user), "apk_link": _get_apk_link(), "local_enabled": storage.get("local_enabled"), "youtube_enabled": storage.get("youtube_enabled"), "spotify_enabled": storage.get("spotify_enabled"), "soundcloud_enabled": storage.get("soundcloud_enabled"), "jamendo_enabled": storage.get("jamendo_enabled"), "streaming_enabled": storage.get("output") == "icecast", }
def shuffle_all(request: WSGIRequest) -> HttpResponse: """Shuffles the queue. Only admin is permitted to do this.""" if not user_manager.is_admin(request.user): return HttpResponseForbidden() playback.queue.shuffle() return HttpResponse()
def logged_in(request: WSGIRequest) -> HttpResponse: """This endpoint is visited after every login. Redirect the admin to the settings and everybody else to the musiq page.""" if user_manager.is_admin(request.user): return HttpResponseRedirect(reverse("settings")) return HttpResponseRedirect(reverse("musiq"))