diff options
author | softwarefactory-project-zuul[bot] <33884098+softwarefactory-project-zuul[bot]@users.noreply.github.com> | 2020-11-30 19:44:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-30 19:44:56 +0100 |
commit | ffb2198eabbb14fad2a36aa470ffc682375d6a3b (patch) | |
tree | 35d19aa611c3a6c48fd5de63564d461a3829c7ca | |
parent | Merge pull request #8672 from wenottingham/if-you-are-sneakerneting-does-it-b... (diff) | |
parent | Mark organization as a required field for Galaxy crendentials (diff) | |
download | awx-ffb2198eabbb14fad2a36aa470ffc682375d6a3b.tar.xz awx-ffb2198eabbb14fad2a36aa470ffc682375d6a3b.zip |
Merge pull request #8594 from nixocio/ui_issue_8276
Mark organization as a required field for Galaxy crendentials
Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
4 files changed, 176 insertions, 2 deletions
diff --git a/awx/ui_next/src/screens/Credential/shared/CredentialForm.jsx b/awx/ui_next/src/screens/Credential/shared/CredentialForm.jsx index c3d6856136..5d5382cbe0 100644 --- a/awx/ui_next/src/screens/Credential/shared/CredentialForm.jsx +++ b/awx/ui_next/src/screens/Credential/shared/CredentialForm.jsx @@ -22,12 +22,26 @@ function CredentialFormFields({ initialValues, }) { const { setFieldValue } = useFormikContext(); - const [orgField, orgMeta, orgHelpers] = useField('organization'); + const [credTypeField, credTypeMeta, credTypeHelpers] = useField({ name: 'credential_type', validate: required(i18n._(t`Select a value for this field`), i18n), }); + const isGalaxyCredential = + !!credTypeField.value && + credentialTypes[credTypeField.value].kind === 'galaxy'; + + const [orgField, orgMeta, orgHelpers] = useField({ + name: 'organization', + validate: + isGalaxyCredential && + required( + i18n._(t`Galaxy credentials must be owned by an Organization.`), + i18n + ), + }); + const credentialTypeOptions = Object.keys(credentialTypes) .map(key => { return { @@ -108,6 +122,7 @@ function CredentialFormFields({ value={orgField.value} touched={orgMeta.touched} error={orgMeta.error} + required={isGalaxyCredential} /> <FormGroup fieldId="credential-Type" diff --git a/awx/ui_next/src/screens/Credential/shared/CredentialForm.test.jsx b/awx/ui_next/src/screens/Credential/shared/CredentialForm.test.jsx index 7f6fa35aa8..20563460da 100644 --- a/awx/ui_next/src/screens/Credential/shared/CredentialForm.test.jsx +++ b/awx/ui_next/src/screens/Credential/shared/CredentialForm.test.jsx @@ -4,6 +4,7 @@ import { mountWithContexts } from '../../../../testUtils/enzymeHelpers'; import machineCredential from './data.machineCredential.json'; import gceCredential from './data.gceCredential.json'; import scmCredential from './data.scmCredential.json'; +import galaxyCredential from './data.galaxyCredential.json'; import credentialTypesArr from './data.credentialTypes.json'; import CredentialForm from './CredentialForm'; @@ -324,5 +325,25 @@ describe('<CredentialForm />', () => { gceFieldExpects(); }); + + test('should display from fields for galaxy/automation hub credentials', async () => { + await act(async () => { + wrapper = mountWithContexts( + <CredentialForm + onCancel={onCancel} + onSubmit={onSubmit} + credential={galaxyCredential} + credentialTypes={credentialTypes} + /> + ); + }); + expect(wrapper.find('FormGroup[label="Name"]').length).toBe(1); + expect(wrapper.find('FormGroup[label="Description"]').length).toBe(1); + expect(wrapper.find('FormGroup[label="Organization"]').length).toBe(1); + expect( + wrapper.find('FormGroup[label="Organization"]').prop('isRequired') + ).toBe(true); + expect(wrapper.find('FormGroup[label="Credential Type"]').length).toBe(1); + }); }); }); diff --git a/awx/ui_next/src/screens/Credential/shared/data.credentialTypes.json b/awx/ui_next/src/screens/Credential/shared/data.credentialTypes.json index 98db5efeab..b7b3189951 100644 --- a/awx/ui_next/src/screens/Credential/shared/data.credentialTypes.json +++ b/awx/ui_next/src/screens/Credential/shared/data.credentialTypes.json @@ -1269,5 +1269,54 @@ "required": ["vault_password"] }, "injectors": {} - } + }, + { + "id": 42, + "type": "credential_type", + "url": "/api/v2/credential_types/42/", + "related": { + "credentials": "/api/v2/credential_types/42/credentials/", + "activity_stream": "/api/v2/credential_types/42/activity_stream/" + }, + "summary_fields": { + "user_capabilities": { + "edit": true, + "delete": true + } + }, + "created": "2020-11-11T00:18:31.928286Z", + "modified": "2020-11-11T00:19:00.851597Z", + "name": "Ansible Galaxy/Automation Hub API Token", + "description": "", + "kind": "galaxy", + "namespace": "galaxy_api_token", + "managed_by_tower": true, + "inputs": { + "fields": [ + { + "id": "url", + "label": "Galaxy Server URL", + "type": "string", + "help_text": "The URL of the Galaxy instance to connect to." + }, + { + "id": "auth_url", + "label": "Auth Server URL", + "type": "string", + "help_text": "The URL of a Keycloak server token_endpoint, if using SSO auth." + }, + { + "id": "token", + "label": "API Token", + "type": "string", + "secret": true, + "help_text": "A token to use for authentication against the Galaxy instance." + } + ], + "required": [ + "url" + ] + }, + "injectors": {} +} ] diff --git a/awx/ui_next/src/screens/Credential/shared/data.galaxyCredential.json b/awx/ui_next/src/screens/Credential/shared/data.galaxyCredential.json new file mode 100644 index 0000000000..a8c7184548 --- /dev/null +++ b/awx/ui_next/src/screens/Credential/shared/data.galaxyCredential.json @@ -0,0 +1,89 @@ +{ + "id": 5, + "type": "credential", + "url": "/api/v2/credentials/5/", + "related": { + "named_url": "/api/v2/credentials/Foo++Ansible Galaxy%2FAutomation Hub API Token+galaxy++Default/", + "created_by": "/api/v2/users/1/", + "modified_by": "/api/v2/users/1/", + "organization": "/api/v2/organizations/1/", + "activity_stream": "/api/v2/credentials/5/activity_stream/", + "access_list": "/api/v2/credentials/5/access_list/", + "object_roles": "/api/v2/credentials/5/object_roles/", + "owner_users": "/api/v2/credentials/5/owner_users/", + "owner_teams": "/api/v2/credentials/5/owner_teams/", + "copy": "/api/v2/credentials/5/copy/", + "input_sources": "/api/v2/credentials/5/input_sources/", + "credential_type": "/api/v2/credential_types/42/" + }, + "summary_fields": { + "organization": { + "id": 1, + "name": "Baz", + "description": "" + }, + "credential_type": { + "id": 42, + "name": "Ansible Galaxy/Automation Hub API Token", + "description": "" + }, + "created_by": { + "id": 1, + "username": "admin", + "first_name": "", + "last_name": "" + }, + "modified_by": { + "id": 1, + "username": "admin", + "first_name": "", + "last_name": "" + }, + "object_roles": { + "admin_role": { + "description": "Can manage all aspects of the credential", + "name": "Admin", + "id": 109 + }, + "use_role": { + "description": "Can use the credential in a job template", + "name": "Use", + "id": 110 + }, + "read_role": { + "description": "May view settings for the credential", + "name": "Read", + "id": 111 + } + }, + "user_capabilities": { + "edit": true, + "delete": true, + "copy": true, + "use": true + }, + "owners": [ + { + "id": 1, + "type": "organization", + "name": "Default", + "description": "", + "url": "/api/v2/organizations/1/" + } + ] + }, + "created": "2020-11-16T21:33:39.385284Z", + "modified": "2020-11-16T21:33:39.385311Z", + "name": "Foo", + "description": "Bar", + "organization": 1, + "credential_type": 42, + "managed_by_tower": false, + "inputs": { + "url": "https://localhost.com", + "auth_url": "" + }, + "kind": "galaxy_api_token", + "cloud": false, + "kubernetes": false +}
\ No newline at end of file |