Adding delete option for scopes

This commit is contained in:
Ian Roddis committed 2026-08-10 12:04:56 -03:00
1 parent f4771e33d4
commit 14aa2ac5d6
4 files changed
+118 -7

No files matched your search

+57
View File
@@ -330,3 +330,60 @@ async def test_scopes_page_redirects_when_anonymous(client):
assert resp.status_code == 302
# Deep link is preserved so the user lands back here after logging in.
assert resp.headers["location"] == "/login?next=%2Fscopes"
@pytest.mark.asyncio
async def test_scopes_page_hides_delete_for_read_only_user(
client, seeded, make_user, db_sessionmaker
):
async with db_sessionmaker() as db:
ids = await _seed_guide_data(db)
await make_user("reader6@example.com", role_ids=[seeded["roles"]["user"].id])
await _web_login(client, "reader6@example.com")
resp = await client.get("/scopes")
assert resp.status_code == 200
assert f"/scopes/{ids['s1'].id}" not in resp.text
@pytest.mark.asyncio
async def test_scopes_page_shows_delete_for_write_user(
client, seeded, make_user, db_sessionmaker
):
async with db_sessionmaker() as db:
ids = await _seed_guide_data(db)
await make_user("writer@example.com", is_superuser=True)
await _web_login(client, "writer@example.com")
resp = await client.get("/scopes")
assert resp.status_code == 200
assert f'hx-delete="/scopes/{ids["s1"].id}"' in resp.text
@pytest.mark.asyncio
async def test_delete_scope_removes_augmented_part(
client, seeded, make_user, db_sessionmaker
):
async with db_sessionmaker() as db:
ids = await _seed_guide_data(db)
await make_user("writer2@example.com", is_superuser=True)
await _web_login(client, "writer2@example.com")
resp = await client.delete(f"/scopes/{ids['s1'].id}")
assert resp.status_code == 200
async with db_sessionmaker() as db:
from app.crud import augmented_part as augmented_part_crud
assert await augmented_part_crud.get(db, ids["s1"].id) is None
@pytest.mark.asyncio
async def test_delete_scope_forbidden_without_write_permission(
client, seeded, make_user, db_sessionmaker
):
async with db_sessionmaker() as db:
ids = await _seed_guide_data(db)
await make_user("reader7@example.com", role_ids=[seeded["roles"]["user"].id])
await _web_login(client, "reader7@example.com")
resp = await client.delete(f"/scopes/{ids['s1'].id}")
assert resp.status_code == 403