Browse Source

fix(hybridcloud) Adopt organization scoped prompts-activity (#63141)

Using the organization scoped endpoint will ensure that any requests
that do go to control silo in the future can be routed to the correct
region.

Refs HC-1066

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Mark Story 1 year ago
parent
commit
1343cae0ae

+ 47 - 21
static/app/actionCreators/prompts.tsx

@@ -1,4 +1,5 @@
 import type {Client} from 'sentry/api';
+import type {OrganizationSummary} from 'sentry/types';
 import {ApiQueryKey, useApiQuery, UseApiQueryOptions} from 'sentry/utils/queryClient';
 
 type PromptsUpdateParams = {
@@ -6,11 +7,11 @@ type PromptsUpdateParams = {
    * The prompt feature name
    */
   feature: string;
-  /**
-   * The numeric organization ID as a string
-   */
-  organizationId: string;
   status: 'snoozed' | 'dismissed';
+  // TODO(mark) Remove optional once getsentry is updated.
+  organization?: OrganizationSummary;
+  // Deprecated.
+  organizationId?: string;
   /**
    * The numeric project ID as a string
    */
@@ -21,10 +22,16 @@ type PromptsUpdateParams = {
  * Update the status of a prompt
  */
 export function promptsUpdate(api: Client, params: PromptsUpdateParams) {
-  return api.requestPromise('/prompts-activity/', {
+  const organizationId = params.organization
+    ? params.organization.id
+    : params.organizationId;
+  const url = params.organization
+    ? `/organizations/${params.organization.slug}/prompts-activity/`
+    : '/prompts-activity/';
+  return api.requestPromise(url, {
     method: 'PUT',
     data: {
-      organization_id: params.organizationId,
+      organization_id: organizationId,
       project_id: params.projectId,
       feature: params.feature,
       status: params.status,
@@ -37,10 +44,10 @@ type PromptCheckParams = {
    * The prompt feature name
    */
   feature: string;
-  /**
-   * The numeric organization ID as a string
-   */
-  organizationId: string;
+  // TODO(mark) Remove optional once getsentry change has landed.
+  organization?: OrganizationSummary;
+  // Deprecated To be removed once all usage has organization
+  organizationId?: string;
   /**
    * The numeric project ID as a string
    */
@@ -68,13 +75,19 @@ export async function promptsCheck(
   api: Client,
   params: PromptCheckParams
 ): Promise<PromptData> {
+  const organizationId = params.organization
+    ? params.organization.id
+    : params.organizationId;
   const query = {
     feature: params.feature,
-    organization_id: params.organizationId,
+    organization_id: organizationId,
     ...(params.projectId === undefined ? {} : {project_id: params.projectId}),
   };
+  const url = params.organization
+    ? `/organizations/${params.organization.slug}/prompts-activity/`
+    : '/prompts-activity/';
 
-  const response: PromptResponse = await api.requestPromise('/prompts-activity/', {
+  const response: PromptResponse = await api.requestPromise(url, {
     query,
   });
 
@@ -90,22 +103,27 @@ export async function promptsCheck(
 
 export const makePromptsCheckQueryKey = ({
   feature,
+  organization,
   organizationId,
   projectId,
-}: PromptCheckParams): ApiQueryKey => [
-  '/prompts-activity/',
-  {query: {feature, organization_id: organizationId, project_id: projectId}},
-];
+}: PromptCheckParams): ApiQueryKey => {
+  const orgId = organization ? organization.id : organizationId;
+  const url = organization
+    ? `/organizations/${organization.slug}/prompts-activity/`
+    : '/prompts-activity/';
+
+  return [url, {query: {feature, organization_id: orgId, project_id: projectId}}];
+};
 
 /**
  * @param organizationId org numerical id, not the slug
  */
 export function usePromptsCheck(
-  {feature, organizationId, projectId}: PromptCheckParams,
+  {feature, organization, organizationId, projectId}: PromptCheckParams,
   options: Partial<UseApiQueryOptions<PromptResponse>> = {}
 ) {
   return useApiQuery<PromptResponse>(
-    makePromptsCheckQueryKey({feature, organizationId, projectId}),
+    makePromptsCheckQueryKey({feature, organization, organizationId, projectId}),
     {
       staleTime: 120000,
       ...options,
@@ -119,15 +137,23 @@ export function usePromptsCheck(
 export async function batchedPromptsCheck<T extends readonly string[]>(
   api: Client,
   features: T,
-  params: {organizationId: string; projectId?: string}
+  params: {
+    organization?: OrganizationSummary;
+    organizationId?: string;
+    projectId?: string;
+  }
 ): Promise<{[key in T[number]]: PromptData}> {
+  const orgId = params.organization ? params.organization.id : params.organizationId;
   const query = {
     feature: features,
-    organization_id: params.organizationId,
+    organization_id: orgId,
     ...(params.projectId === undefined ? {} : {project_id: params.projectId}),
   };
+  const url = params.organization
+    ? `/organizations/${params.organization.slug}/prompts-activity/`
+    : '/prompts-activity/';
 
-  const response: PromptResponse = await api.requestPromise('/prompts-activity/', {
+  const response: PromptResponse = await api.requestPromise(url, {
     query,
   });
   const responseFeatures = response?.features;

+ 2 - 2
static/app/components/events/interfaces/crashContent/exception/content.spec.tsx

@@ -27,7 +27,7 @@ describe('Exception Content', function () {
   beforeEach(function () {
     MockApiClient.clearMockResponses();
     MockApiClient.addMockResponse({
-      url: `/prompts-activity/`,
+      url: `/organizations/${organization.slug}/prompts-activity/`,
     });
     MockApiClient.addMockResponse({
       url: `/projects/${organization.slug}/${project.slug}/stacktrace-link/`,
@@ -232,7 +232,7 @@ describe('Exception Content', function () {
         snoozed_ts: undefined,
       };
       MockApiClient.addMockResponse({
-        url: '/prompts-activity/',
+        url: `/organizations/${organization.slug}/prompts-activity/`,
         body: promptResponse,
       });
       MockApiClient.addMockResponse({

+ 1 - 1
static/app/components/events/interfaces/crashContent/stackTrace/content.spec.tsx

@@ -56,7 +56,7 @@ describe('StackTrace', function () {
       snoozed_ts: undefined,
     };
     MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: `/organizations/${organization.slug}/prompts-activity/`,
       body: promptResponse,
     });
     MockApiClient.addMockResponse({

+ 1 - 1
static/app/components/events/interfaces/crashContent/stackTrace/nativeContent.spec.tsx

@@ -56,7 +56,7 @@ describe('Native StackTrace', function () {
       snoozed_ts: undefined,
     };
     MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: `/organizations/${organization.slug}/prompts-activity/`,
       body: promptResponse,
     });
     MockApiClient.addMockResponse({

+ 4 - 4
static/app/components/events/interfaces/frame/stacktraceLink.spec.tsx

@@ -42,7 +42,7 @@ describe('StacktraceLink', function () {
     MockApiClient.clearMockResponses();
     promptActivity = MockApiClient.addMockResponse({
       method: 'GET',
-      url: '/prompts-activity/',
+      url: `/organizations/${org.slug}/prompts-activity/`,
       body: {},
     });
     ProjectsStore.loadInitialData([project]);
@@ -77,7 +77,7 @@ describe('StacktraceLink', function () {
     );
     expect(promptActivity).toHaveBeenCalledTimes(1);
     expect(promptActivity).toHaveBeenCalledWith(
-      '/prompts-activity/',
+      `/organizations/${org.slug}/prompts-activity/`,
       expect.objectContaining({
         query: {
           feature: 'stacktrace_link',
@@ -95,7 +95,7 @@ describe('StacktraceLink', function () {
     });
     const dismissPrompt = MockApiClient.addMockResponse({
       method: 'PUT',
-      url: `/prompts-activity/`,
+      url: `/organizations/${org.slug}/prompts-activity/`,
       body: {},
     });
     const {container} = render(<StacktraceLink frame={frame} event={event} line="" />, {
@@ -114,7 +114,7 @@ describe('StacktraceLink', function () {
     });
 
     expect(dismissPrompt).toHaveBeenCalledWith(
-      `/prompts-activity/`,
+      `/organizations/${org.slug}/prompts-activity/`,
       expect.objectContaining({
         data: {
           feature: 'stacktrace_link',

+ 3 - 3
static/app/components/events/interfaces/frame/stacktraceLink.tsx

@@ -78,7 +78,7 @@ function StacktraceLinkSetup({
 
   const dismissPrompt = () => {
     promptsUpdate(api, {
-      organizationId: organization.id,
+      organization,
       projectId: project?.id,
       feature: 'stacktrace_link',
       status: 'dismissed',
@@ -89,8 +89,8 @@ function StacktraceLinkSetup({
     setApiQueryData<PromptResponse>(
       queryClient,
       makePromptsCheckQueryKey({
+        organization,
         feature: 'stacktrace_link',
-        organizationId: organization.id,
         projectId: project?.id,
       }),
       () => {
@@ -227,8 +227,8 @@ export function StacktraceLink({frame, event, line}: StacktraceLinkProps) {
   );
 
   const prompt = usePromptsCheck({
+    organization,
     feature: 'stacktrace_link',
-    organizationId: organization.id,
     projectId: project?.id,
   });
   const isPromptDismissed =

+ 1 - 1
static/app/components/events/interfaces/threads.spec.tsx

@@ -27,7 +27,7 @@ describe('Threads', function () {
       snoozed_ts: undefined,
     };
     MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: `/organizations/${organization.slug}/prompts-activity/`,
       body: promptResponse,
     });
     MockApiClient.addMockResponse({

+ 22 - 15
static/app/components/globalSdkUpdateAlert.spec.tsx

@@ -67,14 +67,15 @@ describe('GlobalSDKUpdateAlert', () => {
       dismissed_ts: undefined,
       snoozed_ts: undefined,
     };
+    const organization = OrganizationFixture();
 
     MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: `/organizations/${organization.slug}/prompts-activity/`,
       body: promptResponse,
     });
 
     const {rerender} = render(<InnerGlobalSdkUpdateAlert sdkUpdates={sdkUpdates} />, {
-      organization: OrganizationFixture(),
+      organization,
     });
 
     expect(
@@ -98,9 +99,10 @@ describe('GlobalSDKUpdateAlert', () => {
       dismissed_ts: undefined,
       snoozed_ts: undefined,
     };
+    const organization = OrganizationFixture();
 
     MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: `/organizations/${organization.slug}/prompts-activity/`,
       body: {data: promptResponse},
     });
 
@@ -123,14 +125,15 @@ describe('GlobalSDKUpdateAlert', () => {
         .unix(),
       snoozed_ts: undefined,
     };
+    const organization = OrganizationFixture();
 
     MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: `/organizations/${organization.slug}/prompts-activity/`,
       body: {data: promptResponse},
     });
 
     render(<InnerGlobalSdkUpdateAlert sdkUpdates={sdkUpdates} />, {
-      organization: OrganizationFixture(),
+      organization,
     });
 
     await waitFor(() =>
@@ -150,14 +153,15 @@ describe('GlobalSDKUpdateAlert', () => {
         .subtract(DEFAULT_SNOOZE_PROMPT_DAYS + 1, 'days')
         .unix(),
     };
+    const organization = OrganizationFixture();
 
     MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: `/organizations/${organization.slug}/prompts-activity/`,
       body: {data: promptResponse},
     });
 
     render(<InnerGlobalSdkUpdateAlert sdkUpdates={sdkUpdates} />, {
-      organization: OrganizationFixture(),
+      organization,
     });
 
     expect(
@@ -175,14 +179,15 @@ describe('GlobalSDKUpdateAlert', () => {
         .subtract(DEFAULT_SNOOZE_PROMPT_DAYS - 2, 'days')
         .unix(),
     };
+    const organization = OrganizationFixture();
 
     MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: `/organizations/${organization.slug}/prompts-activity/`,
       body: {data: promptResponse},
     });
 
     render(<InnerGlobalSdkUpdateAlert sdkUpdates={sdkUpdates} />, {
-      organization: OrganizationFixture(),
+      organization,
     });
 
     await waitFor(() =>
@@ -202,14 +207,15 @@ describe('GlobalSDKUpdateAlert', () => {
       dismissed_ts: undefined,
       snoozed_ts: undefined,
     };
+    const organization = OrganizationFixture();
 
     MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: `/organizations/${organization.slug}/prompts-activity/`,
       body: promptResponse,
     });
 
     render(<InnerGlobalSdkUpdateAlert sdkUpdates={sdkUpdates} />, {
-      organization: OrganizationFixture(),
+      organization,
     });
 
     expect(
@@ -224,25 +230,26 @@ describe('GlobalSDKUpdateAlert', () => {
       dismissed_ts: undefined,
       snoozed_ts: undefined,
     };
+    const organization = OrganizationFixture();
 
     MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: `/organizations/${organization.slug}/prompts-activity/`,
       body: {data: promptResponse},
     });
 
     const promptsActivityMock = MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: `/organizations/${organization.slug}/prompts-activity/`,
       method: 'PUT',
     });
 
     render(<InnerGlobalSdkUpdateAlert sdkUpdates={sdkUpdates} />, {
-      organization: OrganizationFixture(),
+      organization,
     });
 
     await userEvent.click(await screen.findByRole('button', {name: 'Remind me later'}));
 
     expect(promptsActivityMock).toHaveBeenCalledWith(
-      '/prompts-activity/',
+      `/organizations/${organization.slug}/prompts-activity/`,
       expect.objectContaining({
         data: expect.objectContaining({
           feature: 'sdk_updates',

+ 2 - 2
static/app/components/globalSdkUpdateAlert.tsx

@@ -33,7 +33,7 @@ function InnerGlobalSdkUpdateAlert(
 
   const handleSnoozePrompt = useCallback(() => {
     promptsUpdate(api, {
-      organizationId: organization.id,
+      organization,
       feature: 'sdk_updates',
       status: 'snoozed',
     });
@@ -53,7 +53,7 @@ function InnerGlobalSdkUpdateAlert(
     let isUnmounted = false;
 
     promptsCheck(api, {
-      organizationId: organization.id,
+      organization,
       feature: 'sdk_updates',
     }).then(prompt => {
       if (isUnmounted) {

+ 4 - 4
static/app/views/alerts/list/incidents/index.spec.tsx

@@ -106,11 +106,11 @@ describe('IncidentsList', () => {
       body: [],
     });
     const promptsMock = MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: '/organizations/org-slug/prompts-activity/',
       body: {data: {dismissed_ts: null}},
     });
     const promptsUpdateMock = MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: '/organizations/org-slug/prompts-activity/',
       method: 'PUT',
     });
 
@@ -133,7 +133,7 @@ describe('IncidentsList', () => {
       body: [],
     });
     const promptsMock = MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: '/organizations/org-slug/prompts-activity/',
       body: {data: {dismissed_ts: Math.floor(Date.now() / 1000)}},
     });
 
@@ -157,7 +157,7 @@ describe('IncidentsList', () => {
       body: [{id: 1}],
     });
     const promptsMock = MockApiClient.addMockResponse({
-      url: '/prompts-activity/',
+      url: '/organizations/org-slug/prompts-activity/',
       body: {data: {dismissed_ts: Math.floor(Date.now() / 1000)}},
     });
 

Some files were not shown because too many files changed in this diff