diff --git a/apps/backend/schema.gql b/apps/backend/schema.gql index 4e9c6022b..8d24e229c 100644 --- a/apps/backend/schema.gql +++ b/apps/backend/schema.gql @@ -291,28 +291,28 @@ type PageInfo { } type PermissionsStaff { - children: [String!]! id: String! + permissions: [String!]! } input PermissionsStaffArgs { - permissions: [PermissionsStaffInput!]! + groups: [PermissionsStaffInput!]! plugin_code: String! } input PermissionsStaffInput { - children: [String!]! id: String! + permissions: [String!]! } type PermissionsStaffObj { - permissions: [PermissionsStaff!]! + groups: [PermissionsStaff!]! plugin: String! plugin_code: String! } type PermissionsStaffObjWithoutPluginName { - permissions: [PermissionsStaff!]! + groups: [PermissionsStaff!]! plugin_code: String! } diff --git a/packages/backend/src/core/admin/plugins/permissions-admin/create-edit/create-edit.service.ts b/packages/backend/src/core/admin/plugins/permissions-admin/create-edit/create-edit.service.ts index f08918d6c..4eb3d3000 100644 --- a/packages/backend/src/core/admin/plugins/permissions-admin/create-edit/create-edit.service.ts +++ b/packages/backend/src/core/admin/plugins/permissions-admin/create-edit/create-edit.service.ts @@ -40,7 +40,7 @@ export class CreateEditAdminPermissionsAdminPluginsService { // Check if the id already exists if (old_id !== id) { const existsPermission = parent - ? parent.children.find(child => child === id) + ? parent.permissions.find(child => child === id) : config.permissions_admin?.find(permission => permission.id === id); if (existsPermission) { @@ -54,7 +54,7 @@ export class CreateEditAdminPermissionsAdminPluginsService { // Edit if (old_id) { const oldPermission = parent - ? parent.children.find(child => child === old_id) + ? parent.permissions.find(child => child === old_id) : config.permissions_admin?.find( permission => permission.id === old_id, ); @@ -72,7 +72,7 @@ export class CreateEditAdminPermissionsAdminPluginsService { if (permission.id === parent.id) { return { ...permission, - children: permission.children.map(child => { + children: permission.permissions.map(child => { if (child === old_id) { return id; } @@ -92,7 +92,7 @@ export class CreateEditAdminPermissionsAdminPluginsService { if (permission.id === old_id) { return { id, - children: permission.children, + permissions: permission.permissions, }; } @@ -115,7 +115,7 @@ export class CreateEditAdminPermissionsAdminPluginsService { return { id, - children: [], + permissions: [], }; } @@ -127,7 +127,7 @@ export class CreateEditAdminPermissionsAdminPluginsService { if (permission.id === parent.id) { return { ...permission, - children: [...permission.children, id], + permissions: [...permission.permissions, id], }; } @@ -141,7 +141,7 @@ export class CreateEditAdminPermissionsAdminPluginsService { ...(config.permissions_admin ?? []), { id, - children: [], + permissions: [], }, ], }; diff --git a/packages/backend/src/core/admin/plugins/permissions-admin/delete/delete.service.ts b/packages/backend/src/core/admin/plugins/permissions-admin/delete/delete.service.ts index c5534492a..c15ffc72e 100644 --- a/packages/backend/src/core/admin/plugins/permissions-admin/delete/delete.service.ts +++ b/packages/backend/src/core/admin/plugins/permissions-admin/delete/delete.service.ts @@ -30,7 +30,7 @@ export class DeleteAdminPermissionsAdminPluginsService { } const existsPermission = parent - ? parent.children.find(child => child === id) + ? parent.permissions.find(child => child === id) : config.permissions_admin?.find(permission => permission.id === id); if (!existsPermission) { @@ -40,7 +40,7 @@ export class DeleteAdminPermissionsAdminPluginsService { if (parent) { config.permissions_admin = config.permissions_admin?.map(permission => { if (permission.id === parent_id) { - permission.children = permission.children.filter( + permission.permissions = permission.permissions.filter( child => child !== id, ); } diff --git a/packages/backend/src/core/admin/settings/authorization/show/show.resolver.ts b/packages/backend/src/core/admin/settings/authorization/show/show.resolver.ts index 54bbad4c2..eb1692969 100644 --- a/packages/backend/src/core/admin/settings/authorization/show/show.resolver.ts +++ b/packages/backend/src/core/admin/settings/authorization/show/show.resolver.ts @@ -13,7 +13,11 @@ export class ShowAdminAuthorizationSettingsResolver { @Query(() => ShowAdminAuthorizationSettingsObj) @UseGuards(AdminAuthGuards) - @AdminPermission('can_manage_authorization_settings') + @AdminPermission({ + plugin_code: 'core', + group: 'settings', + permission: 'can_manage_settings_authorization', + }) admin__core_authorization_settings__show(): ShowAdminAuthorizationSettingsObj { return this.service.show(); } diff --git a/packages/backend/src/core/admin/staff/administrators/permissions/core-admin-permisisons.ts b/packages/backend/src/core/admin/staff/administrators/permissions/core-admin-permissions.ts similarity index 82% rename from packages/backend/src/core/admin/staff/administrators/permissions/core-admin-permisisons.ts rename to packages/backend/src/core/admin/staff/administrators/permissions/core-admin-permissions.ts index 3b01b1287..dba3b4306 100644 --- a/packages/backend/src/core/admin/staff/administrators/permissions/core-admin-permisisons.ts +++ b/packages/backend/src/core/admin/staff/administrators/permissions/core-admin-permissions.ts @@ -5,14 +5,14 @@ export const coreAdminPermissions: ShowAdminStaffAdministratorsObj['permissions' { plugin: 'Core', plugin_code: 'core', - permissions: [ + groups: [ { id: 'dashboard', - children: ['can_manage_diagnostic_tools'], + permissions: ['can_manage_diagnostic_tools'], }, { id: 'settings', - children: [ + permissions: [ 'can_manage_settings_main', 'can_manage_settings_security', 'can_manage_settings_metadata', @@ -27,10 +27,10 @@ export const coreAdminPermissions: ShowAdminStaffAdministratorsObj['permissions' { plugin: 'Members', plugin_code: 'members', - permissions: [ + groups: [ { id: 'staff', - children: ['can_view_staff'], + permissions: ['can_view_staff'], }, ], }, diff --git a/packages/backend/src/core/admin/staff/administrators/permissions/dto.ts b/packages/backend/src/core/admin/staff/administrators/permissions/dto.ts index 2e30d4ec3..7dbbf105d 100644 --- a/packages/backend/src/core/admin/staff/administrators/permissions/dto.ts +++ b/packages/backend/src/core/admin/staff/administrators/permissions/dto.ts @@ -2,17 +2,17 @@ import { Field, InputType, ObjectType, OmitType } from '@nestjs/graphql'; @InputType() class PermissionsStaffInput { - @Field(() => [String]) - children: string[]; - @Field(() => String) id: string; + + @Field(() => [String]) + permissions: string[]; } @InputType() export class PermissionsStaffArgs { @Field(() => [PermissionsStaffInput]) - permissions: PermissionsStaffInput[]; + groups: PermissionsStaffInput[]; @Field(() => String) plugin_code: string; @@ -20,17 +20,17 @@ export class PermissionsStaffArgs { @ObjectType() export class PermissionsStaff { - @Field(() => [String]) - children: string[]; - @Field(() => String) id: string; + + @Field(() => [String]) + permissions: string[]; } @ObjectType() export class PermissionsStaffObj { @Field(() => [PermissionsStaff]) - permissions: PermissionsStaff[]; + groups: PermissionsStaff[]; @Field(() => String) plugin: string; diff --git a/packages/backend/src/core/admin/staff/administrators/permissions/permissions.service.ts b/packages/backend/src/core/admin/staff/administrators/permissions/permissions.service.ts index b99502584..7e293c038 100644 --- a/packages/backend/src/core/admin/staff/administrators/permissions/permissions.service.ts +++ b/packages/backend/src/core/admin/staff/administrators/permissions/permissions.service.ts @@ -2,7 +2,7 @@ import { InternalDatabaseService } from '@/utils'; import { Injectable } from '@nestjs/common'; import { ShowAdminStaffAdministratorsObj } from '../show/show.dto'; -import { coreAdminPermissions } from './core-admin-permisisons'; +import { coreAdminPermissions } from './core-admin-permissions'; @Injectable() export class PermissionsAdminStaffAdministratorsService { @@ -18,7 +18,7 @@ export class PermissionsAdminStaffAdministratorsService { ...plugins.map(plugin => ({ plugin_code: plugin.code, plugin: plugin.name, - permissions: [], + groups: [], })), ]; } diff --git a/packages/backend/src/providers/plugins.type.ts b/packages/backend/src/providers/plugins.type.ts index c45603cbf..017d72459 100644 --- a/packages/backend/src/providers/plugins.type.ts +++ b/packages/backend/src/providers/plugins.type.ts @@ -16,8 +16,8 @@ export interface PluginInfoJSONType extends CreateAdminPluginsArgs { allow_default: boolean; nav: NavPluginInfoJSONTypeWithChildren[]; permissions_admin?: { - children: string[]; id: string; + permissions: string[]; }[]; version: string; version_code: number; diff --git a/packages/backend/src/utils/guards/admin-auth.guard.ts b/packages/backend/src/utils/guards/admin-auth.guard.ts index 001e81cb1..e6684e13b 100644 --- a/packages/backend/src/utils/guards/admin-auth.guard.ts +++ b/packages/backend/src/utils/guards/admin-auth.guard.ts @@ -1,3 +1,4 @@ +import { AccessDeniedError } from '@/errors'; import { CanActivate, ExecutionContext, @@ -10,7 +11,14 @@ import { GqlExecutionContext } from '@nestjs/graphql'; import { AuthorizationAdminSessionsObj } from '../../core/admin/sessions/authorization/authorization.dto'; import { GqlContext } from '../context'; -export const AdminPermission = Reflector.createDecorator(); +interface AdminPermissionDecorator { + group: string; + permission: string; + plugin_code: string; +} + +export const AdminPermission = + Reflector.createDecorator(); @Injectable() export class AdminAuthGuards implements CanActivate { @@ -38,15 +46,25 @@ export class AdminAuthGuards implements CanActivate { async canActivate(context: ExecutionContext): Promise { const ctx: GqlContext = GqlExecutionContext.create(context).getContext(); const authorization = await this.getAuth(ctx); - const permission: string | undefined = this.reflector.get( + const permission: AdminPermissionDecorator | undefined = this.reflector.get( AdminPermission, context.getHandler(), ); - - if (!permission) { + if (!permission || authorization.permissions.length === 0) { return !!authorization; } + const plugin = authorization.permissions.find( + plugin => plugin.plugin_code === permission.plugin_code, + ); + if (!plugin) throw new AccessDeniedError(); + const group = plugin.groups.find(group => group.id === permission.group); + if (!group) throw new AccessDeniedError(); + const permissionObj = group.permissions.find( + item => item === permission.permission, + ); + if (!permissionObj) throw new AccessDeniedError(); + return !!authorization; } } diff --git a/packages/frontend/src/graphql/queries/admin/members/staff/admin__core_staff_administrators__show.generated.ts b/packages/frontend/src/graphql/queries/admin/members/staff/admin__core_staff_administrators__show.generated.ts index 2b6219dff..6c22ff7f8 100644 --- a/packages/frontend/src/graphql/queries/admin/members/staff/admin__core_staff_administrators__show.generated.ts +++ b/packages/frontend/src/graphql/queries/admin/members/staff/admin__core_staff_administrators__show.generated.ts @@ -9,7 +9,7 @@ export type Admin__Core_Staff_Administrators__ShowQueryVariables = Types.Exact<{ }>; -export type Admin__Core_Staff_Administrators__ShowQuery = { __typename?: 'Query', admin__core_staff_administrators__show: { __typename?: 'ShowAdminStaffAdministratorsObj', edges: Array<{ __typename?: 'ShowAdminStaffAdministrators', created: Date, id: number, updated: Date, protected: boolean, user_or_group: { __typename: 'StaffGroupUser', color?: string, id: number, group_name: Array<{ __typename?: 'StringLanguage', language_code: string, value: string }> } | { __typename: 'User', avatar_color: string, language: string, name_seo: string, id: number, name: string, avatar?: { __typename?: 'AvatarUser', id: number, dir_folder: string, file_name: string }, group: { __typename?: 'GroupUser', id: number, color?: string, name: Array<{ __typename?: 'StringLanguage', language_code: string, value: string }> } }, permissions: Array<{ __typename?: 'PermissionsStaffObjWithoutPluginName', plugin_code: string, permissions: Array<{ __typename?: 'PermissionsStaff', children: Array, id: string }> }> }>, pageInfo: { __typename?: 'PageInfo', count: number, endCursor?: number, hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: number, totalCount: number }, permissions: Array<{ __typename?: 'PermissionsStaffObj', plugin: string, plugin_code: string, permissions: Array<{ __typename?: 'PermissionsStaff', id: string, children: Array }> }> } }; +export type Admin__Core_Staff_Administrators__ShowQuery = { __typename?: 'Query', admin__core_staff_administrators__show: { __typename?: 'ShowAdminStaffAdministratorsObj', edges: Array<{ __typename?: 'ShowAdminStaffAdministrators', created: Date, id: number, updated: Date, protected: boolean, user_or_group: { __typename: 'StaffGroupUser', color?: string, id: number, group_name: Array<{ __typename?: 'StringLanguage', language_code: string, value: string }> } | { __typename: 'User', avatar_color: string, language: string, name_seo: string, id: number, name: string, avatar?: { __typename?: 'AvatarUser', id: number, dir_folder: string, file_name: string }, group: { __typename?: 'GroupUser', id: number, color?: string, name: Array<{ __typename?: 'StringLanguage', language_code: string, value: string }> } }, permissions: Array<{ __typename?: 'PermissionsStaffObjWithoutPluginName', plugin_code: string, groups: Array<{ __typename?: 'PermissionsStaff', permissions: Array, id: string }> }> }>, pageInfo: { __typename?: 'PageInfo', count: number, endCursor?: number, hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: number, totalCount: number }, permissions: Array<{ __typename?: 'PermissionsStaffObj', plugin: string, plugin_code: string, groups: Array<{ __typename?: 'PermissionsStaff', id: string, permissions: Array }> }> } }; export const Admin__Core_Staff_Administrators__Show = gql` @@ -57,8 +57,8 @@ export const Admin__Core_Staff_Administrators__Show = gql` updated protected permissions { - permissions { - children + groups { + permissions id } plugin_code @@ -73,9 +73,9 @@ export const Admin__Core_Staff_Administrators__Show = gql` totalCount } permissions { - permissions { + groups { id - children + permissions } plugin plugin_code diff --git a/packages/frontend/src/graphql/queries/admin/members/staff/admin__core_staff_administrators__show.gql b/packages/frontend/src/graphql/queries/admin/members/staff/admin__core_staff_administrators__show.gql index 62f0bced0..ec8ac9d74 100644 --- a/packages/frontend/src/graphql/queries/admin/members/staff/admin__core_staff_administrators__show.gql +++ b/packages/frontend/src/graphql/queries/admin/members/staff/admin__core_staff_administrators__show.gql @@ -47,8 +47,8 @@ query Admin__core_staff_administrators__show( updated protected permissions { - permissions { - children + groups { + permissions id } plugin_code @@ -63,9 +63,9 @@ query Admin__core_staff_administrators__show( totalCount } permissions { - permissions { + groups { id - children + permissions } plugin plugin_code diff --git a/packages/frontend/src/graphql/queries/admin/plugins/dev/permissions-admin/admin__core_plugins__permissions_admin__show.generated.ts b/packages/frontend/src/graphql/queries/admin/plugins/dev/permissions-admin/admin__core_plugins__permissions_admin__show.generated.ts index 9533d43cd..fff1b82f8 100644 --- a/packages/frontend/src/graphql/queries/admin/plugins/dev/permissions-admin/admin__core_plugins__permissions_admin__show.generated.ts +++ b/packages/frontend/src/graphql/queries/admin/plugins/dev/permissions-admin/admin__core_plugins__permissions_admin__show.generated.ts @@ -6,13 +6,13 @@ export type Admin__Core_Plugins__Permissions_Admin__ShowQueryVariables = Types.E }>; -export type Admin__Core_Plugins__Permissions_Admin__ShowQuery = { __typename?: 'Query', admin__core_plugins__permissions_admin__show: Array<{ __typename?: 'PermissionsStaff', children: Array, id: string }> }; +export type Admin__Core_Plugins__Permissions_Admin__ShowQuery = { __typename?: 'Query', admin__core_plugins__permissions_admin__show: Array<{ __typename?: 'PermissionsStaff', permissions: Array, id: string }> }; export const Admin__Core_Plugins__Permissions_Admin__Show = gql` query Admin__core_plugins__permissions_admin__show($pluginCode: String!) { admin__core_plugins__permissions_admin__show(plugin_code: $pluginCode) { - children + permissions id } } diff --git a/packages/frontend/src/graphql/queries/admin/plugins/dev/permissions-admin/admin__core_plugins__permissions_admin__show.gql b/packages/frontend/src/graphql/queries/admin/plugins/dev/permissions-admin/admin__core_plugins__permissions_admin__show.gql index c17b6c6de..807da013e 100644 --- a/packages/frontend/src/graphql/queries/admin/plugins/dev/permissions-admin/admin__core_plugins__permissions_admin__show.gql +++ b/packages/frontend/src/graphql/queries/admin/plugins/dev/permissions-admin/admin__core_plugins__permissions_admin__show.gql @@ -1,6 +1,6 @@ query Admin__core_plugins__permissions_admin__show($pluginCode: String!) { admin__core_plugins__permissions_admin__show(plugin_code: $pluginCode) { - children + permissions id } } diff --git a/packages/frontend/src/graphql/types.ts b/packages/frontend/src/graphql/types.ts index ab074bd30..043cb713d 100644 --- a/packages/frontend/src/graphql/types.ts +++ b/packages/frontend/src/graphql/types.ts @@ -675,30 +675,30 @@ export type PageInfo = { export type PermissionsStaff = { __typename?: 'PermissionsStaff'; - children: Array; id: Scalars['String']['output']; + permissions: Array; }; export type PermissionsStaffArgs = { - permissions: Array; + groups: Array; plugin_code: Scalars['String']['input']; }; export type PermissionsStaffInput = { - children: Array; id: Scalars['String']['input']; + permissions: Array; }; export type PermissionsStaffObj = { __typename?: 'PermissionsStaffObj'; - permissions: Array; + groups: Array; plugin: Scalars['String']['output']; plugin_code: Scalars['String']['output']; }; export type PermissionsStaffObjWithoutPluginName = { __typename?: 'PermissionsStaffObjWithoutPluginName'; - permissions: Array; + groups: Array; plugin_code: Scalars['String']['output']; }; diff --git a/packages/frontend/src/views/admin/views/core/plugins/views/dev/permissions-admin/content.tsx b/packages/frontend/src/views/admin/views/core/plugins/views/dev/permissions-admin/content.tsx index ead971b7e..baa006af7 100644 --- a/packages/frontend/src/views/admin/views/core/plugins/views/dev/permissions-admin/content.tsx +++ b/packages/frontend/src/views/admin/views/core/plugins/views/dev/permissions-admin/content.tsx @@ -11,7 +11,7 @@ export const ContentPermissionsAdminDevPluginAdminView = ( const data = dataFromSSR.admin__core_plugins__permissions_admin__show.map( item => ({ ...item, - children: item.children.map(child => ({ + children: item.permissions.map(child => ({ id: child, children: [], })), @@ -24,10 +24,9 @@ export const ContentPermissionsAdminDevPluginAdminView = ( return ( child.id)} dataFromSSR={dataFromSSR} parentId={parentId?.toString()} + permissions={data.children.map(child => child.id)} /> ); }} diff --git a/packages/frontend/src/views/admin/views/core/plugins/views/dev/permissions-admin/item/actions/delete/content.tsx b/packages/frontend/src/views/admin/views/core/plugins/views/dev/permissions-admin/item/actions/delete/content.tsx index 6c2bc7dfd..3f1e6de0d 100644 --- a/packages/frontend/src/views/admin/views/core/plugins/views/dev/permissions-admin/item/actions/delete/content.tsx +++ b/packages/frontend/src/views/admin/views/core/plugins/views/dev/permissions-admin/item/actions/delete/content.tsx @@ -16,7 +16,7 @@ import { SubmitDeleteActionItemPermissionsAdminDevPluginAdmin } from './submit'; export const ContentDeleteActionItemPermissionsAdminDevPluginAdmin = ({ id, parentId, - children, + permissions, }: { parentId: string | undefined; } & Admin__Core_Plugins__Permissions_Admin__ShowQuery['admin__core_plugins__permissions_admin__show'][0]) => { @@ -34,7 +34,7 @@ export const ContentDeleteActionItemPermissionsAdminDevPluginAdmin = ({ })} - {children.length > 0 && ( + {permissions.length > 0 && ( {t('children_warn.title')} {t('children_warn.desc')} diff --git a/packages/frontend/src/views/admin/views/core/plugins/views/dev/permissions-admin/item/item.tsx b/packages/frontend/src/views/admin/views/core/plugins/views/dev/permissions-admin/item/item.tsx index 1c7a476ed..5ea08319d 100644 --- a/packages/frontend/src/views/admin/views/core/plugins/views/dev/permissions-admin/item/item.tsx +++ b/packages/frontend/src/views/admin/views/core/plugins/views/dev/permissions-admin/item/item.tsx @@ -6,7 +6,7 @@ export const ItemPermissionsAdminDevPluginAdmin = ({ id, parentId, dataFromSSR, - children, + permissions, }: { dataFromSSR: Admin__Core_Plugins__Permissions_Admin__ShowQuery; parentId: string | undefined; @@ -15,7 +15,7 @@ export const ItemPermissionsAdminDevPluginAdmin = ({
{id} diff --git a/packages/frontend/src/views/admin/views/members/staff/administrators/create-edit-form/hooks/use-form.ts b/packages/frontend/src/views/admin/views/members/staff/administrators/create-edit-form/hooks/use-form.ts index c9cbcb9f9..a337d2d02 100644 --- a/packages/frontend/src/views/admin/views/members/staff/administrators/create-edit-form/hooks/use-form.ts +++ b/packages/frontend/src/views/admin/views/members/staff/administrators/create-edit-form/hooks/use-form.ts @@ -56,10 +56,10 @@ export const useFormCreateEditFormGroupsMembersAdmin = ({ .array( z.object({ plugin_code: z.string(), - permissions: z.array( + groups: z.array( z.object({ id: z.string(), - children: z.array(z.string()), + permissions: z.array(z.string()), }), ), }), diff --git a/packages/frontend/src/views/admin/views/members/staff/permissions-field.tsx b/packages/frontend/src/views/admin/views/members/staff/permissions-field.tsx index 8f2510cb2..3f2fbcc17 100644 --- a/packages/frontend/src/views/admin/views/members/staff/permissions-field.tsx +++ b/packages/frontend/src/views/admin/views/members/staff/permissions-field.tsx @@ -20,9 +20,9 @@ export interface PermissionsFieldProps { } interface PermissionState { - permissions: { - children: string[]; + groups: { id: string; + permissions: string[]; }[]; plugin_code: string; } @@ -66,8 +66,8 @@ export function PermissionsField({ )} key={plugin.plugin_code} > - {plugin.permissions.map(permission => { - const permissionValue = valuePlugin?.permissions.find( + {plugin.groups.map(permission => { + const groupValue = valuePlugin?.groups.find( p => p.id === permission.id, ); const langKey = `admin_${plugin.plugin_code}.admin_permissions.${permission.id}`; @@ -80,7 +80,7 @@ export function PermissionsField({ >
{ if (checked) { @@ -90,14 +90,14 @@ export function PermissionsField({ ), { plugin_code: plugin.plugin_code, - permissions: valuePlugin + groups: valuePlugin ? [ - ...valuePlugin.permissions.filter( + ...valuePlugin.groups.filter( p => p.id !== permission.id, ), - { id: permission.id, children: [] }, + { id: permission.id, permissions: [] }, ] - : [{ id: permission.id, children: [] }], + : [{ id: permission.id, permissions: [] }], }, ]; field.onChange(valueToChange); @@ -113,7 +113,7 @@ export function PermissionsField({ ), { ...valuePlugin, - permissions: valuePlugin.permissions.filter( + groups: valuePlugin.groups.filter( p => p.id !== permission.id, ), }, @@ -121,7 +121,7 @@ export function PermissionsField({ field.onChange( valueToChange.filter( - value => value.permissions.length > 0, + value => value.groups.length > 0, ), ); }} @@ -140,10 +140,10 @@ export function PermissionsField({
- {permission.children.length > 0 && ( + {permission.permissions.length > 0 && (
    - {permission.children.map(child => { - const childValue = permissionValue?.children.find( + {permission.permissions.map(child => { + const childValue = groupValue?.permissions.find( c => c === child, ); const childLangKey = `${langKey}_${child}`; @@ -156,7 +156,7 @@ export function PermissionsField({ { @@ -169,16 +169,16 @@ export function PermissionsField({ ), { plugin_code: plugin.plugin_code, - permissions: valuePlugin + groups: valuePlugin ? [ - ...valuePlugin.permissions.filter( + ...valuePlugin.groups.filter( p => p.id !== permission.id, ), { id: permission.id, - children: permissionValue + permissions: groupValue ? [ - ...permissionValue.children, + ...groupValue.permissions, child, ] : [child], @@ -187,7 +187,7 @@ export function PermissionsField({ : [ { id: permission.id, - children: [child], + permissions: [child], }, ], }, @@ -207,22 +207,20 @@ export function PermissionsField({ ), { ...valuePlugin, - permissions: valuePlugin.permissions.map( - p => { - if (p.id !== permission.id) return p; + groups: valuePlugin.groups.map(p => { + if (p.id !== permission.id) return p; - return { - ...p, - children: childValue - ? p.children.filter( - c => c !== child, - ) - : permission.children.filter( - c => c !== child, - ), - }; - }, - ), + return { + ...p, + permissions: childValue + ? p.permissions.filter( + c => c !== child, + ) + : permission.permissions.filter( + c => c !== child, + ), + }; + }), }, ]; @@ -230,9 +228,9 @@ export function PermissionsField({ value => value.plugin_code === plugin.plugin_code && - value.permissions.find( + value.groups.find( p => p.id === permission.id, - )?.children.length === 0, + )?.permissions.length === 0, ); const returnValue: PermissionState[] = @@ -246,18 +244,16 @@ export function PermissionsField({ ) { return { ...item, - permissions: - item.permissions.filter( - p => p.id !== permission.id, - ), + permissions: item.groups.filter( + p => p.id !== permission.id, + ), }; } return item; }) .filter( - plugin => - plugin.permissions.length > 0, + plugin => plugin.groups.length > 0, ) : valueToChange;