mirror of https://github.com/portainer/portainer
fix(app/templates): non admins cannot load templates list (#12235)
parent
e0b6f2283a
commit
fd26565b14
|
@ -22,7 +22,7 @@ export function AppTemplatesView() {
|
|||
'template',
|
||||
(param) => (param ? parseInt(param, 10) : 0)
|
||||
);
|
||||
const templatesQuery = useAppTemplates();
|
||||
const templatesQuery = useAppTemplates({ environmentId: envId });
|
||||
const selectedTemplate = selectedTemplateId
|
||||
? templatesQuery.data?.find(
|
||||
(template) => template.Id === selectedTemplateId
|
||||
|
|
|
@ -4,6 +4,8 @@ import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|||
import { useRegistries } from '@/react/portainer/registries/queries/useRegistries';
|
||||
import { DockerHubViewModel } from '@/portainer/models/dockerhub';
|
||||
import { Registry } from '@/react/portainer/registries/types/registry';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { useEnvironmentRegistries } from '@/react/portainer/environments/queries/useEnvironmentRegistries';
|
||||
|
||||
import { AppTemplate } from '../types';
|
||||
import { TemplateViewModel } from '../view-model';
|
||||
|
@ -11,22 +13,30 @@ import { TemplateViewModel } from '../view-model';
|
|||
import { buildUrl } from './build-url';
|
||||
|
||||
export function useAppTemplates<T = Array<TemplateViewModel>>({
|
||||
environmentId,
|
||||
select,
|
||||
enabled = true,
|
||||
}: {
|
||||
environmentId?: EnvironmentId;
|
||||
select?: (templates: Array<TemplateViewModel>) => T;
|
||||
enabled?: boolean;
|
||||
} = {}) {
|
||||
const registriesQuery = useRegistries({ enabled });
|
||||
const hasEnvParam = !!environmentId;
|
||||
|
||||
return useQuery(
|
||||
['templates'],
|
||||
() => getTemplatesWithRegistry(registriesQuery.data),
|
||||
{
|
||||
enabled: !!registriesQuery.data && enabled,
|
||||
select,
|
||||
}
|
||||
const environmentRegistriesQuery = useEnvironmentRegistries(
|
||||
environmentId || 0,
|
||||
{ enabled: enabled && hasEnvParam }
|
||||
);
|
||||
const registriesQuery = useRegistries({ enabled: enabled && !hasEnvParam });
|
||||
|
||||
const data = hasEnvParam
|
||||
? environmentRegistriesQuery.data
|
||||
: registriesQuery.data;
|
||||
|
||||
return useQuery(['templates'], () => getTemplatesWithRegistry(data), {
|
||||
enabled: !!data && enabled,
|
||||
select,
|
||||
});
|
||||
}
|
||||
|
||||
export function useAppTemplate(
|
||||
|
|
Loading…
Reference in New Issue