Fix 502s from anonymous visitors: guard request.user.can_edit_shop with null check

Bot crawlers (AhrefsBot, SemrushBot) hitting content pages caused
jinja2.UndefinedError: 'None' has no attribute 'can_edit_shop' because
request.user is None for unauthenticated visitors.
This commit is contained in:
russell@unturf.com 2026-02-10 08:54:51 -05:00
parent a950304a49
commit 7401b4a3c3
4 changed files with 7 additions and 7 deletions

View file

@ -151,14 +151,14 @@
<section class="windows-95-task-bar">
<section class="windows-95-start-button">
{% if request.is_saas_domain or request.user.can_edit_shop(request.shop) %}
{% if request.is_saas_domain or request.user and request.user.can_edit_shop(request.shop) %}
<a href="/actions/view" class="windows-95-start-button mps-button mps-button-blue"><span class="start-button-icon">&#9776; &nbsp </span> {{ request.shop.name }}</a>
{% endif %}
</section>
<section class="call-to-action">
{% block call_to_action %}
{% if request.is_saas_domain or request.user.can_edit_shop(request.shop) %}
{% if request.is_saas_domain or request.user and request.user.can_edit_shop(request.shop) %}
{% if request.user.shops %}
<a href="/actions/new" class="mps-button mps-button-small mps-button-green">&#65291; New</a>
{% else %}

View file

@ -22,7 +22,7 @@
{%- block call_to_action -%}
{% if request.user.can_edit_shop(request.shop) %}
{% if request.user and request.user.can_edit_shop(request.shop) %}
<a href="{{ product.absolute_edit_url(request) }}" class="product-edit-button mps-button mps-button-small">&#9998; Edit</a>
{% endif %}
{%- endblock call_to_action -%}
@ -32,7 +32,7 @@
<section class="two-column{% if request.shop.watch_mode_enabled %} watch-mode{% endif %}" data-signal-product-id="{{ product.id }}" data-signal-shop-id="{{ product.shop_id }}">
{% if request.shop.watch_mode_enabled %}<div class="watch-left" data-watch-product-id="{{ product.id }}"{% if request.user.can_edit_shop(request.shop) %} data-watch-is-mod="1"{% endif %}>{% endif %}
{% if request.shop.watch_mode_enabled %}<div class="watch-left" data-watch-product-id="{{ product.id }}"{% if request.user and request.user.can_edit_shop(request.shop) %} data-watch-is-mod="1"{% endif %}>{% endif %}
<div class="product-images">
{% set video_extensions = ["mp4", "avi", "mov", "wmv", "flv", "mkv", "webm", "m4v"] %}

View file

@ -1,7 +1,7 @@
{% extends "base.j2" -%}
{%- block call_to_action -%}
{% if request.user.can_edit_shop(request.shop) %}
{% if request.user and request.user.can_edit_shop(request.shop) %}
<a href="/s/{{ request.shop.id }}/{{ markup_path }}/edit" class="product-edit-button mps-button mps-button-small">&#9998; Edit</a>
{% endif %}
{%- endblock call_to_action -%}

View file

@ -21,7 +21,7 @@
{%- endblock append_to_head_tag_section -%}
{%- block call_to_action -%}
{% if request.user.can_edit_shop(request.shop) %}
{% if request.user and request.user.can_edit_shop(request.shop) %}
<a href="/p/{{ product.id }}/edit" class="product-edit-button mps-button mps-button-small">&#9998; Edit</a>
{% endif %}
{%- endblock call_to_action -%}
@ -30,7 +30,7 @@
<section class="two-column{% if request.shop.watch_mode_enabled %} watch-mode{% endif %}" data-signal-product-id="{{ product.id }}" data-signal-shop-id="{{ product.shop_id }}">
{% if request.shop.watch_mode_enabled %}<div class="watch-left" data-watch-product-id="{{ product.id }}"{% if request.user.can_edit_shop(request.shop) %} data-watch-is-mod="1"{% endif %}>{% endif %}
{% if request.shop.watch_mode_enabled %}<div class="watch-left" data-watch-product-id="{{ product.id }}"{% if request.user and request.user.can_edit_shop(request.shop) %} data-watch-is-mod="1"{% endif %}>{% endif %}
<div class="product-images">
<h1>{{ product.title }}<br/><span class="subtitle-text">sold by <a href="{{ product.shop.absolute_about_url(request) }}" rel="nofollow" class="shop-theme-link-color">{{ product.shop.name }}</a></span></h1>