-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow edit groups from an agent (#6250)
* Agent groups column refactor and allow remove * Agent groups allow edit * Edit agent groups modal * Fix links las registered agent * Agent table with actions * Extend funtionality from button with permissions and restore groups trucate component * Modularize agents table actions * Fix table filters * Add form modal message * Add CHANGELOG * Update snapshot * Fix return * Fix actions field * Fix snapshot * Disable 'View details' actions when agent never connected * Delete 'Upgrade' action
- Loading branch information
1 parent
ff561c5
commit e649ae2
Showing
26 changed files
with
1,032 additions
and
760 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
plugins/main/public/components/common/permissions/element.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Wazuh app - Button with Wazuh API permissions and/or roles required to be useful | ||
* Copyright (C) 2015-2022 Wazuh, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Find more information about this on the LICENSE file. | ||
*/ | ||
|
||
import React, { Fragment } from 'react'; | ||
import { useUserPermissionsRequirements } from '../hooks/useUserPermissions'; | ||
import { useUserRolesRequirements } from '../hooks/useUserRoles'; | ||
|
||
import { EuiToolTip, EuiSpacer } from '@elastic/eui'; | ||
|
||
import { WzPermissionsFormatted } from './format'; | ||
|
||
export interface IUserPermissionsObject { | ||
action: string; | ||
resource: string; | ||
} | ||
export type TUserPermissionsFunction = (props: any) => TUserPermissions; | ||
export type TUserPermissions = (string | IUserPermissionsObject)[] | null; | ||
export type TUserRoles = string[] | null; | ||
export type TUserRolesFunction = (props: any) => TUserRoles; | ||
|
||
export interface IWzElementPermissionsProps { | ||
permissions?: TUserPermissions | TUserPermissionsFunction; | ||
roles?: TUserRoles | TUserRolesFunction; | ||
tooltip?: any; | ||
children: React.ReactElement; | ||
getAdditionalProps?: (disabled: boolean) => { | ||
[prop: string]: any; | ||
}; | ||
} | ||
|
||
export const WzElementPermissions = ({ | ||
children, | ||
permissions = null, | ||
roles = null, | ||
getAdditionalProps, | ||
tooltip, | ||
...rest | ||
}: IWzElementPermissionsProps) => { | ||
const [userPermissionRequirements] = useUserPermissionsRequirements( | ||
typeof permissions === 'function' ? permissions(rest) : permissions, | ||
); | ||
const [userRolesRequirements] = useUserRolesRequirements( | ||
typeof roles === 'function' ? roles(rest) : roles, | ||
); | ||
|
||
const isDisabledByRolesOrPermissions = | ||
userRolesRequirements || userPermissionRequirements; | ||
|
||
const disabled = Boolean( | ||
isDisabledByRolesOrPermissions || rest?.isDisabled || rest?.disabled, | ||
); | ||
|
||
const additionalProps = getAdditionalProps | ||
? getAdditionalProps(disabled) | ||
: {}; | ||
|
||
const childrenWithAdditionalProps = React.cloneElement(children, { | ||
...additionalProps, | ||
}); | ||
|
||
const contentTextRequirements = isDisabledByRolesOrPermissions && ( | ||
<Fragment> | ||
{userPermissionRequirements && ( | ||
<div> | ||
<div> | ||
Require the{' '} | ||
{userPermissionRequirements.length === 1 | ||
? 'permission' | ||
: 'permissions'} | ||
: | ||
</div> | ||
{WzPermissionsFormatted(userPermissionRequirements)} | ||
</div> | ||
)} | ||
{userPermissionRequirements && userRolesRequirements && ( | ||
<EuiSpacer size='s' /> | ||
)} | ||
{userRolesRequirements && ( | ||
<div> | ||
Require{' '} | ||
{userRolesRequirements | ||
.map(role => ( | ||
<strong key={`empty-prompt-no-roles-${role}`}>{role}</strong> | ||
)) | ||
.reduce((prev, cur) => [prev, ', ', cur])}{' '} | ||
{userRolesRequirements.length > 1 ? 'roles' : 'role'} | ||
</div> | ||
)} | ||
</Fragment> | ||
); | ||
return isDisabledByRolesOrPermissions ? ( | ||
<EuiToolTip {...tooltip} content={contentTextRequirements}> | ||
{childrenWithAdditionalProps} | ||
</EuiToolTip> | ||
) : tooltip && tooltip.content ? ( | ||
<EuiToolTip {...tooltip}>{childrenWithAdditionalProps}</EuiToolTip> | ||
) : ( | ||
childrenWithAdditionalProps | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 0 additions & 81 deletions
81
plugins/main/public/components/common/util/agent-group-truncate/agent_group_truncate.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
plugins/main/public/components/common/util/agent-group-truncate/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export { AgentGroupTruncate } from './agent_group_truncate'; | ||
export { GroupTruncate } from './group-truncate'; | ||
export { GroupTruncate } from './group-truncate'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.