New route and button to anonymize old users
This commit is contained in:
parent
a9bb758e99
commit
0965698c90
3 changed files with 73 additions and 5 deletions
|
|
@ -19,6 +19,18 @@ export async function getUsers(promo, group) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function anonOldAccounts() {
|
||||
const res = await fetch('api/users', {
|
||||
method: 'PATCH',
|
||||
headers: {'Accept': 'application/json'},
|
||||
});
|
||||
if (res.status == 200) {
|
||||
return await res.json()
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
export class User {
|
||||
constructor(res) {
|
||||
if (res) {
|
||||
|
|
|
|||
|
|
@ -3,28 +3,45 @@
|
|||
|
||||
import { user } from '$lib/stores/user';
|
||||
import DateFormat from '$lib/components/DateFormat.svelte';
|
||||
import { getUsers, getPromos } from '$lib/users';
|
||||
import { anonOldAccounts, getUsers, getPromos } from '$lib/users';
|
||||
|
||||
function showUser(user) {
|
||||
goto(`users/${user.id}`)
|
||||
}
|
||||
|
||||
let usersP = getUsers();
|
||||
function refreshUsers() {
|
||||
usersP = getUsers();
|
||||
}
|
||||
|
||||
function askAnon() {
|
||||
if (confirm("Ceci va anonymiser tous les comptes des étudiants avant " + ($user.current_promo - 1) + ". Voulez-vous continuer ?"))
|
||||
anonOldAccounts().then(refreshUsers);
|
||||
}
|
||||
|
||||
let filterPromo = "";
|
||||
</script>
|
||||
|
||||
{#if $user && $user.is_admin}
|
||||
<button
|
||||
class="btn btn-danger ms-2 float-end"
|
||||
on:click={askAnon}
|
||||
>
|
||||
<i class="bi bi-back"></i>
|
||||
Anonymiser vieux comptes
|
||||
</button>
|
||||
<a
|
||||
href="auth/gitlabcri?next={window.location.pathname}"
|
||||
class="btn btn-primary float-end"
|
||||
class="btn btn-primary float-end ms-2"
|
||||
>
|
||||
<i class="bi bi-link-45deg"></i>
|
||||
OAuth GitLab
|
||||
</a>
|
||||
<a href="grades/{filterPromo}" class="btn btn-success me-1 float-end" title="Notes">
|
||||
<a href="grades/{filterPromo}" class="btn btn-success ms-2 float-end" title="Notes">
|
||||
<i class="bi bi-files"></i>
|
||||
</a>
|
||||
{#await getPromos() then promos}
|
||||
<div class="float-end me-2">
|
||||
<div class="float-end ms-2">
|
||||
<select class="form-select" bind:value={filterPromo}>
|
||||
<option value="">-</option>
|
||||
{#each promos as promo, pid (pid)}
|
||||
|
|
@ -38,7 +55,7 @@
|
|||
Étudiants
|
||||
</h2>
|
||||
|
||||
{#await getUsers()}
|
||||
{#await usersP}
|
||||
<div class="text-center">
|
||||
<div class="spinner-border text-danger mx-3" role="status"></div>
|
||||
<span>Chargement des étudiants …</span>
|
||||
|
|
|
|||
Reference in a new issue