Skip to content

Commit 59c3864

Browse files
fix(preprod): Fix settings api bug for status checks (#106480)
The frontend was sending data wrapped in an options object: {"options": {"sentry:preprod_size_status_checks_enabled": false}} The options field only exists in ProjectAdminSerializer which requires project:write or project:admin scope. Users with only project:read were getting 403 errors. Changed to send top-level camelCase fields that match ProjectMemberSerializer: {"preprodSizeStatusChecksEnabled": false}
1 parent 7594efb commit 59c3864

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

static/app/types/project.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ export type Project = {
8181
latestDeploys?: Record<string, Pick<Deploy, 'dateFinished' | 'version'>> | null;
8282
latestRelease?: {version: string} | null;
8383
options?: Record<string, boolean | string>;
84+
preprodDistributionEnabledQuery?: string | null;
85+
preprodSizeEnabledQuery?: string | null;
86+
preprodSizeStatusChecksEnabled?: boolean;
87+
preprodSizeStatusChecksRules?: unknown[];
8488
securityToken?: string;
8589
securityTokenHeader?: string;
8690
seerScannerAutomation?: boolean;

static/app/views/settings/project/preprod/useStatusCheckRules.ts

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,37 @@ function parseRules(raw: unknown): StatusCheckRule[] {
4747
export function useStatusCheckRules(project: Project) {
4848
const updateProject = useUpdateProject(project);
4949

50-
const enabled = project.options?.[ENABLED_KEY] !== false;
51-
const rulesJson = project.options?.[RULES_KEY];
50+
// Check top-level field first (optimistic update), fallback to options (server response)
51+
const enabled =
52+
project.preprodSizeStatusChecksEnabled ?? project.options?.[ENABLED_KEY] !== false;
53+
54+
const rulesRaw = project.preprodSizeStatusChecksRules ?? project.options?.[RULES_KEY];
5255
const rules: StatusCheckRule[] = useMemo(() => {
53-
if (typeof rulesJson !== 'string') {
56+
if (Array.isArray(rulesRaw)) {
57+
return parseRules(rulesRaw);
58+
}
59+
if (typeof rulesRaw !== 'string') {
5460
return [];
5561
}
5662
try {
57-
return parseRules(JSON.parse(rulesJson));
63+
return parseRules(JSON.parse(rulesRaw));
5864
} catch {
5965
return [];
6066
}
61-
}, [rulesJson]);
67+
}, [rulesRaw]);
6268

6369
const config = {enabled, rules};
6470

65-
const updateConfig = useCallback(
66-
(newOptions: Record<string, string | boolean>, successMessage?: string) => {
71+
const setEnabled = useCallback(
72+
(value: boolean) => {
6773
addLoadingMessage(t('Saving...'));
6874
updateProject.mutate(
69-
{
70-
options: newOptions,
71-
},
75+
{preprodSizeStatusChecksEnabled: value},
7276
{
7377
onSuccess: () => {
74-
if (successMessage) {
75-
addSuccessMessage(successMessage);
76-
}
78+
addSuccessMessage(
79+
value ? t('Status checks enabled.') : t('Status checks disabled.')
80+
);
7781
},
7882
onError: () => {
7983
addErrorMessage(t('Failed to save changes. Please try again.'));
@@ -84,21 +88,24 @@ export function useStatusCheckRules(project: Project) {
8488
[updateProject]
8589
);
8690

87-
const setEnabled = useCallback(
88-
(value: boolean) => {
89-
updateConfig(
90-
{[ENABLED_KEY]: value},
91-
value ? t('Status checks enabled.') : t('Status checks disabled.')
92-
);
93-
},
94-
[updateConfig]
95-
);
96-
9791
const saveRules = useCallback(
9892
(newRules: StatusCheckRule[], successMessage?: string) => {
99-
updateConfig({[RULES_KEY]: JSON.stringify(newRules)}, successMessage);
93+
addLoadingMessage(t('Saving...'));
94+
updateProject.mutate(
95+
{preprodSizeStatusChecksRules: newRules as unknown[]},
96+
{
97+
onSuccess: () => {
98+
if (successMessage) {
99+
addSuccessMessage(successMessage);
100+
}
101+
},
102+
onError: () => {
103+
addErrorMessage(t('Failed to save changes. Please try again.'));
104+
},
105+
}
106+
);
100107
},
101-
[updateConfig]
108+
[updateProject]
102109
);
103110

104111
const addRule = useCallback(

0 commit comments

Comments
 (0)