feat(models): scope deployment and model-file create by organization

Add the organization picker to the model deployment and model-file
download forms (platform-admin "all organizations" view). Filter the
cluster / worker pickers to clusters the chosen org owns, so the created
resource's owner stays aligned with where it runs and a cross-org cluster
can't be selected. Carry owner ids on the cluster / worker options to
drive the filter.
This commit is contained in:
gitlawr
2026-06-03 10:14:50 +08:00
committed by jialin
parent fbb707d014
commit 9e30e964e6
4 changed files with 136 additions and 22 deletions
@@ -78,7 +78,12 @@ type AddModalProps = {
deploymentType?: 'modelList' | 'modelFiles';
clusterList: Global.BaseOption<
number,
{ provider: string; state: string | number; is_default: boolean }
{
provider: string;
state: string | number;
is_default: boolean;
owner_principal_id?: number;
}
>[];
onOk: (values: FormData) => void;
onCancel: () => void;
@@ -458,15 +463,24 @@ const AddModal: FC<AddModalProps> = (props) => {
if (initialValues?.cluster_id) {
return initialValues.cluster_id;
}
// When a platform admin has targeted an org via the create-scope picker,
// seed the cluster from that org's own clusters so the initial selection
// matches the (org-filtered) dropdown the form renders.
const scopeOrgId = form.current?.getFieldValue?.('organization_id');
const scopedList =
scopeOrgId == null
? clusterList
: clusterList?.filter((item) => item.owner_principal_id === scopeOrgId);
// Find default cluster
const defaultCluster = clusterList?.find((item) => item.is_default);
const defaultCluster = scopedList?.find((item) => item.is_default);
if (defaultCluster) {
return defaultCluster.value;
}
const cluster_id =
clusterList?.find((item) => item.state === ClusterStatusValueMap.Ready)
?.value || clusterList?.[0]?.value;
scopedList?.find((item) => item.state === ClusterStatusValueMap.Ready)
?.value || scopedList?.[0]?.value;
return cluster_id;
};
@@ -1,3 +1,4 @@
import PluginExtraFields from '@/components/plugin-extra-fields';
import { ModelFileFormData as FormData } from '@/pages/resources/config/types';
import {
Input as CInput,
@@ -14,7 +15,8 @@ import React, {
forwardRef,
useEffect,
useImperativeHandle,
useMemo
useMemo,
useRef
} from 'react';
import { localPathTipsList, modelSourceMap, sourceOptions } from '../../config';
import { useGenerateWorkersModelFileOptions } from '../../hooks';
@@ -55,6 +57,20 @@ const TargetForm: React.FC<TargetFormProps> = forwardRef((props, ref) => {
const intl = useIntl();
const [form] = Form.useForm();
const localPath = Form.useWatch('local_path', form);
// Owned by the create-scope picker slot (admin "All" view). When set, scope
// the worker picker to clusters owned by that org — a model file's owner is
// derived from the target worker's cluster, so this keeps them aligned.
const scopeOrgId = Form.useWatch('organization_id', form);
const prevScopeRef = useRef<number | null | undefined>(undefined);
const visibleWorkerOptions = useMemo(() => {
if (scopeOrgId == null) {
return workerOptions;
}
return (workerOptions || []).filter(
(cluster: any) => cluster.owner_principal_id === scopeOrgId
);
}, [workerOptions, scopeOrgId]);
useEffect(() => {
const init = async () => {
@@ -68,6 +84,19 @@ const TargetForm: React.FC<TargetFormProps> = forwardRef((props, ref) => {
init();
}, [workersList]);
// On a genuine org change, drop the now-out-of-scope worker selection.
useEffect(() => {
if (prevScopeRef.current === undefined) {
prevScopeRef.current = scopeOrgId;
return;
}
if (prevScopeRef.current === scopeOrgId) {
return;
}
prevScopeRef.current = scopeOrgId;
form.setFieldValue('worker_id', undefined);
}, [scopeOrgId]);
useImperativeHandle(ref, () => ({
form
}));
@@ -183,6 +212,10 @@ const TargetForm: React.FC<TargetFormProps> = forwardRef((props, ref) => {
></SealSelect>
}
</Form.Item>
<PluginExtraFields
name="CreateOrgScopeField"
context={{ action: 'create' }}
/>
{renderFieldsBySource}
<Form.Item
name="worker_id"
@@ -212,7 +245,7 @@ const TargetForm: React.FC<TargetFormProps> = forwardRef((props, ref) => {
}}
maxTagCount={1}
label={intl.formatMessage({ id: 'resources.worker' })}
options={workerOptions}
options={visibleWorkerOptions}
showCheckedStrategy="SHOW_CHILD"
optionNode={renderOptionNode}
getPopupContainer={(triggerNode) => triggerNode.parentNode}