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: password is removed from DB if registry is modified without checking the change password option #2875

Merged
merged 1 commit into from
Nov 26, 2024
Merged
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
114 changes: 87 additions & 27 deletions react/src/components/ContainerRegistryEditorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import HiddenFormItem from './HiddenFormItem';
import { ContainerRegistryEditorModalCreateMutation } from './__generated__/ContainerRegistryEditorModalCreateMutation.graphql';
import { ContainerRegistryEditorModalFragment$key } from './__generated__/ContainerRegistryEditorModalFragment.graphql';
import { ContainerRegistryEditorModalModifyMutation } from './__generated__/ContainerRegistryEditorModalModifyMutation.graphql';
import { ContainerRegistryEditorModalModifyWithoutPasswordMutation } from './__generated__/ContainerRegistryEditorModalModifyWithoutPasswordMutation.graphql';
import { Form, Input, Select, Checkbox, FormInstance, App } from 'antd';
import graphql from 'babel-plugin-relay/macro';
import _ from 'lodash';
Expand Down Expand Up @@ -99,6 +100,39 @@ const ContainerRegistryEditorModal: React.FC<
}
`);

const [
commitModifyRegistryWithoutPassword,
isInflightModifyRegistryWithoutPassword,
] = useMutation<ContainerRegistryEditorModalModifyWithoutPasswordMutation>(
graphql`
mutation ContainerRegistryEditorModalModifyWithoutPasswordMutation(
$id: String!
$registry_name: String
$type: ContainerRegistryTypeField
$url: String
$is_global: Boolean
$project: String
$ssl_verify: Boolean
$username: String
) {
modify_container_registry_node(
id: $id
registry_name: $registry_name
type: $type
url: $url
is_global: $is_global
project: $project
ssl_verify: $ssl_verify
username: $username
) {
container_registry {
id
}
}
}
`,
);

const handleSave = async () => {
return formRef.current
?.validateFields()
Expand All @@ -120,34 +154,56 @@ const ContainerRegistryEditorModal: React.FC<
if (containerRegistry) {
if (!values.isChangedPassword) {
delete mutationVariables.password;
}
mutationVariables = _.omitBy(mutationVariables, _.isNil) as Required<
typeof mutationVariables
>;
commitModifyRegistry({
variables: mutationVariables,
onCompleted: (res, errors) => {
if (
_.isEmpty(
res.modify_container_registry_node?.container_registry,
)
) {
commitModifyRegistryWithoutPassword({
variables: mutationVariables,
onCompleted: (res, errors) => {
if (
_.isEmpty(
res.modify_container_registry_node?.container_registry,
)
) {
message.error(t('dialog.ErrorOccurred'));
return;
}
if (errors && errors.length > 0) {
const errorMsgList = _.map(errors, (error) => error.message);
for (const error of errorMsgList) {
message.error(error, 2.5);
}
} else {
onOk && onOk('modify');
}
},
onError: (error) => {
message.error(t('dialog.ErrorOccurred'));
return;
}
if (errors && errors.length > 0) {
const errorMsgList = _.map(errors, (error) => error.message);
for (const error of errorMsgList) {
message.error(error, 2.5);
},
});
} else {
commitModifyRegistry({
variables: mutationVariables,
onCompleted: (res, errors) => {
if (
_.isEmpty(
res.modify_container_registry_node?.container_registry,
)
) {
message.error(t('dialog.ErrorOccurred'));
return;
}
} else {
onOk && onOk('modify');
}
},
onError: (error) => {
message.error(t('dialog.ErrorOccurred'));
},
});
if (errors && errors.length > 0) {
const errorMsgList = _.map(errors, (error) => error.message);
for (const error of errorMsgList) {
message.error(error, 2.5);
}
} else {
onOk && onOk('modify');
}
},
onError: (error) => {
message.error(t('dialog.ErrorOccurred'));
},
});
}
} else {
mutationVariables = _.omitBy(mutationVariables, _.isNil) as Required<
typeof mutationVariables
Expand Down Expand Up @@ -188,7 +244,11 @@ const ContainerRegistryEditorModal: React.FC<
: t('registry.AddRegistry')
}
okText={containerRegistry ? t('button.Save') : t('button.Add')}
confirmLoading={isInflightCreateRegistry || isInflightModifyRegistry}
confirmLoading={
isInflightCreateRegistry ||
isInflightModifyRegistry ||
isInflightModifyRegistryWithoutPassword
}
onOk={() => {
formRef.current
?.validateFields()
Expand Down