Skip to content

Commit e86d96f

Browse files
committed
feat:Non-administrators forbid editing connections
1 parent 196ab50 commit e86d96f

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

chat2db-client/src/components/ConnectionEdit/components/Driver/index.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,16 @@ export default memo<IProps>((props) => {
146146
) : (
147147
<div />
148148
)}
149-
150-
<div
151-
className={styles.uploadCustomDrive}
152-
onClick={() => {
153-
setUploadDriverModal(true);
154-
}}
155-
>
156-
{i18n('connection.tips.customUpload')}
157-
</div>
149+
{backfillData.isAdmin !== false && (
150+
<div
151+
className={styles.uploadCustomDrive}
152+
onClick={() => {
153+
setUploadDriverModal(true);
154+
}}
155+
>
156+
{i18n('connection.tips.customUpload')}
157+
</div>
158+
)}
158159
</div>
159160
<Modal
160161
destroyOnClose={true}

chat2db-client/src/components/ConnectionEdit/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const ConnectionEdit = forwardRef((props: IProps, ref: ForwardedRef<ICreateConne
113113
backfillData={backfillData!}
114114
form={sshForm}
115115
tab="ssh"
116+
disabled={backfillData.isAdmin === false}
116117
/>
117118
<div className={styles.testSSHConnect}>
118119
{loadings.sshTestLoading && <LoadingGracile />}
@@ -268,6 +269,7 @@ const ConnectionEdit = forwardRef((props: IProps, ref: ForwardedRef<ICreateConne
268269
backfillData={backfillData!}
269270
form={baseInfoForm}
270271
tab="baseInfo"
272+
disabled={backfillData.isAdmin === false}
271273
/>
272274
</div>
273275
<Collapse defaultActiveKey={['driver']} items={getItems()} />
@@ -308,6 +310,7 @@ interface IRenderFormProps {
308310
form: any;
309311
backfillData: IConnectionDetails;
310312
dataSourceFormConfigProps: IConnectionConfig;
313+
disabled: boolean
311314
}
312315

313316
function RenderForm(props: IRenderFormProps) {
@@ -580,6 +583,7 @@ function RenderForm(props: IRenderFormProps) {
580583
autoComplete="off"
581584
labelAlign="left"
582585
onFieldsChange={onFieldsChange}
586+
disabled={props.disabled}
583587
>
584588
{dataSourceFormConfig[tab]!.items.map((t) => renderFormItem(t))}
585589
</Form>
@@ -607,6 +611,8 @@ function RenderExtendTable(props: IRenderExtendTableProps) {
607611
return t.type === databaseType;
608612
});
609613
}, [backfillData.type]);
614+
// 禁止修改
615+
const disabled = backfillData.isAdmin === false;
610616

611617
useEffect(() => {
612618
const extendInfoList = backfillData?.extendInfo?.length
@@ -673,6 +679,7 @@ function RenderExtendTable(props: IRenderExtendTableProps) {
673679
if (index === data.length - 1 || isCustomLabel) {
674680
return (
675681
<Input
682+
disabled={disabled}
676683
onBlur={blur}
677684
placeholder={index === data.length - 1 ? i18n('common.text.custom') : ''}
678685
onChange={change}
@@ -699,12 +706,10 @@ function RenderExtendTable(props: IRenderExtendTableProps) {
699706
setData(newData);
700707
}
701708

702-
function blur() {}
703-
704709
if (index === data.length - 1) {
705710
return <Input onBlur={blur} disabled placeholder="<value>" onChange={change} value={value} />;
706711
} else {
707-
return <Input onChange={change} value={value} />;
712+
return <Input disabled={disabled} onChange={change} value={value} />;
708713
}
709714
},
710715
},

chat2db-client/src/typings/connection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface IConnectionDetails {
3131
environment: IConnectionEnv;
3232
type: DatabaseTypeCode;
3333

34+
isAdmin: boolean;
3435
url: string;
3536
user: string;
3637
password: string;

0 commit comments

Comments
 (0)