def test_is_admin_user_func(rf, admin_user, regular_user): get_default_shop() regular_user.is_staff = True request = apply_request_middleware(rf.post("/"), user=regular_user) assert not is_admin_user(request) assert not request.is_admin_user assert not is_admin_user(request) request = apply_request_middleware(rf.post("/"), user=admin_user) assert is_admin_user(request) assert request.is_admin_user assert is_admin_user(request) request = apply_request_middleware(rf.post("/")) assert not is_admin_user(request)
def toggle_all_seeing(request): return_url = request.META["HTTP_REFERER"] if not is_admin_user(request): return HttpResponseRedirect(return_url) toggle_all_seeing_for_user(request.user) return HttpResponseRedirect(return_url)
def toggle_all_seeing(request): return_url = request.META["HTTP_REFERER"] if not is_admin_user(request): return HttpResponseRedirect(return_url) all_seeing_key = "is_all_seeing:%d" % request.user.pk is_all_seeing = not configuration.get(None, all_seeing_key, False) configuration.set(None, all_seeing_key, is_all_seeing) return HttpResponseRedirect(return_url)
def force_person_contact(request): return_url = request.META["HTTP_REFERER"] if not is_admin_user(request): return HttpResponseRedirect(return_url) user = request.user force_person_contact_for_user(user, True) force_anonymous_contact_for_user(user, False) return HttpResponseRedirect(return_url)
def could_edit(request): """ Return true if the context of the given request would allow Xtheme editing. :param request: HTTP request :type request: django.http.HttpRequest :return: Would allow editing? :rtype: bool """ return is_admin_user(request)
def force_company_contact(request): return_url = request.META["HTTP_REFERER"] if not is_admin_user(request): return HttpResponseRedirect(return_url) user = request.user force_anonymous_contact_for_user(user, False) force_person_contact_for_user(user, False) get_company_contact_for_shop_staff(request.shop, user) return HttpResponseRedirect(return_url)
def _get_maintenance_response(self, request, view_func): if settings.DEBUG: # Allow media and static accesses in debug mode if request.path.startswith("/media") or request.path.startswith("/static"): return None if getattr(view_func, "maintenance_mode_exempt", False): return None if "login" in view_func.__name__: return None resolver_match = getattr(request, "resolver_match", None) if resolver_match and resolver_match.app_name == "shuup_admin": return None if request.shop.maintenance_mode and not is_admin_user(request): return HttpResponse(loader.render_to_string("shuup/front/maintenance.jinja", request=request), status=503)
def is_shop_admin(context): return is_admin_user(context["request"])