Allow modify scm branch override

* Source Control Branch was not being displayed as part of the
JobTemplate Edit, since the project did not have the variable
`allow_override` as part of the summary_fields.

* Add source control details for JobDetail and WorkflowJobTemplateDetail

See: https://github.com/ansible/awx/issues/8788
This commit is contained in:
nixocio 2021-05-06 16:44:36 -04:00
parent 82af78fe33
commit 5fb9afc9f5
12 changed files with 57 additions and 6 deletions

View File

@ -150,7 +150,7 @@ SUMMARIZABLE_FK_FIELDS = {
'group': DEFAULT_SUMMARY_FIELDS,
'default_environment': DEFAULT_SUMMARY_FIELDS + ('image',),
'execution_environment': DEFAULT_SUMMARY_FIELDS + ('image',),
'project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type'),
'project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type', 'allow_override'),
'source_project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type'),
'project_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed'),
'credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'cloud', 'kubernetes', 'credential_type_id'),

View File

@ -24,7 +24,6 @@ const QS_CONFIG = getQSConfig('project', {
function ProjectLookup({
helperTextInvalid,
autoPopulate,
isValid,
onChange,
required,

View File

@ -68,6 +68,7 @@ function JobDetail({ job }) {
source_workflow_job,
execution_environment: executionEnvironment,
} = job.summary_fields;
const { scm_branch: scmBranch } = job;
const [errorMsg, setErrorMsg] = useState();
const history = useHistory();
@ -224,6 +225,13 @@ function JobDetail({ job }) {
}
/>
)}
{scmBranch && (
<Detail
dataCy="source-control-branch"
label={t`Source Control Branch`}
value={scmBranch}
/>
)}
<Detail label={t`Revision`} value={job.scm_revision} />
<Detail label={t`Playbook`} value={job.playbook} />
<Detail label={t`Limit`} value={job.limit} />

View File

@ -64,6 +64,7 @@ describe('<JobDetail />', () => {
assertDetail('Job Slice', '0/1');
assertDetail('Credentials', 'SSH: Demo Credential');
assertDetail('Machine Credential', 'SSH: Machine cred');
assertDetail('Source Control Branch', 'main');
const executionEnvironment = wrapper.find('ExecutionEnvironmentDetail');
expect(executionEnvironment).toHaveLength(1);

View File

@ -103,6 +103,7 @@
"inventory": 1,
"project": 6,
"playbook": "chatty_tasks.yml",
"scm_branch": "main",
"forks": 0,
"limit": "",
"verbosity": 0,

View File

@ -70,7 +70,6 @@ function ProjectFormFields({
project_base_dir,
project_local_paths,
formik,
setCredentials,
credentials,
scmTypeOptions,

View File

@ -44,6 +44,7 @@ function WorkflowJobTemplateDetail({ template }) {
related,
webhook_credential,
webhook_key,
scm_branch: scmBranch,
} = template;
const urlOrigin = window.location.origin;
@ -130,6 +131,13 @@ function WorkflowJobTemplateDetail({ template }) {
}
/>
)}
{scmBranch && (
<Detail
dataCy="source-control-branch"
label={t`Source Control Branch`}
value={scmBranch}
/>
)}
{summary_fields?.execution_environment && (
<Detail
label={t`Execution Environment`}

View File

@ -50,6 +50,7 @@ describe('<WorkflowJobTemplateDetail/>', () => {
webhook_service: 'Github',
webhook_key: 'Foo webhook key',
execution_environment: 4,
scm_branch: 'main',
};
beforeEach(async () => {
@ -109,6 +110,11 @@ describe('<WorkflowJobTemplateDetail/>', () => {
prop: 'value',
value: 'http://localhost/api/v2/workflow_job_templates/45/github/',
},
{
element: 'Detail[label="Source Control Branch"]',
prop: 'value',
value: 'main',
},
{
element: "Detail[label='Webhook Service']",
prop: 'value',

View File

@ -313,10 +313,11 @@ function JobTemplateForm({
>
<TextInput
id="template-scm-branch"
{...scmField}
onChange={value => {
scmHelpers.setValue(value);
}}
value={scmField.value}
aria-label={t`source control branch`}
/>
</FieldWithPrompt>
)}
@ -660,6 +661,7 @@ JobTemplateForm.defaultProps = {
inventory: undefined,
project: undefined,
playbook: '',
scm_branch: '',
summary_fields: {
inventory: null,
labels: { results: [] },

View File

@ -40,6 +40,7 @@ describe('<JobTemplateForm />', () => {
project: {
id: 3,
name: 'qux',
allow_override: false,
},
labels: {
results: [
@ -113,7 +114,7 @@ describe('<JobTemplateForm />', () => {
ProjectsAPI.readDetail.mockReturnValue({
name: 'foo',
id: 1,
allow_override: true,
allow_override: false,
});
ProjectsAPI.readPlaybooks.mockReturnValue({
data: ['debug.yml'],
@ -152,6 +153,30 @@ describe('<JobTemplateForm />', () => {
);
});
test('should not render source control branch when allow_override is false', async () => {
let wrapper;
await act(async () => {
wrapper = mountWithContexts(
<JobTemplateForm
template={mockData}
handleSubmit={jest.fn()}
handleCancel={jest.fn()}
/>
);
});
wrapper.update();
expect(wrapper.find('TextInputBase#template-scm-branch').length).toEqual(0);
await act(async () => {
wrapper.find('ProjectLookup').invoke('onChange')({
id: 4,
name: 'project',
allow_override: true,
});
});
wrapper.update();
expect(wrapper.find('TextInputBase#template-scm-branch').length).toEqual(1);
});
test('should update form values on input changes', async () => {
let wrapper;
await act(async () => {

View File

@ -186,10 +186,11 @@ function WorkflowJobTemplateForm({
>
<TextInput
id="wfjt-scm-branch"
{...scmField}
value={scmField.value}
onChange={value => {
scmHelpers.setValue(value);
}}
aria-label={t`source control branch`}
/>
</FieldWithPrompt>
<ExecutionEnvironmentLookup

View File

@ -83,6 +83,7 @@ export const JobTemplate = shape({
job_type: oneOf(['run', 'check']),
playbook: string,
project: number,
scm_branch: string,
});
export const WorkFlowJobTemplate = shape({