Delete perms: must be staff and in group (#82)
* Delete perms: must be staff and in group * separate group check and staff check * test_del_list => test_del_list_not_in_list_group
This commit is contained in:
parent
21e0c6d656
commit
7f576c9bc8
2 changed files with 10 additions and 8 deletions
|
@ -62,13 +62,6 @@ def test_view_list(todo_setup, admin_client):
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_del_list(todo_setup, admin_client):
|
|
||||||
tlist = TaskList.objects.get(slug="zip")
|
|
||||||
url = reverse("todo:del_list", kwargs={"list_id": tlist.id, "list_slug": tlist.slug})
|
|
||||||
response = admin_client.get(url)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_add_list(todo_setup, admin_client):
|
def test_view_add_list(todo_setup, admin_client):
|
||||||
url = reverse("todo:add_list")
|
url = reverse("todo:add_list")
|
||||||
response = admin_client.get(url)
|
response = admin_client.get(url)
|
||||||
|
@ -182,6 +175,13 @@ def test_view_del_list_nonadmin(todo_setup, client):
|
||||||
assert response.status_code == 302 # Fedirected to login
|
assert response.status_code == 302 # Fedirected to login
|
||||||
|
|
||||||
|
|
||||||
|
def test_del_list_not_in_list_group(todo_setup, admin_client):
|
||||||
|
tlist = TaskList.objects.get(slug="zip")
|
||||||
|
url = reverse("todo:del_list", kwargs={"list_id": tlist.id, "list_slug": tlist.slug})
|
||||||
|
response = admin_client.get(url)
|
||||||
|
assert response.status_code == 403
|
||||||
|
|
||||||
|
|
||||||
def test_view_list_mine(todo_setup, client):
|
def test_view_list_mine(todo_setup, client):
|
||||||
"""View a list in a group I belong to.
|
"""View a list in a group I belong to.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -17,7 +17,9 @@ def del_list(request, list_id: int, list_slug: str) -> HttpResponse:
|
||||||
|
|
||||||
# Ensure user has permission to delete list. Get the group this list belongs to,
|
# Ensure user has permission to delete list. Get the group this list belongs to,
|
||||||
# and check whether current user is a member of that group AND a staffer.
|
# and check whether current user is a member of that group AND a staffer.
|
||||||
if task_list.group not in request.user.groups.all() and not request.user.is_staff:
|
if task_list.group not in request.user.groups.all():
|
||||||
|
raise PermissionDenied
|
||||||
|
if not request.user.is_staff:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue