Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not require change password to change reporting configuration #1004

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/ReportingConfig/ReportingConfigForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ class ReportingConfigForm extends React.Component {
* @param {FormData} formData
* @param {[String]} requiredFields
*/
validateReportingForm = (formData, requiredFields) => {
validateReportingForm = (config, formData, requiredFields) => {
const invalidFields = requiredFields
.filter(field => !formData.get(field))
.reduce((prevFields, currField) => ({ ...prevFields, [currField]: true }), {});

// Password is conditionally required only when pgp key will not be present
// and delivery method is email
if (!formData.get('pgpEncryptionKey') && formData.get('deliveryMethod') === 'email') {
if (!formData.get('encryptedPassword')) {
if (!formData.get('encryptedPassword') && !config?.encryptedPassword) {
invalidFields.encryptedPassword = true;
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ class ReportingConfigForm extends React.Component {
requiredFields = config ? [...REQUIRED_SFTP_FIELDS] : [...REQUIRED_NEW_SFTP_FEILDS];
}
// validate the form
const invalidFields = this.validateReportingForm(formData, requiredFields);
const invalidFields = this.validateReportingForm(config, formData, requiredFields);
// if there are invalid fields, reflect that in the UI
if (!isEmpty(invalidFields)) {
this.setState((state) => ({
Expand Down
32 changes: 32 additions & 0 deletions src/components/ReportingConfig/ReportingConfigForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,38 @@ describe('<ReportingConfigForm />', () => {
wrapper.find('.form-control').forEach(input => input.simulate('blur'));
expect(wrapper.find('input#encryptedPassword').hasClass('is-invalid')).toBeTruthy();
});
it('Password is not required while updating if it is already present and delivery method is email', async () => {
const updateConfigMock = jest.fn().mockResolvedValue();
const initialConfig = {
...defaultConfig,
};
initialConfig.encryptedPassword = 'some_pass';
initialConfig.pgpEncryptionKey = '';
initialConfig.hourOfDay = 4;
const requiredFields = ['hourOfDay', 'emailRaw'];
const wrapper = mount(
<ReportingConfigForm
config={initialConfig}
createConfig={createConfig}
updateConfig={updateConfigMock}
availableCatalogs={availableCatalogs}
reportingConfigTypes={reportingConfigTypes}
enterpriseCustomerUuid={enterpriseCustomerUuid}
/>,
);

const updatedFormData = new FormData();
updatedFormData.append('deliveryMethod', 'email');
updatedFormData.append('pgpEncryptionKey', '');
updatedFormData.append('encryptedPassword', '');

const invalidFields = await wrapper.instance().validateReportingForm(
initialConfig,
updatedFormData,
requiredFields,
);
expect('encryptedPassword' in invalidFields).toBe(false);
});
it('Submit enterprise uuid upon report config creation', async () => {
const wrapper = mount((
<ReportingConfigForm
Expand Down