index.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import {t} from 'sentry/locale';
  2. import type {AuthProvider, Organization} from 'sentry/types';
  3. import routeTitleGen from 'sentry/utils/routeTitle';
  4. import withOrganization from 'sentry/utils/withOrganization';
  5. import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
  6. import OrganizationAuthList from './organizationAuthList';
  7. type Props = DeprecatedAsyncView['props'] & {
  8. organization: Organization;
  9. };
  10. type State = DeprecatedAsyncView['state'] & {
  11. provider: AuthProvider | null;
  12. providerList: AuthProvider[] | null;
  13. };
  14. class OrganizationAuth extends DeprecatedAsyncView<Props, State> {
  15. componentDidUpdate() {
  16. const {organization} = this.props;
  17. const access = organization.access;
  18. if (this.state.provider && access.includes('org:write')) {
  19. // If SSO provider is configured, keep showing loading while we redirect
  20. // to django configuration view
  21. // XXX: This does not need to be normalized for customer-domains because we're going
  22. // to a django rendered view.
  23. const path = `/organizations/${organization.slug}/auth/configure/`;
  24. // Use replace so we don't go back to the /settings/auth and hit this path again.
  25. window.location.replace(path);
  26. }
  27. }
  28. getEndpoints(): ReturnType<DeprecatedAsyncView['getEndpoints']> {
  29. const {organization} = this.props;
  30. return [
  31. ['providerList', `/organizations/${organization.slug}/auth-providers/`],
  32. ['provider', `/organizations/${organization.slug}/auth-provider/`],
  33. ];
  34. }
  35. getTitle() {
  36. return routeTitleGen(t('Auth Settings'), this.props.organization.slug, false);
  37. }
  38. /**
  39. * TODO(epurkhiser): This does not work right now as we still fallback to the
  40. * old SSO auth configuration page
  41. */
  42. handleConfigure = (provider: AuthProvider) => {
  43. const {organization} = this.props;
  44. this.setState({busy: true});
  45. this.api.request(`/organizations/${organization.slug}/auth-provider/`, {
  46. method: 'POST',
  47. data: {provider, init: true},
  48. success: data => {
  49. // Redirect to auth provider URL
  50. if (data?.auth_url) {
  51. window.location.href = data.auth_url;
  52. }
  53. },
  54. error: () => {
  55. this.setState({busy: false});
  56. },
  57. });
  58. };
  59. /**
  60. * TODO(epurkhiser): This does not work right now as we still fallback to the
  61. * old SSO auth configuration page
  62. */
  63. handleDisableProvider = (provider: AuthProvider) => {
  64. const {organization} = this.props;
  65. this.setState({busy: true});
  66. this.api.request(`/organizations/${organization.slug}/auth-provider/`, {
  67. method: 'DELETE',
  68. data: {provider},
  69. success: () => {
  70. this.setState({provider: null, busy: false});
  71. },
  72. error: () => {
  73. this.setState({busy: false});
  74. },
  75. });
  76. };
  77. renderBody() {
  78. const {providerList, provider} = this.state;
  79. if (providerList === null) {
  80. return null;
  81. }
  82. if (this.props.organization.access.includes('org:write') && provider) {
  83. // If SSO provider is configured, keep showing loading while we redirect
  84. // to django configuration view
  85. return this.renderLoading();
  86. }
  87. const activeProvider = providerList?.find(p => p.key === provider?.key);
  88. return (
  89. <OrganizationAuthList activeProvider={activeProvider} providerList={providerList} />
  90. );
  91. }
  92. }
  93. export default withOrganization(OrganizationAuth);