2021-09-11 21:52:46 +03:00
|
|
|
<script lang="ts">
|
2023-08-02 19:35:27 +01:00
|
|
|
// import { ROLE } from '$lib/utils/constants/roles';
|
|
|
|
|
import { profile } from '$lib/utils/store/user';
|
2021-09-11 21:52:46 +03:00
|
|
|
import { group } from '../Course/store';
|
|
|
|
|
import type { Person } from '../Course/components/People/types';
|
|
|
|
|
|
|
|
|
|
export let allowedRoles: number[] = [];
|
|
|
|
|
|
|
|
|
|
let userRole: number = 0;
|
|
|
|
|
|
|
|
|
|
$: {
|
|
|
|
|
const user: Person = $group.people.find(
|
|
|
|
|
(person: { profile_id: number }) => person.profile_id === $profile.id
|
|
|
|
|
)!;
|
|
|
|
|
|
|
|
|
|
if (user) {
|
|
|
|
|
userRole = user.role_id;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-18 21:33:19 +01:00
|
|
|
|
|
|
|
|
$: console.log({ group: $group });
|
2024-05-18 21:40:24 +01:00
|
|
|
$: console.log(
|
|
|
|
|
'is allowed',
|
|
|
|
|
allowedRoles.includes(userRole),
|
|
|
|
|
'roles',
|
|
|
|
|
userRole,
|
|
|
|
|
'allowedRoles',
|
|
|
|
|
allowedRoles
|
|
|
|
|
);
|
2021-09-11 21:52:46 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
{#if allowedRoles.includes(userRole)}
|
|
|
|
|
<slot />
|
|
|
|
|
{/if}
|