Redirect no-shop users to /s/new, improve anonymous landing page
Authenticated users on the SaaS domain with no shop get redirected from / to /s/new instead of seeing a bare message. Flash messages are preserved by skipping the redirect when peek_flash() has content. Anonymous visitors now see a proper landing with tagline and CTA.
This commit is contained in:
parent
c4d3537a28
commit
d7e98e7148
3 changed files with 43 additions and 4 deletions
|
|
@ -25,9 +25,9 @@
|
|||
|
||||
{% else %}
|
||||
|
||||
<center>
|
||||
You should <a href="/join-or-log-in">join</a> or <a href="/join-or-log-in">log in</a> to see this dashboard.
|
||||
</center>
|
||||
<h2>Make. Post. Sell.</h2>
|
||||
<p>Create your own shop and start selling digital products in minutes.</p>
|
||||
<a href="/join-or-log-in" class="mps-button">Get Started</a>
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,9 +98,17 @@ class FunctionalTests(unittest.TestCase):
|
|||
class UnauthenticatedFunctionalTests(FunctionalTests):
|
||||
def test_root_home_page(self):
|
||||
res = self.testapp.get("/", status=200)
|
||||
self.assertIn(b"log in", res.body)
|
||||
self.assertIn(b"Get Started", res.body)
|
||||
self.assertIn(b"Cart $0.00 (0)", res.body)
|
||||
|
||||
def test_root_home_page_landing_content(self):
|
||||
"""Anonymous visitors see the MPS landing with tagline and signup CTA."""
|
||||
res = self.testapp.get("/", status=200)
|
||||
body = res.body.decode()
|
||||
self.assertIn("Make. Post. Sell.", body)
|
||||
self.assertIn("start selling digital products", body)
|
||||
self.assertIn("/join-or-log-in", body)
|
||||
|
||||
def test_new_product_redirects(self):
|
||||
redirect_res = self.testapp.get("/p/new", status=302)
|
||||
res = redirect_res.follow()
|
||||
|
|
@ -303,6 +311,33 @@ class AuthenticatedFunctionalTests(FunctionalTests):
|
|||
res = redirect_res.follow()
|
||||
self.assertIn(b"You must have a shop editor role to access that.", res.body)
|
||||
|
||||
def test_home_redirects_to_new_shop_when_no_shop(self):
|
||||
"""Authenticated user with no shop redirects from / to /s/new."""
|
||||
self.log_in_user(self.user2_creds)
|
||||
res = self.testapp.get("/", status=302)
|
||||
self.assertIn("/s/new", res.location)
|
||||
|
||||
def test_home_no_redirect_when_user_has_shop(self):
|
||||
"""Authenticated user with a shop sees the home page, no redirect."""
|
||||
self._create_shop_helper()
|
||||
res = self.testapp.get("/", status=200)
|
||||
# Should render the shop home, not the "no shop" landing
|
||||
self.assertNotIn(b"You don't have any shops", res.body)
|
||||
|
||||
def test_home_shows_flash_instead_of_redirect(self):
|
||||
"""When a flash message is pending, home renders instead of redirecting.
|
||||
|
||||
This ensures flash messages from other views (e.g. shop_editor_required)
|
||||
are displayed rather than lost in a redirect chain.
|
||||
"""
|
||||
self.log_in_user(self.user2_creds)
|
||||
# /p/new without a shop queues a flash and redirects to /
|
||||
redirect_res = self.testapp.get("/p/new", status=302)
|
||||
# Following should render home with the flash, not redirect again
|
||||
res = redirect_res.follow()
|
||||
self.assertEqual(res.status_int, 200)
|
||||
self.assertIn(b"You must have a shop editor role", res.body)
|
||||
|
||||
def _create_shop_helper(
|
||||
self, user_creds=None, shop_params=None, log_out_user=False
|
||||
):
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ def get_shop_from_matchdict(request, prefetched_shop=None):
|
|||
|
||||
@view_config(route_name="home", renderer="home.j2")
|
||||
def home(request):
|
||||
if request.is_saas_domain and request.user and request.user.authenticated:
|
||||
if not request.shop and not request.user.active_shop:
|
||||
if not request.session.peek_flash():
|
||||
return HTTPFound("/s/new")
|
||||
products = None
|
||||
if request.shop:
|
||||
products = get_products_from_a_shop(request.shop)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue