mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-02 20:15:24 +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
|
@ -31,17 +31,33 @@ def test_preferences_in_household(api_client: TestClient, unique_user: TestUser)
|
|||
assert household["preferences"]["recipeShowNutrition"] in {True, False}
|
||||
|
||||
|
||||
def test_update_preferences(api_client: TestClient, unique_user: TestUser) -> None:
|
||||
def test_update_preferences_no_permission(api_client: TestClient, user_tuple: list[TestUser]) -> None:
|
||||
unique_user, other_user = user_tuple
|
||||
|
||||
user = other_user.repos.users.get_one(unique_user.user_id)
|
||||
assert user
|
||||
user.can_manage_household = False
|
||||
other_user.repos.users.update(user.id, user)
|
||||
|
||||
new_data = UpdateHouseholdPreferences(recipe_public=random_bool(), recipe_show_nutrition=random_bool())
|
||||
|
||||
response = api_client.put(api_routes.households_preferences, json=new_data.model_dump(), headers=unique_user.token)
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
def test_update_preferences(api_client: TestClient, user_tuple: list[TestUser]) -> None:
|
||||
unique_user, other_user = user_tuple
|
||||
|
||||
user = other_user.repos.users.get_one(unique_user.user_id)
|
||||
assert user
|
||||
user.can_manage_household = True
|
||||
other_user.repos.users.update(user.id, user)
|
||||
|
||||
new_data = UpdateHouseholdPreferences(recipe_public=random_bool(), recipe_show_nutrition=random_bool())
|
||||
response = api_client.put(api_routes.households_preferences, json=new_data.model_dump(), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
preferences = response.json()
|
||||
|
||||
assert preferences is not None
|
||||
assert preferences["recipePublic"] == new_data.recipe_public
|
||||
assert preferences["recipeShowNutrition"] == new_data.recipe_show_nutrition
|
||||
|
||||
assert_ignore_keys(new_data.model_dump(by_alias=True), preferences, ["id", "householdId"])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue