index.tsx 2.9 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 {Organization} from 'sentry/types';
  10. import useApi from 'sentry/utils/useApi';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  13. import {DataScrubbing} from '../components/dataScrubbing';
  14. export default function OrganizationSecurityAndPrivacyContent() {
  15. const api = useApi();
  16. const organization = useOrganization();
  17. const [authProvider, setAuthProvider] = useState<string | null>(null);
  18. useEffect(() => {
  19. async function fetchAuthProvider() {
  20. try {
  21. const response = await api.requestPromise(
  22. `/organizations/${organization.slug}/auth-provider/`
  23. );
  24. setAuthProvider(response);
  25. } catch {
  26. addErrorMessage(t('Unable to fetch authentication provider'));
  27. }
  28. }
  29. fetchAuthProvider();
  30. }, [organization.slug, api]);
  31. const initialData = organization;
  32. const endpoint = `/organizations/${organization.slug}/`;
  33. const access = new Set(organization.access);
  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={!access.has('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={!access.has('org:write')}
  69. onSubmitSuccess={data => handleUpdateOrganization({...organization, ...data})}
  70. />
  71. </Fragment>
  72. );
  73. }