Skip to content

Commit 6fa7886

Browse files
Permissions partial view added
1 parent 95bf974 commit 6fa7886

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!-- Modal -->
2+
<div class="modal fade" id="permModal" tabindex="-1" aria-labelledby="permLabel" aria-hidden="true">
3+
<div class="modal-dialog modal-sm">
4+
<div class="modal-content">
5+
<div class="modal-header py-2">
6+
<h6 class="modal-title" id="permLabel"><i class="bi bi-key me-1"></i> Permission Switch</h6>
7+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
8+
</div>
9+
<div class="modal-body">
10+
<div class="d-grid gap-2">
11+
<button id="btnGrantWeb" class="btn btn-success btn-sm">Grant WebApp</button>
12+
<button id="btnGrantApi" class="btn btn-primary btn-sm">Grant API</button>
13+
<button id="btnRevokeApi" class="btn btn-warning btn-sm">Revoke API</button>
14+
<button id="btnRevokeBoth" class="btn btn-danger btn-sm">Revoke Both</button>
15+
</div>
16+
<hr class="my-2">
17+
<div id="permState" class="small text-muted">State: …</div>
18+
</div>
19+
<div class="modal-footer justify-content-start py-2">
20+
<small class="text-muted">Update DB and Invalidate Redis cache.</small>
21+
</div>
22+
</div>
23+
</div>
24+
</div>
25+
26+
<script>
27+
const call = (op) =>
28+
fetch('/Admin/Roles/UpdatePermissions', {
29+
method: 'POST',
30+
headers: { 'Content-Type': 'application/json' },
31+
body: JSON.stringify({op})
32+
})
33+
.then(r => r.json())
34+
.then(d => { toast(d); refreshState(); });
35+
36+
document.getElementById('btnGrantWeb').onclick = () => call('grant-webapp');
37+
document.getElementById('btnGrantApi').onclick = () => call('grant-api');
38+
document.getElementById('btnRevokeApi').onclick = () => call('revoke-api');
39+
document.getElementById('btnRevokeBoth').onclick= () => call('revoke-both');
40+
41+
async function refreshState() {
42+
const res = await fetch('/Admin/Roles/GetState', {
43+
method: 'GET'
44+
});
45+
const data = await res.json();
46+
console.log("data:", data);
47+
console.log(data, typeof data.webapp, typeof data.api);
48+
49+
document.getElementById('permState').textContent =
50+
`WebApp=${data.webapp ? 'On' : 'Off'} · API=${data.api ? 'On' : 'Off'}`;
51+
}
52+
function toastSuccess(msg) {
53+
toastr.options.closeButton = true;
54+
toastr.options.timeOut = 3000;
55+
toastr.success(msg, "Success");
56+
}
57+
function toast(d) {
58+
// wire your toast lib here
59+
// ex: PNotify / toastr / Bootstrap Toast
60+
alert(d.message); // temporary for clarity
61+
//toastSuccess(d.message);
62+
}
63+
64+
document.addEventListener('shown.bs.modal', refreshState);
65+
66+
67+
</script>

0 commit comments

Comments
 (0)