index.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {Fragment, useEffect, useState} from 'react';
  2. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  3. import {updateOrganization} from 'sentry/actionCreators/organizations';
  4. import Form from 'sentry/components/forms/form';
  5. import JsonForm from 'sentry/components/forms/jsonForm';
  6. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  7. import organizationSecurityAndPrivacyGroups from 'sentry/data/forms/organizationSecurityAndPrivacyGroups';
  8. import {t} from 'sentry/locale';
  9. import type {AuthProvider} from 'sentry/types/auth';
  10. import type {Organization} from 'sentry/types/organization';
  11. import useApi from 'sentry/utils/useApi';
  12. import useOrganization from 'sentry/utils/useOrganization';
  13. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  14. import {DataScrubbing} from '../components/dataScrubbing';
  15. export default function OrganizationSecurityAndPrivacyContent() {
  16. const api = useApi();
  17. const organization = useOrganization();
  18. const [authProvider, setAuthProvider] = useState<AuthProvider | null>(null);
  19. useEffect(() => {
  20. async function fetchAuthProvider() {
  21. try {
  22. const response: AuthProvider = await api.requestPromise(
  23. `/organizations/${organization.slug}/auth-provider/`
  24. );
  25. setAuthProvider(response);
  26. } catch {
  27. addErrorMessage(t('Unable to fetch authentication provider'));
  28. }
  29. }
  30. fetchAuthProvider();
  31. }, [organization.slug, api]);
  32. const initialData = organization;
  33. const endpoint = `/organizations/${organization.slug}/`;
  34. const features = new Set(organization.features);
  35. const relayPiiConfig = organization.relayPiiConfig;
  36. const title = t('Security & Privacy');
  37. function handleUpdateOrganization(data: Organization) {
  38. // This will update OrganizationStore (as well as OrganizationsStore
  39. // which is slightly incorrect because it has summaries vs a detailed org)
  40. updateOrganization(data);
  41. }
  42. return (
  43. <Fragment>
  44. <SentryDocumentTitle title={title} orgSlug={organization.slug} />
  45. <SettingsPageHeader title={title} />
  46. <Form
  47. data-test-id="organization-settings-security-and-privacy"
  48. apiMethod="PUT"
  49. apiEndpoint={endpoint}
  50. initialData={initialData}
  51. additionalFieldProps={{hasSsoEnabled: !!authProvider}}
  52. onSubmitSuccess={handleUpdateOrganization}
  53. onSubmitError={() => addErrorMessage(t('Unable to save change'))}
  54. saveOnBlur
  55. allowUndo
  56. >
  57. <JsonForm
  58. features={features}
  59. forms={organizationSecurityAndPrivacyGroups}
  60. disabled={!organization.access.includes('org:write')}
  61. />
  62. </Form>
  63. <DataScrubbing
  64. additionalContext={t('These rules can be configured for each project.')}
  65. endpoint={endpoint}
  66. relayPiiConfig={relayPiiConfig}
  67. organization={organization}
  68. disabled={!organization.access.includes('org:write')}
  69. onSubmitSuccess={data => handleUpdateOrganization({...organization, ...data})}
  70. />
  71. </Fragment>
  72. );
  73. }