Some quick changes to permissions
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {User} from "@/interfaces/user";
|
||||
import {Tab, TabGroup, TabList, TabPanel, TabPanels} from "@headlessui/react";
|
||||
import { User } from "@/interfaces/user";
|
||||
import { Tab, TabGroup, TabList, TabPanel, TabPanels } from "@headlessui/react";
|
||||
import clsx from "clsx";
|
||||
import CodeList from "./CodeList";
|
||||
import DiscountList from "./DiscountList";
|
||||
@@ -7,10 +7,10 @@ import ExamList from "./ExamList";
|
||||
import GroupList from "./GroupList";
|
||||
import PackageList from "./PackageList";
|
||||
import UserList from "./UserList";
|
||||
import {checkAccess} from "@/utils/permissions";
|
||||
import {PermissionType} from "@/interfaces/permissions";
|
||||
import { checkAccess } from "@/utils/permissions";
|
||||
import { PermissionType } from "@/interfaces/permissions";
|
||||
import { EntityWithRoles } from "@/interfaces/entity";
|
||||
import { useAllowedEntitiesSomePermissions } from "@/hooks/useEntityPermissions";
|
||||
import { useAllowedEntities, useAllowedEntitiesSomePermissions } from "@/hooks/useEntityPermissions";
|
||||
import { useMemo } from "react";
|
||||
|
||||
interface Props {
|
||||
@@ -19,7 +19,9 @@ interface Props {
|
||||
permissions: PermissionType[];
|
||||
}
|
||||
|
||||
export default function Lists({user, entities = [], permissions}: Props) {
|
||||
export default function Lists({ user, entities = [], permissions }: Props) {
|
||||
const entitiesViewCodes = useAllowedEntities(user, entities, 'view_code_list')
|
||||
const entitiesDeleteCodes = useAllowedEntities(user, entities, 'delete_code')
|
||||
const entitiesViewExams = useAllowedEntitiesSomePermissions(user, entities, [
|
||||
'view_reading', 'view_listening', 'view_writing', 'view_speaking', 'view_level'
|
||||
])
|
||||
@@ -30,7 +32,7 @@ export default function Lists({user, entities = [], permissions}: Props) {
|
||||
<TabGroup>
|
||||
<TabList className="flex space-x-1 rounded-xl bg-mti-purple-ultralight/40 p-1">
|
||||
<Tab
|
||||
className={({selected}) =>
|
||||
className={({ selected }) =>
|
||||
clsx(
|
||||
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-mti-purple-light",
|
||||
"ring-white ring-opacity-60 ring-offset-2 ring-offset-mti-purple-light focus:outline-none focus:ring-2",
|
||||
@@ -42,7 +44,7 @@ export default function Lists({user, entities = [], permissions}: Props) {
|
||||
</Tab>
|
||||
{canViewExams && (
|
||||
<Tab
|
||||
className={({selected}) =>
|
||||
className={({ selected }) =>
|
||||
clsx(
|
||||
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-mti-purple-light",
|
||||
"ring-white ring-opacity-60 ring-offset-2 ring-offset-mti-purple-light focus:outline-none focus:ring-2",
|
||||
@@ -53,9 +55,9 @@ export default function Lists({user, entities = [], permissions}: Props) {
|
||||
Exam List
|
||||
</Tab>
|
||||
)}
|
||||
{checkAccess(user, ["developer", "admin", "corporate"]) && (
|
||||
{checkAccess(user, ["developer", "admin", "corporate"]) && entitiesViewCodes.length > 0 && (
|
||||
<Tab
|
||||
className={({selected}) =>
|
||||
className={({ selected }) =>
|
||||
clsx(
|
||||
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-mti-purple-light",
|
||||
"ring-white ring-opacity-60 ring-offset-2 ring-offset-mti-purple-light focus:outline-none focus:ring-2",
|
||||
@@ -68,7 +70,7 @@ export default function Lists({user, entities = [], permissions}: Props) {
|
||||
)}
|
||||
{checkAccess(user, ["developer", "admin"]) && (
|
||||
<Tab
|
||||
className={({selected}) =>
|
||||
className={({ selected }) =>
|
||||
clsx(
|
||||
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-mti-purple-light",
|
||||
"ring-white ring-opacity-60 ring-offset-2 ring-offset-mti-purple-light focus:outline-none focus:ring-2",
|
||||
@@ -81,7 +83,7 @@ export default function Lists({user, entities = [], permissions}: Props) {
|
||||
)}
|
||||
{checkAccess(user, ["developer", "admin"]) && (
|
||||
<Tab
|
||||
className={({selected}) =>
|
||||
className={({ selected }) =>
|
||||
clsx(
|
||||
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-mti-purple-light",
|
||||
"ring-white ring-opacity-60 ring-offset-2 ring-offset-mti-purple-light focus:outline-none focus:ring-2",
|
||||
@@ -102,9 +104,9 @@ export default function Lists({user, entities = [], permissions}: Props) {
|
||||
<ExamList user={user} entities={entities} />
|
||||
</TabPanel>
|
||||
)}
|
||||
{checkAccess(user, ["developer", "admin", "corporate", "mastercorporate"], permissions, "viewCodes") && (
|
||||
{checkAccess(user, ["developer", "admin", "corporate", "mastercorporate"]) && entitiesViewCodes.length > 0 && (
|
||||
<TabPanel className="overflow-y-scroll max-h-[600px] rounded-xl scrollbar-hide">
|
||||
<CodeList user={user} />
|
||||
<CodeList user={user} canDeleteCodes={entitiesDeleteCodes.length > 0} />
|
||||
</TabPanel>
|
||||
)}
|
||||
{checkAccess(user, ["developer", "admin"]) && (
|
||||
|
||||
Reference in New Issue
Block a user