-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow admins to view and edit users (#168)
* Allow admins to view and edit users - backend - add /admin/users/ endpoint to get a list of users - refactor admin endpoints into separate files for languages, milestones, users, questions - refactor tests to also create a temporary in-memory users database for each test - add pytest-asyncio to allow use of async fixtures - refactor tests to be fully independent of each other - new app & new temp dirs for each test - makes test suite slower to run but easier to maintain - remove DATA_FILES_PATH as we already have STATIC_FILES_PATH and PRIVATE_FILES_PATH - admin-frontend - add users tab with table of users whose permissions can be edited - resolves #164 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d71691a
commit e405e47
Showing
26 changed files
with
1,175 additions
and
930 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<svelte:options runes={true} /> | ||
|
||
<script lang="ts"> | ||
import SaveButton from "$lib/components/Admin/SaveButton.svelte"; | ||
import { | ||
Card, | ||
Checkbox, | ||
Table, | ||
TableBody, | ||
TableBodyCell, | ||
TableBodyRow, | ||
TableHead, | ||
TableHeadCell, | ||
} from "flowbite-svelte"; | ||
import { getUsers, usersPatchUser } from "$lib/client/services.gen"; | ||
import type { UserRead, UserUpdate } from "$lib/client/types.gen"; | ||
import { onMount } from "svelte"; | ||
import { _ } from "svelte-i18n"; | ||
let users = $state([] as Array<UserRead>); | ||
let saveDisabled = $state({} as Record<string, boolean>); | ||
async function refreshUsers() { | ||
const { data, error } = await getUsers(); | ||
if (error || !data) { | ||
console.log(error); | ||
} else { | ||
saveDisabled = {}; | ||
users = data; | ||
for (const user of users) { | ||
saveDisabled[user.id] = true; | ||
} | ||
} | ||
} | ||
async function updateUser(user: UserRead) { | ||
const { data, error } = await usersPatchUser({ | ||
body: { | ||
is_active: user.is_active, | ||
is_verified: user.is_verified, | ||
is_researcher: user.is_researcher, | ||
is_superuser: user.is_superuser, | ||
}, | ||
path: { | ||
id: `${user.id}`, | ||
}, | ||
}); | ||
if (error || !data) { | ||
console.log(error); | ||
} else { | ||
await refreshUsers(); | ||
} | ||
} | ||
onMount(async () => { | ||
await refreshUsers(); | ||
}); | ||
</script> | ||
|
||
<Card size="xl" class="m-5 w-full"> | ||
<h3 class="mb-3 text-xl font-medium text-gray-900 dark:text-white"> | ||
{$_("admin.users")} | ||
</h3> | ||
<Table> | ||
<TableHead> | ||
<TableHeadCell>Email</TableHeadCell> | ||
<TableHeadCell>Active</TableHeadCell> | ||
<TableHeadCell>Verified</TableHeadCell> | ||
<TableHeadCell>Researcher</TableHeadCell> | ||
<TableHeadCell>Admin</TableHeadCell> | ||
<TableHeadCell>Actions</TableHeadCell> | ||
</TableHead> | ||
<TableBody> | ||
{#each users as user (user.id)} | ||
<TableBodyRow> | ||
<TableBodyCell> | ||
{user.email} | ||
</TableBodyCell> | ||
<TableBodyCell> | ||
<Checkbox bind:checked={user.is_active} onchange={() => {saveDisabled[user.id]=false}} /> | ||
</TableBodyCell> | ||
<TableBodyCell> | ||
<Checkbox bind:checked={user.is_verified} onchange={() => {saveDisabled[user.id]=false}} /> | ||
</TableBodyCell> | ||
<TableBodyCell> | ||
<Checkbox bind:checked={user.is_researcher} onchange={() => {saveDisabled[user.id]=false}} /> | ||
</TableBodyCell> | ||
<TableBodyCell> | ||
<Checkbox bind:checked={user.is_superuser} onchange={() => {saveDisabled[user.id]=false}} /> | ||
</TableBodyCell> | ||
<TableBodyCell> | ||
<SaveButton disabled={saveDisabled[user.id]} onclick={() => {updateUser(user)}} /> | ||
</TableBodyCell> | ||
</TableBodyRow> | ||
{/each} | ||
</TableBody> | ||
</Table> | ||
</Card> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.