index.tsx 4.1 KB

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