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