-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37228 - Replace Ansible/Roles page with React component
- Loading branch information
Showing
18 changed files
with
443 additions
and
97 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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
object @ansible_role | ||
|
||
extends "api/v2/ansible_roles/show" | ||
attributes :id, :name, :updated_at | ||
code :hostgroups_count do |role| | ||
role.hostgroups.count | ||
end | ||
code :hosts_count do |role| | ||
role.hosts.count | ||
end | ||
code :variables_count do |role| | ||
role.ansible_variables.count | ||
end | ||
code :can_delete do | ||
User.current.can?(:destroy_ansible_roles) | ||
end |
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
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
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,78 @@ | ||
import React from 'react'; | ||
import { useAPI } from 'foremanReact/common/hooks/API/APIHooks'; | ||
import TableIndexPage from 'foremanReact/components/PF4/TableIndexPage/TableIndexPage'; | ||
import RelativeDateTime from 'foremanReact/components/common/dates/RelativeDateTime'; | ||
import { translate as __ } from 'foremanReact/common/I18n'; | ||
import { getDocsURL } from 'foremanReact/common/helpers'; | ||
import { | ||
hostgroupsLink, | ||
hostsLink, | ||
variablesLink, | ||
} from './AnsibleRolesPageHelpers'; | ||
import { AnsibleRolesImportButtonWrapper } from './components/AnsibleRolesImportButtonWrapper'; | ||
import { showToast } from '../../toastHelper'; | ||
|
||
export const AnsibleRolesPage = () => { | ||
const { | ||
response: { results }, | ||
status, | ||
} = useAPI('get', '/api/v2/permissions/current_permissions'); | ||
|
||
if (status === 'ERROR') { | ||
showToast({ | ||
type: 'error', | ||
message: __('There was an error requesting user permissions'), | ||
}); | ||
} | ||
|
||
return ( | ||
<TableIndexPage | ||
header={__('Ansible Roles')} | ||
controller="ansible_roles" | ||
apiUrl="/ansible/ui_ansible_roles" | ||
apiOptions={{ key: 'ANSIBLE_ROLES_API_REQUEST_KEY' }} | ||
hasHelpPage | ||
creatable={false} | ||
isDeleteable | ||
customToolbarItems={ | ||
<AnsibleRolesImportButtonWrapper | ||
apiStatus={status} | ||
allPermissions={results} | ||
/> | ||
} | ||
customHelpURL={getDocsURL( | ||
'Managing_Configurations_Ansible', | ||
'Importing_Ansible_Roles_and_Variables_ansible' | ||
)} | ||
columns={{ | ||
name: { title: __('Name'), isSorted: true, weight: 0 }, | ||
hostgroups_count: { | ||
title: __('Hostgroups'), | ||
weight: 1, | ||
wrapper: ({ name, hostgroups_count: hostgroupsCount }) => | ||
hostgroupsLink(name, hostgroupsCount, status, results), | ||
}, | ||
hosts_count: { | ||
title: __('Hosts'), | ||
weight: 2, | ||
wrapper: ({ name, hosts_count: hostsCount }) => | ||
hostsLink(name, hostsCount, status, results), | ||
}, | ||
variables_count: { | ||
title: __('Variables'), | ||
weight: 3, | ||
wrapper: ({ name, variables_count: variablesCount }) => | ||
variablesLink(name, variablesCount, status, results), | ||
}, | ||
updated_at: { | ||
title: __('Imported at'), | ||
isSorted: true, | ||
weight: 4, | ||
wrapper: ({ updated_at: updatedAt }) => ( | ||
<RelativeDateTime date={new Date(updatedAt)} /> | ||
), | ||
}, | ||
}} | ||
/> | ||
); | ||
}; |
61 changes: 61 additions & 0 deletions
61
webpack/components/AnsibleRoles/AnsibleRolesPageHelpers.js
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,61 @@ | ||
import React from 'react'; | ||
|
||
export const hostgroupsLink = ( | ||
roleName, | ||
hostgroupsCount, | ||
apiStatus, | ||
permissions | ||
) => { | ||
if ( | ||
apiStatus === 'RESOLVED' && | ||
permissions.some(perm => perm.name === 'view_hostgroups') | ||
) { | ||
return link(hostgroupsUrl(roleName), hostgroupsCount); | ||
} | ||
return hostgroupsCount; | ||
}; | ||
|
||
export const hostsLink = ( | ||
roleName, | ||
hostgroupsCount, | ||
apiStatus, | ||
permissions | ||
) => { | ||
if ( | ||
apiStatus === 'RESOLVED' && | ||
permissions.some(perm => perm.name === 'view_hosts') | ||
) { | ||
return link(hostsUrl(roleName), hostgroupsCount); | ||
} | ||
return hostgroupsCount; | ||
}; | ||
|
||
export const variablesLink = ( | ||
roleName, | ||
hostgroupsCount, | ||
apiStatus, | ||
permissions | ||
) => { | ||
if ( | ||
apiStatus === 'RESOLVED' && | ||
permissions.some(perm => perm.name === 'view_ansible_variables') | ||
) { | ||
return link(variablesUrl(roleName), hostgroupsCount); | ||
} | ||
return hostgroupsCount; | ||
}; | ||
|
||
const link = (url, displayText) => ( | ||
<a href={url} target="_blank" rel="noreferrer"> | ||
{displayText} | ||
</a> | ||
); | ||
|
||
const hostgroupsUrl = roleName => `/hostgroups${searchString(roleName)}`; | ||
const hostsUrl = roleName => `/new/hosts${searchString(roleName)}`; | ||
const variablesUrl = roleName => `ansible_variables${searchString(roleName)}`; | ||
const searchString = roleName => | ||
`?search=${encodeURIComponent(`ansible_role = ${roleName}`)}`; | ||
|
||
export const importUrl = (proxyName, proxyId) => | ||
`ansible_roles/import?proxy=${encodeURIComponent(`${proxyId}-${proxyName}`)}`; |
31 changes: 31 additions & 0 deletions
31
webpack/components/AnsibleRoles/components/AnsibleRolesImportButton.fixtures.js
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,31 @@ | ||
export const testSmartProxies = [ | ||
{ | ||
created_at: '2024-06-21 14:49:35 +0200', | ||
updated_at: '2024-06-21 14:49:35 +0200', | ||
hosts_count: 0, | ||
name: 'debuggable', | ||
id: 2, | ||
url: 'http://smart-proxy-ansible-capable.example.com:8080', | ||
remote_execution_pubkey: null, | ||
download_policy: 'on_demand', | ||
supported_pulp_types: [], | ||
lifecycle_environments: [], | ||
features: [ | ||
{ | ||
capabilities: ['ansible-runner', 'single'], | ||
name: 'Dynflow', | ||
id: 17, | ||
}, | ||
{ | ||
capabilities: ['vcs_clone'], | ||
name: 'Ansible', | ||
id: 20, | ||
}, | ||
{ | ||
capabilities: [], | ||
name: 'Logs', | ||
id: 13, | ||
}, | ||
], | ||
}, | ||
]; |
Oops, something went wrong.