mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-04 21:15:22 +02:00
feat: Additional Household Permissions (#4158)
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
parent
b1820f9b23
commit
fd0257c1b8
37 changed files with 690 additions and 185 deletions
|
@ -86,13 +86,20 @@ def test_get_one_recipe_from_another_household(
|
|||
|
||||
|
||||
@pytest.mark.parametrize("is_private_household", [True, False])
|
||||
@pytest.mark.parametrize("household_lock_recipe_edits", [True, False])
|
||||
@pytest.mark.parametrize("use_patch", [True, False])
|
||||
def test_prevent_updates_to_recipes_from_other_households(
|
||||
api_client: TestClient, unique_user: TestUser, h2_user: TestUser, is_private_household: bool, use_patch: bool
|
||||
def test_update_recipes_in_other_households(
|
||||
api_client: TestClient,
|
||||
unique_user: TestUser,
|
||||
h2_user: TestUser,
|
||||
is_private_household: bool,
|
||||
household_lock_recipe_edits: bool,
|
||||
use_patch: bool,
|
||||
):
|
||||
household = unique_user.repos.households.get_one(h2_user.household_id)
|
||||
assert household and household.preferences
|
||||
household.preferences.private_household = is_private_household
|
||||
household.preferences.lock_recipe_edits_from_other_households = household_lock_recipe_edits
|
||||
unique_user.repos.household_preferences.update(household.id, household.preferences)
|
||||
|
||||
original_name = random_string()
|
||||
|
@ -110,23 +117,39 @@ def test_prevent_updates_to_recipes_from_other_households(
|
|||
updated_name = random_string()
|
||||
recipe["name"] = updated_name
|
||||
client_func = api_client.patch if use_patch else api_client.put
|
||||
response = client_func(api_routes.recipes_slug(recipe["slug"]), json=recipe, headers=unique_user.token)
|
||||
assert response.status_code == 403
|
||||
response = client_func(api_routes.recipes_slug(recipe["id"]), json=recipe, headers=unique_user.token)
|
||||
|
||||
# confirm the recipe is unchanged
|
||||
response = api_client.get(api_routes.recipes_slug(recipe["slug"]), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
updated_recipe = response.json()
|
||||
assert updated_recipe["name"] == original_name != updated_name
|
||||
if household_lock_recipe_edits:
|
||||
assert response.status_code == 403
|
||||
|
||||
# confirm the recipe is unchanged
|
||||
response = api_client.get(api_routes.recipes_slug(recipe["id"]), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
updated_recipe = response.json()
|
||||
assert updated_recipe["name"] == original_name != updated_name
|
||||
else:
|
||||
assert response.status_code == 200
|
||||
|
||||
# confirm the recipe was updated
|
||||
response = api_client.get(api_routes.recipes_slug(recipe["id"]), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
updated_recipe = response.json()
|
||||
assert updated_recipe["name"] == updated_name != original_name
|
||||
|
||||
|
||||
@pytest.mark.parametrize("is_private_household", [True, False])
|
||||
def test_prevent_deletes_to_recipes_from_other_households(
|
||||
api_client: TestClient, unique_user: TestUser, h2_user: TestUser, is_private_household: bool
|
||||
@pytest.mark.parametrize("household_lock_recipe_edits", [True, False])
|
||||
def test_delete_recipes_from_other_households(
|
||||
api_client: TestClient,
|
||||
unique_user: TestUser,
|
||||
h2_user: TestUser,
|
||||
is_private_household: bool,
|
||||
household_lock_recipe_edits: bool,
|
||||
):
|
||||
household = unique_user.repos.households.get_one(h2_user.household_id)
|
||||
assert household and household.preferences
|
||||
household.preferences.private_household = is_private_household
|
||||
household.preferences.lock_recipe_edits_from_other_households = household_lock_recipe_edits
|
||||
unique_user.repos.household_preferences.update(household.id, household.preferences)
|
||||
|
||||
response = api_client.post(api_routes.recipes, json={"name": random_string()}, headers=h2_user.token)
|
||||
|
@ -141,21 +164,34 @@ def test_prevent_deletes_to_recipes_from_other_households(
|
|||
assert recipe_json["id"] == h2_recipe_id
|
||||
|
||||
response = api_client.delete(api_routes.recipes_slug(recipe_json["slug"]), headers=unique_user.token)
|
||||
assert response.status_code == 403
|
||||
if household_lock_recipe_edits:
|
||||
assert response.status_code == 403
|
||||
|
||||
# confirm the recipe still exists
|
||||
response = api_client.get(api_routes.recipes_slug(h2_recipe_id), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["id"] == h2_recipe_id
|
||||
# confirm the recipe still exists
|
||||
response = api_client.get(api_routes.recipes_slug(h2_recipe_id), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["id"] == h2_recipe_id
|
||||
else:
|
||||
assert response.status_code == 200
|
||||
|
||||
# confirm the recipe was deleted
|
||||
response = api_client.get(api_routes.recipes_slug(h2_recipe_id), headers=unique_user.token)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.parametrize("is_private_household", [True, False])
|
||||
@pytest.mark.parametrize("household_lock_recipe_edits", [True, False])
|
||||
def test_user_can_update_last_made_on_other_household(
|
||||
api_client: TestClient, unique_user: TestUser, h2_user: TestUser, is_private_household: bool
|
||||
api_client: TestClient,
|
||||
unique_user: TestUser,
|
||||
h2_user: TestUser,
|
||||
is_private_household: bool,
|
||||
household_lock_recipe_edits: bool,
|
||||
):
|
||||
household = unique_user.repos.households.get_one(h2_user.household_id)
|
||||
assert household and household.preferences
|
||||
household.preferences.private_household = is_private_household
|
||||
household.preferences.lock_recipe_edits_from_other_households = household_lock_recipe_edits
|
||||
unique_user.repos.household_preferences.update(household.id, household.preferences)
|
||||
|
||||
response = api_client.post(api_routes.recipes, json={"name": random_string()}, headers=h2_user.token)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue