parent
aaab95d414
commit
9c6dc5b424
@ -50,6 +50,7 @@
|
|||||||
OpenAPI.BASE = config.baseurl;
|
OpenAPI.BASE = config.baseurl;
|
||||||
import { register as registerSW } from "./swmodule";
|
import { register as registerSW } from "./swmodule";
|
||||||
import TeamDetail from "./components/TeamDetail.svelte";
|
import TeamDetail from "./components/TeamDetail.svelte";
|
||||||
|
import UserPermissions from "./components/UserPermissions.svelte";
|
||||||
store.init();
|
store.init();
|
||||||
// registerSW();
|
// registerSW();
|
||||||
</script>
|
</script>
|
||||||
@ -73,8 +74,13 @@
|
|||||||
<Route path="/">
|
<Route path="/">
|
||||||
<Users />
|
<Users />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/:userid" let:params>
|
<Route path="/:userid/*" let:params>
|
||||||
<UserDetail {params} />
|
<Route path="/">
|
||||||
|
<UserDetail {params} />
|
||||||
|
</Route>
|
||||||
|
<Route path="/permissions/">
|
||||||
|
<UserPermissions {params} />
|
||||||
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/tracks/*">
|
<Route path="/tracks/*">
|
||||||
|
249
src/components/UserPermissions.svelte
Normal file
249
src/components/UserPermissions.svelte
Normal file
@ -0,0 +1,249 @@
|
|||||||
|
<script>
|
||||||
|
import { _ } from "svelte-i18n";
|
||||||
|
import {
|
||||||
|
UserService,
|
||||||
|
PermissionService,
|
||||||
|
CreatePermission,
|
||||||
|
} from "@odit/lfk-client-js";
|
||||||
|
import Toastify from "toastify-js";
|
||||||
|
import PromiseError from "./PromiseError.svelte";
|
||||||
|
export let params;
|
||||||
|
let grantedPermissions_initial = [];
|
||||||
|
let grantedPermissions = [];
|
||||||
|
let inheritedPermissions = [];
|
||||||
|
let to_add = [];
|
||||||
|
let to_delete = [];
|
||||||
|
$: original_data = {};
|
||||||
|
$: save_enabled =
|
||||||
|
JSON.stringify(grantedPermissions) ===
|
||||||
|
JSON.stringify(grantedPermissions_initial);
|
||||||
|
|
||||||
|
const user_promise = UserService.userControllerGetOne(params.userid);
|
||||||
|
user_promise.then((data) => {
|
||||||
|
original_data = Object.assign(original_data, data);
|
||||||
|
});
|
||||||
|
function submit() {
|
||||||
|
to_delete.forEach((d) => {
|
||||||
|
console.log("processing...");
|
||||||
|
console.log(d);
|
||||||
|
console.log("api-calling...");
|
||||||
|
PermissionService.permissionControllerRemove(d, true)
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
to_add.forEach((a) => {
|
||||||
|
console.log("processing...");
|
||||||
|
console.log(a);
|
||||||
|
console.log("api-calling...");
|
||||||
|
PermissionService.permissionControllerPost(a)
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// Toastify({
|
||||||
|
// text: $_("updating-user"),
|
||||||
|
// duration: 2500,
|
||||||
|
// }).showToast();
|
||||||
|
// UserService.userControllerPut(original_data.id, editable_userdata)
|
||||||
|
// .then((resp) => {
|
||||||
|
// Object.assign(original_data, editable_userdata);
|
||||||
|
// original_data = editable_userdata;
|
||||||
|
// Object.assign(original_data, editable_userdata);
|
||||||
|
// //
|
||||||
|
// Toastify({
|
||||||
|
// text: $_("user-updated"),
|
||||||
|
// duration: 2500,
|
||||||
|
// backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)",
|
||||||
|
// }).showToast();
|
||||||
|
// })
|
||||||
|
// .catch((err) => {});
|
||||||
|
}
|
||||||
|
let allpermissions = [];
|
||||||
|
console.log(CreatePermission.target);
|
||||||
|
Object.values(CreatePermission.target).forEach((t) => {
|
||||||
|
Object.values(CreatePermission.action).forEach((a) => {
|
||||||
|
allpermissions = allpermissions.concat([{ target: t, action: a }]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
UserService.userControllerGetPermissions(params.userid).then((val) => {
|
||||||
|
console.log(val);
|
||||||
|
val.inherited.forEach((p) => {
|
||||||
|
inheritedPermissions = inheritedPermissions.concat([p]);
|
||||||
|
});
|
||||||
|
val.directlyGranted.forEach((p) => {
|
||||||
|
grantedPermissions = grantedPermissions.concat([
|
||||||
|
p.target + ":" + p.action,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
grantedPermissions_initial = grantedPermissions;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#await user_promise}
|
||||||
|
<!-- -->
|
||||||
|
{:then user}
|
||||||
|
<section class="container p-5 select-none">
|
||||||
|
<div class="flex flex-row mb-4">
|
||||||
|
<div class="w-full">
|
||||||
|
<nav class="w-full flex">
|
||||||
|
<ol class="list-none flex flex-row items-center justify-start">
|
||||||
|
<li class="flex items-center">
|
||||||
|
<svg
|
||||||
|
class="flex-shrink-0 w-5 h-5 mr-2"
|
||||||
|
fill="currentColor"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox="0 0 640 512"><path
|
||||||
|
fill="currentColor"
|
||||||
|
d="M610.5 341.3c2.6-14.1 2.6-28.5 0-42.6l25.8-14.9c3-1.7 4.3-5.2 3.3-8.5-6.7-21.6-18.2-41.2-33.2-57.4-2.3-2.5-6-3.1-9-1.4l-25.8 14.9c-10.9-9.3-23.4-16.5-36.9-21.3v-29.8c0-3.4-2.4-6.4-5.7-7.1-22.3-5-45-4.8-66.2 0-3.3.7-5.7 3.7-5.7 7.1v29.8c-13.5 4.8-26 12-36.9 21.3l-25.8-14.9c-2.9-1.7-6.7-1.1-9 1.4-15 16.2-26.5 35.8-33.2 57.4-1 3.3.4 6.8 3.3 8.5l25.8 14.9c-2.6 14.1-2.6 28.5 0 42.6l-25.8 14.9c-3 1.7-4.3 5.2-3.3 8.5 6.7 21.6 18.2 41.1 33.2 57.4 2.3 2.5 6 3.1 9 1.4l25.8-14.9c10.9 9.3 23.4 16.5 36.9 21.3v29.8c0 3.4 2.4 6.4 5.7 7.1 22.3 5 45 4.8 66.2 0 3.3-.7 5.7-3.7 5.7-7.1v-29.8c13.5-4.8 26-12 36.9-21.3l25.8 14.9c2.9 1.7 6.7 1.1 9-1.4 15-16.2 26.5-35.8 33.2-57.4 1-3.3-.4-6.8-3.3-8.5l-25.8-14.9zM496 368.5c-26.8 0-48.5-21.8-48.5-48.5s21.8-48.5 48.5-48.5 48.5 21.8 48.5 48.5-21.7 48.5-48.5 48.5zM96 224c35.3 0 64-28.7 64-64s-28.7-64-64-64-64 28.7-64 64 28.7 64 64 64zm224 32c1.9 0 3.7-.5 5.6-.6 8.3-21.7 20.5-42.1 36.3-59.2 7.4-8 17.9-12.6 28.9-12.6 6.9 0 13.7 1.8 19.6 5.3l7.9 4.6c.8-.5 1.6-.9 2.4-1.4 7-14.6 11.2-30.8 11.2-48 0-61.9-50.1-112-112-112S208 82.1 208 144c0 61.9 50.1 112 112 112zm105.2 194.5c-2.3-1.2-4.6-2.6-6.8-3.9-8.2 4.8-15.3 9.8-27.5 9.8-10.9 0-21.4-4.6-28.9-12.6-18.3-19.8-32.3-43.9-40.2-69.6-10.7-34.5 24.9-49.7 25.8-50.3-.1-2.6-.1-5.2 0-7.8l-7.9-4.6c-3.8-2.2-7-5-9.8-8.1-3.3.2-6.5.6-9.8.6-24.6 0-47.6-6-68.5-16h-8.3C179.6 288 128 339.6 128 403.2V432c0 26.5 21.5 48 48 48h255.4c-3.7-6-6.2-12.8-6.2-20.3v-9.2zM173.1 274.6C161.5 263.1 145.6 256 128 256H64c-35.3 0-64 28.7-64 64v32c0 17.7 14.3 32 32 32h65.9c6.3-47.4 34.9-87.3 75.2-109.4z" /></svg>
|
||||||
|
</li>
|
||||||
|
<li class="flex items-center">
|
||||||
|
<a class="mr-2" href="./">{$_('users')}</a><svg
|
||||||
|
stroke="currentColor"
|
||||||
|
fill="none"
|
||||||
|
stroke-width="2"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
class="h-3 w-3 mr-2 stroke-current"
|
||||||
|
height="1em"
|
||||||
|
width="1em"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"><line
|
||||||
|
x1="5"
|
||||||
|
y1="12"
|
||||||
|
x2="19"
|
||||||
|
y2="12" />
|
||||||
|
<polyline points="12 5 19 12 12 19" /></svg>
|
||||||
|
</li>
|
||||||
|
<li class="flex items-center">
|
||||||
|
<span class="mr-2"><a href="../">{original_data.firstname}
|
||||||
|
{original_data.middlename || ''}
|
||||||
|
{original_data.lastname}</a></span>
|
||||||
|
</li>
|
||||||
|
<li class="flex items-center">
|
||||||
|
<svg
|
||||||
|
stroke="currentColor"
|
||||||
|
fill="none"
|
||||||
|
stroke-width="2"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
class="h-3 w-3 mr-2 stroke-current"
|
||||||
|
height="1em"
|
||||||
|
width="1em"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"><line
|
||||||
|
x1="5"
|
||||||
|
y1="12"
|
||||||
|
x2="19"
|
||||||
|
y2="12" />
|
||||||
|
<polyline points="12 5 19 12 12 19" /></svg>
|
||||||
|
</li>
|
||||||
|
<li class="flex items-center">
|
||||||
|
<span class="mr-2">Permissions</span>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mb-8 text-3xl font-extrabold">
|
||||||
|
Permissions:
|
||||||
|
{original_data.firstname}
|
||||||
|
{original_data.middlename || ''}
|
||||||
|
{original_data.lastname}
|
||||||
|
<span>
|
||||||
|
<button
|
||||||
|
disabled={save_enabled}
|
||||||
|
class:opacity-50={save_enabled}
|
||||||
|
type="button"
|
||||||
|
on:click={submit}
|
||||||
|
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:ml-3 sm:w-auto sm:text-sm">{$_('save-changes')}</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<!-- -->
|
||||||
|
<div class="flex flex-wrap -mx-1 overflow-hidden">
|
||||||
|
<div class="my-1 px-1 w-full overflow-hidden sm:w-1/3">verfügbare</div>
|
||||||
|
<div class="my-1 px-1 w-full overflow-hidden sm:w-1/3">erteilte</div>
|
||||||
|
<div class="my-1 px-1 w-full overflow-hidden sm:w-1/3">geerbte</div>
|
||||||
|
</div>
|
||||||
|
<!-- -->
|
||||||
|
<div class="flex flex-wrap -mx-1 overflow-hidden">
|
||||||
|
{#if allpermissions.length > 0}
|
||||||
|
<div class="my-1 px-1 w-full overflow-hidden sm:w-1/3">
|
||||||
|
<div
|
||||||
|
class="border-4 border-dashed rounded mb-4 p-5 text-lg text-center">
|
||||||
|
{#each allpermissions as p}
|
||||||
|
{#if !grantedPermissions.includes(p)}
|
||||||
|
<p
|
||||||
|
class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 bg-gray-200 p-2 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input">
|
||||||
|
{p.target + ':' + p.action}
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
grantedPermissions = grantedPermissions.concat([p]);
|
||||||
|
if (to_delete.some((o) => o === p.id)) {
|
||||||
|
to_delete = to_delete.filter((o) => o !== p.id);
|
||||||
|
} else {
|
||||||
|
to_add = to_add.concat([
|
||||||
|
{
|
||||||
|
action: p.action,
|
||||||
|
target: p.target,
|
||||||
|
principal: original_data.id,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
console.log({ to_delete, to_add });
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-green-200 text-base font-medium text-black hover:bg-green-700 hover:text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 sm:ml-3 sm:w-auto sm:text-sm">+</button>
|
||||||
|
</p>
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="my-1 px-1 w-full overflow-hidden sm:w-1/3">
|
||||||
|
<div
|
||||||
|
class="border-4 border-dashed rounded mb-4 p-5 text-lg text-center">
|
||||||
|
{#each grantedPermissions as p}
|
||||||
|
<p
|
||||||
|
class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 bg-gray-200 p-2 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input">
|
||||||
|
{p.target + ':' + p.action}
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
grantedPermissions = grantedPermissions.filter((o) => o.target + ':' + o.action !== p.target + ':' + p.action);
|
||||||
|
if (to_add.some((o) => o.target + ':' + o.action === p.target + ':' + p.action)) {
|
||||||
|
to_add = to_add.filter((o) => o.target + ':' + o.action !== p.target + ':' + p.action);
|
||||||
|
} else {
|
||||||
|
to_delete = to_delete.concat([p.id]);
|
||||||
|
}
|
||||||
|
console.log({ to_delete, to_add });
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
class="w-full justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-300 text-base font-medium text-black hover:bg-red-700 hover:text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 sm:ml-3 sm:w-auto sm:text-sm">-</button>
|
||||||
|
</p>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="my-1 px-1 w-full overflow-hidden sm:w-1/3">
|
||||||
|
<div
|
||||||
|
class="border-4 border-dashed rounded mb-4 p-5 text-lg text-center">
|
||||||
|
{#each inheritedPermissions as p}
|
||||||
|
<p
|
||||||
|
class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 bg-gray-200 p-2 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input">
|
||||||
|
{p.target + ':' + p.action}
|
||||||
|
</p>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{:catch error}
|
||||||
|
<PromiseError {error} />
|
||||||
|
{/await}
|
Loading…
x
Reference in New Issue
Block a user