adminSettings.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import {Form} from 'sentry/components/forms';
  2. import {Panel, PanelHeader} from 'sentry/components/panels';
  3. import {t} from 'sentry/locale';
  4. import AsyncView from 'sentry/views/asyncView';
  5. import {getOption, getOptionField} from './options';
  6. const optionsAvailable = [
  7. 'system.url-prefix',
  8. 'system.admin-email',
  9. 'system.support-email',
  10. 'system.security-email',
  11. 'system.rate-limit',
  12. 'auth.allow-registration',
  13. 'auth.ip-rate-limit',
  14. 'auth.user-rate-limit',
  15. 'api.rate-limit.org-create',
  16. 'beacon.anonymous',
  17. ];
  18. type Field = ReturnType<typeof getOption>;
  19. type FieldDef = {
  20. field: Field;
  21. value: string | undefined;
  22. };
  23. type State = AsyncView['state'] & {
  24. data: Record<string, FieldDef>;
  25. };
  26. export default class AdminSettings extends AsyncView<{}, State> {
  27. get endpoint() {
  28. return '/internal/options/';
  29. }
  30. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  31. return [['data', this.endpoint]];
  32. }
  33. renderBody() {
  34. const {data} = this.state;
  35. const initialData = {};
  36. const fields = {};
  37. for (const key of optionsAvailable) {
  38. // TODO(dcramer): we should not be mutating options
  39. const option = data[key] ?? {field: {}, value: undefined};
  40. if (option.value === undefined || option.value === '') {
  41. const defn = getOption(key);
  42. initialData[key] = defn.defaultValue ? defn.defaultValue() : '';
  43. } else {
  44. initialData[key] = option.value;
  45. }
  46. fields[key] = getOptionField(key, option.field);
  47. }
  48. return (
  49. <div>
  50. <h3>{t('Settings')}</h3>
  51. <Form
  52. apiMethod="PUT"
  53. apiEndpoint={this.endpoint}
  54. initialData={initialData}
  55. saveOnBlur
  56. >
  57. <Panel>
  58. <PanelHeader>General</PanelHeader>
  59. {fields['system.url-prefix']}
  60. {fields['system.admin-email']}
  61. {fields['system.support-email']}
  62. {fields['system.security-email']}
  63. {fields['system.rate-limit']}
  64. </Panel>
  65. <Panel>
  66. <PanelHeader>Security & Abuse</PanelHeader>
  67. {fields['auth.allow-registration']}
  68. {fields['auth.ip-rate-limit']}
  69. {fields['auth.user-rate-limit']}
  70. {fields['api.rate-limit.org-create']}
  71. </Panel>
  72. <Panel>
  73. <PanelHeader>Beacon</PanelHeader>
  74. {fields['beacon.anonymous']}
  75. </Panel>
  76. </Form>
  77. </div>
  78. );
  79. }
  80. }