Provisioning: Allow viewers to view /status subresource and wait on the frontend before sync (#111576)

This commit is contained in:
Stephanie Hingtgen
2025-09-24 22:37:55 +00:00
committed by GitHub
parent 64c700e563
commit 9172daa3dd
4 changed files with 45 additions and 4 deletions
+5 -1
View File
@@ -355,7 +355,11 @@ func (b *APIBuilder) GetAuthorizer() authorizer.Authorizer {
} else {
return authorizer.DecisionDeny, "editor role is required", nil
}
case "status":
if id.GetOrgRole().Includes(identity.RoleViewer) && a.GetVerb() == apiutils.VerbGet {
return authorizer.DecisionAllow, "", nil
}
return authorizer.DecisionDeny, "users cannot update the status of a repository", nil
default:
if id.GetIsGrafanaAdmin() {
return authorizer.DecisionAllow, "", nil
@@ -7,6 +7,7 @@ import {
useCreateRepositoryJobsMutation,
useGetFrontendSettingsQuery,
useGetRepositoryFilesQuery,
useGetRepositoryStatusQuery,
useGetResourceStatsQuery,
} from 'app/api/clients/provisioning/v0alpha1';
@@ -29,6 +30,7 @@ jest.mock('app/api/clients/provisioning/v0alpha1', () => ({
...jest.requireActual('app/api/clients/provisioning/v0alpha1'),
useGetFrontendSettingsQuery: jest.fn(),
useGetRepositoryFilesQuery: jest.fn(),
useGetRepositoryStatusQuery: jest.fn(),
useGetResourceStatsQuery: jest.fn(),
useCreateRepositoryJobsMutation: jest.fn(),
}));
@@ -43,6 +45,9 @@ const mockUseGetFrontendSettingsQuery = useGetFrontendSettingsQuery as jest.Mock
const mockUseGetRepositoryFilesQuery = useGetRepositoryFilesQuery as jest.MockedFunction<
typeof useGetRepositoryFilesQuery
>;
const mockUseGetRepositoryStatusQuery = useGetRepositoryStatusQuery as jest.MockedFunction<
typeof useGetRepositoryStatusQuery
>;
const mockUseGetResourceStatsQuery = useGetResourceStatsQuery as jest.MockedFunction<typeof useGetResourceStatsQuery>;
const mockUseCreateRepositoryJobsMutation = useCreateRepositoryJobsMutation as jest.MockedFunction<
typeof useCreateRepositoryJobsMutation
@@ -131,6 +136,23 @@ describe('ProvisioningWizard', () => {
refetch: jest.fn(),
});
mockUseGetRepositoryStatusQuery.mockReturnValue({
data: {
status: {
health: {
healthy: true,
checked: true,
message: '',
},
},
},
isLoading: false,
isFetching: false,
isError: false,
error: null,
refetch: jest.fn(),
});
mockUseGetResourceStatsQuery.mockReturnValue({
data: {
instance: [],
@@ -40,7 +40,9 @@ export function SynchronizeStep({ isLegacyStorage, onCancel, isCancelling }: Syn
message: repositoryHealthMessages,
checked,
} = repositoryStatusQuery?.data?.status?.health || {};
const isButtonDisabled = checked !== undefined && isRepositoryHealthy === false;
const hasError = repositoryStatusQuery.isError;
const isButtonDisabled = hasError || (checked !== undefined && isRepositoryHealthy === false);
const startSynchronization = async () => {
const [history] = getValues(['migrate.history']);
@@ -65,7 +67,18 @@ export function SynchronizeStep({ isLegacyStorage, onCancel, isCancelling }: Syn
to the repository and provisioned back into the instance.
</Trans>
</Text>
{repositoryHealthMessages && !isRepositoryHealthy && (
{hasError && (
<ProvisioningAlert
error={{
title: t('provisioning.synchronize-step.repository-error', 'Repository error'),
message: t(
'provisioning.synchronize-step.repository-error-message',
'Unable to check repository status. Please verify the repository configuration and try again.'
),
}}
/>
)}
{repositoryHealthMessages && !isRepositoryHealthy && !hasError && (
<ProvisioningAlert
error={{
title: t(
@@ -134,7 +147,7 @@ export function SynchronizeStep({ isLegacyStorage, onCancel, isCancelling }: Syn
)}
<Field noMargin>
{isRepositoryHealthy === false ? (
{hasError || isRepositoryHealthy === false ? (
<Button variant="destructive" onClick={() => onCancel?.(repoName)} disabled={isCancelling}>
{isCancelling ? (
<Trans i18nKey="provisioning.wizard.button-cancelling">Cancelling...</Trans>
+2
View File
@@ -11674,6 +11674,8 @@
"tooltip-unhealthy-repository": "Unable to pull an unhealthy repository"
},
"synchronize-step": {
"repository-error": "Repository error",
"repository-error-message": "Unable to check repository status. Please verify the repository configuration and try again.",
"repository-unhealthy": "The repository cannot be synchronized. Cancel provisioning and try again once the issue has been resolved. See details below.",
"synchronization-description": "Include commits for each historical value",
"synchronization-options": "Synchronization options"