implemented user impersonization

This commit is contained in:
2025-07-02 23:20:21 +02:00
parent ea6ca9e45d
commit 5100ac244a
12 changed files with 198 additions and 63 deletions

View File

@@ -13,12 +13,24 @@
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
const json = await resp.json();
for (let user of json) users.push(user);
for (let u of json) users.push(u);
}
});
async function impersonate(userId){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/${userId}/impersonate`;
const resp = await fetch(url,{
method: 'POST',
credentials: 'include'
});
if (resp.ok){
const json = await resp.json();
for (let key of Object.keys(json)) user[key] = json[key];
}
}
</script>
<fieldset>
<fieldset tabindex="0">
<legend>{t('user.list')}</legend>
<table>
<thead>
@@ -38,6 +50,9 @@
<td>{u.email}</td>
<td>{u.language}</td>
<td>
{#if user.permissions.includes('IMPERSONATE')}
<button onclick={() => impersonate(u.id)}>{t('user.impersonate')}</button>
{/if}
{#if user.permissions.includes('UPDATE_USERS')}
<button onclick={() => router.navigate(`/user/${u.id}/edit`)}>{t('user.edit')}</button>
{/if}