Add display in sidebar for impersonation
This commit is contained in:
parent
51811132a4
commit
76c395d613
11 changed files with 259 additions and 234 deletions
|
|
@ -12,10 +12,9 @@
|
|||
<div class="col-md-6">
|
||||
<label for="userSearch" class="form-label">Search Users</label>
|
||||
<UserSelector
|
||||
v-model="selectedUserId"
|
||||
v-model="selectedUser"
|
||||
label="Choose a user"
|
||||
placeholder="Select a user..."
|
||||
@change="onUserChange"
|
||||
/>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
|
|
@ -29,76 +28,9 @@
|
|||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>User ID</th>
|
||||
<th>Name</th>
|
||||
<th>Email</th>
|
||||
<th>Role</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>1001</td>
|
||||
<td>John Doe</td>
|
||||
<td>john.doe@example.com</td>
|
||||
<td><span class="badge bg-primary">Admin</span></td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-primary">
|
||||
Impersonate <i class="bi bi-box-arrow-in-right"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1002</td>
|
||||
<td>Jane Smith</td>
|
||||
<td>jane.smith@example.com</td>
|
||||
<td><span class="badge bg-info">Support</span></td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-primary">
|
||||
Impersonate <i class="bi bi-box-arrow-in-right"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1003</td>
|
||||
<td>Robert Johnson</td>
|
||||
<td>robert@example.com</td>
|
||||
<td><span class="badge bg-success">Premium User</span></td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-primary">
|
||||
Impersonate <i class="bi bi-box-arrow-in-right"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1004</td>
|
||||
<td>Maria Garcia</td>
|
||||
<td>maria@example.com</td>
|
||||
<td><span class="badge bg-secondary">Standard User</span></td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-primary">
|
||||
Impersonate <i class="bi bi-box-arrow-in-right"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="alert alert-warning mt-3 mb-0"
|
||||
id="impersonationStatus"
|
||||
style="display: none"
|
||||
>
|
||||
<i class="bi bi-exclamation-triangle"></i> You are currently
|
||||
impersonating <strong>John Doe</strong>
|
||||
<button class="btn btn-sm btn-warning float-end">
|
||||
Exit Impersonation <i class="bi bi-box-arrow-left"></i>
|
||||
<div class="row mb-3">
|
||||
<button class="btn btn-danger" @click="doImpersonation" type="submit">
|
||||
Impersonate
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -113,9 +45,31 @@ import type { User } from "@/types";
|
|||
|
||||
const session = useSessionStore();
|
||||
|
||||
const selectedUserId = ref<number | null>(null);
|
||||
const selectedUser = ref<User | null>(null);
|
||||
|
||||
const onUserChange = (user: User | null) => {
|
||||
console.log("Selected user:", user);
|
||||
const doImpersonation = async () => {
|
||||
if (!selectedUser.value) {
|
||||
console.log("Can't impersonate, null user");
|
||||
return;
|
||||
}
|
||||
console.log("doing impersonation of user", selectedUser.value);
|
||||
const body = {
|
||||
id: selectedUser.value.id,
|
||||
};
|
||||
const url = session.urls!.api.impersonation;
|
||||
const response = await fetch(url, {
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
method: "POST",
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Upload failed: ${response.statusText}`);
|
||||
}
|
||||
const result = await response.json();
|
||||
console.log("impersonation", result);
|
||||
const new_session = await session.fetchSession();
|
||||
console.log("session is now", new_session);
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue