index.tsx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 {AuthProvider, 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<AuthProvider | null>(null);
  18. useEffect(() => {
  19. async function fetchAuthProvider() {
  20. try {
  21. const response: AuthProvider = 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 features = new Set(organization.features);
  34. const relayPiiConfig = organization.relayPiiConfig;
  35. const title = t('Security & Privacy');
  36. function handleUpdateOrganization(data: Organization) {
  37. // This will update OrganizationStore (as well as OrganizationsStore
  38. // which is slightly incorrect because it has summaries vs a detailed org)
  39. updateOrganization(data);
  40. }
  41. return (
  42. <Fragment>
  43. <SentryDocumentTitle title={title} orgSlug={organization.slug} />
  44. <SettingsPageHeader title={title} />
  45. <Form
  46. data-test-id="organization-settings-security-and-privacy"
  47. apiMethod="PUT"
  48. apiEndpoint={endpoint}
  49. initialData={initialData}
  50. additionalFieldProps={{hasSsoEnabled: !!authProvider}}
  51. onSubmitSuccess={handleUpdateOrganization}
  52. onSubmitError={() => addErrorMessage(t('Unable to save change'))}
  53. saveOnBlur
  54. allowUndo
  55. >
  56. <JsonForm
  57. features={features}
  58. forms={organizationSecurityAndPrivacyGroups}
  59. disabled={!organization.access.includes('org:write')}
  60. />
  61. </Form>
  62. <DataScrubbing
  63. additionalContext={t('These rules can be configured for each project.')}
  64. endpoint={endpoint}
  65. relayPiiConfig={relayPiiConfig}
  66. organization={organization}
  67. disabled={!organization.access.includes('org:write')}
  68. onSubmitSuccess={data => handleUpdateOrganization({...organization, ...data})}
  69. />
  70. </Fragment>
  71. );
  72. }