fix: Broken Social Preview Links (#4183)

This commit is contained in:
Michael Genson
2024-09-12 04:43:23 -05:00
committed by GitHub
parent f6cf58334f
commit f796258529
2 changed files with 133 additions and 12 deletions

View File

@@ -165,13 +165,13 @@ def serve_recipe_with_meta_public(
public_repos = AllRepositories(session)
group = public_repos.groups.get_by_slug_or_id(group_slug)
if not group or group.preferences.private_group: # type: ignore
if not (group and group.preferences) or group.preferences.private_group:
return response_404()
group_repos = AllRepositories(session, group_id=group.id)
group_repos = AllRepositories(session, group_id=group.id, household_id=None)
recipe = group_repos.recipes.get_one(recipe_slug)
if not recipe or not recipe.settings.public: # type: ignore
if not (recipe and recipe.settings) or not recipe.settings.public:
return response_404()
# Inject meta tags
@@ -190,9 +190,9 @@ async def serve_recipe_with_meta(
return serve_recipe_with_meta_public(group_slug, recipe_slug, session)
try:
repos = AllRepositories(session, group_id=user.group_id)
group_repos = AllRepositories(session, group_id=user.group_id, household_id=None)
recipe = repos.recipes.get_one(recipe_slug, "slug")
recipe = group_repos.recipes.get_one(recipe_slug, "slug")
if recipe is None:
return response_404()
@@ -204,8 +204,8 @@ async def serve_recipe_with_meta(
async def serve_shared_recipe_with_meta(group_slug: str, token_id: str, session: Session = Depends(generate_session)):
try:
repos = AllRepositories(session)
token_summary = repos.recipe_share_tokens.get_one(token_id)
public_repos = AllRepositories(session, group_id=None)
token_summary = public_repos.recipe_share_tokens.get_one(token_id)
if token_summary is None:
raise Exception("Token Not Found")