From bfd01d03168ffc54fcd80c5045c450340b929b4e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 29 Dec 2020 22:17:03 -0600 Subject: [PATCH] Admin: fetch ConfigDB config, start RegistrationModePicker --- app/soapbox/actions/admin.js | 17 +++++++ .../components/registration_mode_picker.js | 50 +++++++++++++++++++ app/soapbox/features/admin/index.js | 3 +- app/soapbox/features/ui/index.js | 3 +- app/soapbox/reducers/__tests__/admin-test.js | 9 +++- app/soapbox/reducers/admin.js | 5 ++ 6 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 app/soapbox/features/admin/components/registration_mode_picker.js diff --git a/app/soapbox/actions/admin.js b/app/soapbox/actions/admin.js index 4329aa670..241026624 100644 --- a/app/soapbox/actions/admin.js +++ b/app/soapbox/actions/admin.js @@ -1,5 +1,9 @@ import api from '../api'; +export const ADMIN_CONFIG_FETCH_REQUEST = 'ADMIN_CONFIG_FETCH_REQUEST'; +export const ADMIN_CONFIG_FETCH_SUCCESS = 'ADMIN_CONFIG_FETCH_SUCCESS'; +export const ADMIN_CONFIG_FETCH_FAIL = 'ADMIN_CONFIG_FETCH_FAIL'; + export const ADMIN_CONFIG_UPDATE_REQUEST = 'ADMIN_CONFIG_UPDATE_REQUEST'; export const ADMIN_CONFIG_UPDATE_SUCCESS = 'ADMIN_CONFIG_UPDATE_SUCCESS'; export const ADMIN_CONFIG_UPDATE_FAIL = 'ADMIN_CONFIG_UPDATE_FAIL'; @@ -20,6 +24,19 @@ export const ADMIN_USERS_APPROVE_REQUEST = 'ADMIN_USERS_APPROVE_REQUEST'; export const ADMIN_USERS_APPROVE_SUCCESS = 'ADMIN_USERS_APPROVE_SUCCESS'; export const ADMIN_USERS_APPROVE_FAIL = 'ADMIN_USERS_APPROVE_FAIL'; +export function fetchConfig() { + return (dispatch, getState) => { + dispatch({ type: ADMIN_CONFIG_FETCH_REQUEST }); + return api(getState) + .get('/api/pleroma/admin/config') + .then(({ data }) => { + dispatch({ type: ADMIN_CONFIG_FETCH_SUCCESS, configs: data.configs, needsReboot: data.need_reboot }); + }).catch(error => { + dispatch({ type: ADMIN_CONFIG_FETCH_FAIL, error }); + }); + }; +} + export function updateAdminConfig(params) { return (dispatch, getState) => { dispatch({ type: ADMIN_CONFIG_UPDATE_REQUEST }); diff --git a/app/soapbox/features/admin/components/registration_mode_picker.js b/app/soapbox/features/admin/components/registration_mode_picker.js new file mode 100644 index 000000000..1d0016bf7 --- /dev/null +++ b/app/soapbox/features/admin/components/registration_mode_picker.js @@ -0,0 +1,50 @@ +import React from 'react'; +import { FormattedMessage } from 'react-intl'; +import { connect } from 'react-redux'; +import ImmutablePureComponent from 'react-immutable-pure-component'; +import { + SimpleForm, + FieldsGroup, + RadioGroup, + RadioItem, +} from 'soapbox/features/forms'; + +const mapStateToProps = (state, props) => ({ + instance: state.get('instance'), + openReportCount: state.getIn(['admin', 'open_report_count']), +}); + +export default @connect(mapStateToProps) +class RegistrationModePicker extends ImmutablePureComponent { + + render() { + return ( + + + } + checked + onChange={this.onChange} + > + } + hint={} + value='open' + /> + } + hint={} + value='approval' + /> + } + hint={} + value='closed' + /> + + + + ); + }; + +} diff --git a/app/soapbox/features/admin/index.js b/app/soapbox/features/admin/index.js index eb91ff2a5..11966eedd 100644 --- a/app/soapbox/features/admin/index.js +++ b/app/soapbox/features/admin/index.js @@ -5,6 +5,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import Column from '../ui/components/column'; +import RegistrationModePicker from './components/registration_mode_picker'; import { parseVersion } from 'soapbox/utils/features'; const messages = defineMessages({ @@ -63,8 +64,8 @@ class Dashboard extends ImmutablePureComponent { - {/* TODO: Awaiting approval users count */} +

diff --git a/app/soapbox/features/ui/index.js b/app/soapbox/features/ui/index.js index 313f60607..370400dd1 100644 --- a/app/soapbox/features/ui/index.js +++ b/app/soapbox/features/ui/index.js @@ -16,7 +16,7 @@ import { debounce } from 'lodash'; import { uploadCompose, resetCompose } from '../../actions/compose'; import { expandHomeTimeline } from '../../actions/timelines'; import { expandNotifications } from '../../actions/notifications'; -import { fetchReports, fetchUsers } from '../../actions/admin'; +import { fetchReports, fetchUsers, fetchConfig } from '../../actions/admin'; import { fetchFilters } from '../../actions/filters'; import { fetchChats } from 'soapbox/actions/chats'; import { clearHeight } from '../../actions/height_cache'; @@ -465,6 +465,7 @@ class UI extends React.PureComponent { if (isStaff(account)) { this.props.dispatch(fetchReports({ state: 'open' })); this.props.dispatch(fetchUsers({ page: 1, filters: 'local,need_approval' })); + this.props.dispatch(fetchConfig()); } setTimeout(() => this.props.dispatch(fetchFilters()), 500); diff --git a/app/soapbox/reducers/__tests__/admin-test.js b/app/soapbox/reducers/__tests__/admin-test.js index 891b8cabe..9f983af0a 100644 --- a/app/soapbox/reducers/__tests__/admin-test.js +++ b/app/soapbox/reducers/__tests__/admin-test.js @@ -1,5 +1,10 @@ import reducer from '../admin'; -import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable'; +import { + Map as ImmutableMap, + List as ImmutableList, + OrderedSet as ImmutableOrderedSet, + fromJS, +} from 'immutable'; describe('admin reducer', () => { it('should return the initial state', () => { @@ -8,6 +13,8 @@ describe('admin reducer', () => { open_report_count: 0, users: ImmutableMap(), awaitingApproval: ImmutableOrderedSet(), + configs: ImmutableList(), + needsReboot: false, })); }); }); diff --git a/app/soapbox/reducers/admin.js b/app/soapbox/reducers/admin.js index c7c6be507..eaacf7323 100644 --- a/app/soapbox/reducers/admin.js +++ b/app/soapbox/reducers/admin.js @@ -1,4 +1,5 @@ import { + ADMIN_CONFIG_FETCH_SUCCESS, ADMIN_REPORTS_FETCH_SUCCESS, ADMIN_USERS_FETCH_SUCCESS, ADMIN_USERS_DELETE_REQUEST, @@ -18,6 +19,8 @@ const initialState = ImmutableMap({ users: ImmutableMap(), open_report_count: 0, awaitingApproval: ImmutableOrderedSet(), + configs: ImmutableList(), + needsReboot: false, }); function importUsers(state, users) { @@ -51,6 +54,8 @@ function approveUsers(state, users) { export default function admin(state = initialState, action) { switch(action.type) { + case ADMIN_CONFIG_FETCH_SUCCESS: + return state.set('configs', fromJS(action.configs)); case ADMIN_REPORTS_FETCH_SUCCESS: if (action.params && action.params.state === 'open') { return state