From 96af79ad9090fc612978c93a86dd5b464518f0f8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 12 Jul 2021 23:32:02 -0500 Subject: [PATCH] Moderators: conditional display of features --- app/soapbox/components/sidebar_menu.js | 18 +++++---------- app/soapbox/features/admin/index.js | 23 +++++++++++++------ .../features/ui/components/link_footer.js | 8 +++---- app/soapbox/features/ui/index.js | 5 +++- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/app/soapbox/components/sidebar_menu.js b/app/soapbox/components/sidebar_menu.js index b13410342..5cda6e1b6 100644 --- a/app/soapbox/components/sidebar_menu.js +++ b/app/soapbox/components/sidebar_menu.js @@ -12,7 +12,7 @@ import IconButton from './icon_button'; import Icon from './icon'; import DisplayName from './display_name'; import { closeSidebar } from '../actions/sidebar'; -import { isStaff } from '../utils/accounts'; +import { isStaff, isAdmin } from '../utils/accounts'; import { makeGetAccount, makeGetOtherAccounts } from '../selectors'; import { logOut, switchAccount } from 'soapbox/actions/auth'; import ThemeToggle from '../features/ui/components/theme_toggle_container'; @@ -58,7 +58,6 @@ const makeMapStateToProps = () => { sidebarOpen: state.get('sidebar').sidebarOpen, donateUrl: state.getIn(['patron', 'instance', 'url']), hasCrypto: typeof soapbox.getIn(['cryptoAddresses', 0, 'ticker']) === 'string', - isStaff: isStaff(state.getIn(['accounts', me])), otherAccounts: getOtherAccounts(state), }; }; @@ -92,13 +91,8 @@ class SidebarMenu extends ImmutablePureComponent { otherAccounts: ImmutablePropTypes.list, sidebarOpen: PropTypes.bool, onClose: PropTypes.func.isRequired, - isStaff: PropTypes.bool.isRequired, }; - static defaultProps = { - isStaff: false, - } - state = { switcher: false, } @@ -153,7 +147,7 @@ class SidebarMenu extends ImmutablePureComponent { } render() { - const { sidebarOpen, intl, account, onClickLogOut, donateUrl, isStaff, otherAccounts, hasCrypto } = this.props; + const { sidebarOpen, intl, account, onClickLogOut, donateUrl, otherAccounts, hasCrypto } = this.props; const { switcher } = this.state; if (!account) return null; const acct = account.get('acct'); @@ -245,14 +239,14 @@ class SidebarMenu extends ImmutablePureComponent { {intl.formatMessage(messages.filters)} - { isStaff && + {isStaff(account) && {intl.formatMessage(messages.admin_settings)} - } - { isStaff && + } + {isAdmin(account) && {intl.formatMessage(messages.soapbox_config)} - } + } {intl.formatMessage(messages.preferences)} diff --git a/app/soapbox/features/admin/index.js b/app/soapbox/features/admin/index.js index 90ce7ac1b..0ed82bc66 100644 --- a/app/soapbox/features/admin/index.js +++ b/app/soapbox/features/admin/index.js @@ -10,6 +10,7 @@ import { parseVersion } from 'soapbox/utils/features'; import sourceCode from 'soapbox/utils/code'; import { getSubscribersCsv, getUnsubscribersCsv, getCombinedCsv } from 'soapbox/actions/email_list'; import { getFeatures } from 'soapbox/utils/features'; +import { isAdmin } from 'soapbox/utils/accounts'; // https://stackoverflow.com/a/53230807 const download = (response, filename) => { @@ -26,10 +27,15 @@ const messages = defineMessages({ heading: { id: 'column.admin.dashboard', defaultMessage: 'Dashboard' }, }); -const mapStateToProps = (state, props) => ({ - instance: state.get('instance'), - supportsEmailList: getFeatures(state.get('instance')).emailList, -}); +const mapStateToProps = (state, props) => { + const me = state.get('me'); + + return { + instance: state.get('instance'), + supportsEmailList: getFeatures(state.get('instance')).emailList, + account: state.getIn(['accounts', me]), + }; +}; export default @connect(mapStateToProps) @injectIntl @@ -39,6 +45,7 @@ class Dashboard extends ImmutablePureComponent { intl: PropTypes.object.isRequired, instance: ImmutablePropTypes.map.isRequired, supportsEmailList: PropTypes.bool, + account: ImmutablePropTypes.map, }; handleSubscribersClick = e => { @@ -63,12 +70,14 @@ class Dashboard extends ImmutablePureComponent { } render() { - const { intl, instance, supportsEmailList } = this.props; + const { intl, instance, supportsEmailList, account } = this.props; const v = parseVersion(instance.get('version')); const userCount = instance.getIn(['stats', 'user_count']); const mau = instance.getIn(['pleroma', 'stats', 'mau']); const retention = (userCount && mau) ? Math.round(mau / userCount * 100) : null; + if (!account) return null; + return (
@@ -123,7 +132,7 @@ class Dashboard extends ImmutablePureComponent {
- + {isAdmin(account) && }

@@ -132,7 +141,7 @@ class Dashboard extends ImmutablePureComponent {
  • {v.software} {v.version}
  • - {supportsEmailList &&
    + {supportsEmailList && isAdmin(account) &&

    • subscribers.csv
    • diff --git a/app/soapbox/features/ui/components/link_footer.js b/app/soapbox/features/ui/components/link_footer.js index 6764be2e8..4b3a35fed 100644 --- a/app/soapbox/features/ui/components/link_footer.js +++ b/app/soapbox/features/ui/components/link_footer.js @@ -6,7 +6,7 @@ import { Link } from 'react-router-dom'; import { connect } from 'react-redux'; import { openModal } from '../../../actions/modal'; import { logOut } from 'soapbox/actions/auth'; -import { isStaff } from 'soapbox/utils/accounts'; +import { isStaff, isAdmin } from 'soapbox/utils/accounts'; import sourceCode from 'soapbox/utils/code'; const mapStateToProps = state => { @@ -35,10 +35,8 @@ const LinkFooter = ({ onOpenHotkeys, account, onClickLogOut }) => (
    • - {isStaff(account) && <> -
    • -
    • - } + {isStaff(account) &&
    • } + {isAdmin(account) &&
    • }
    • } diff --git a/app/soapbox/features/ui/index.js b/app/soapbox/features/ui/index.js index 05581ac11..a140cd0a7 100644 --- a/app/soapbox/features/ui/index.js +++ b/app/soapbox/features/ui/index.js @@ -38,7 +38,7 @@ import SidebarMenu from '../../components/sidebar_menu'; import { connectUserStream } from '../../actions/streaming'; import { Redirect } from 'react-router-dom'; import Icon from 'soapbox/components/icon'; -import { isStaff } from 'soapbox/utils/accounts'; +import { isStaff, isAdmin } from 'soapbox/utils/accounts'; import ProfileHoverCard from 'soapbox/components/profile_hover_card'; import { getAccessToken } from 'soapbox/utils/auth'; @@ -429,6 +429,9 @@ class UI extends React.PureComponent { if (isStaff(account)) { this.props.dispatch(fetchReports({ state: 'open' })); this.props.dispatch(fetchUsers({ page: 1, filters: 'local,need_approval' })); + } + + if (isAdmin(account)) { this.props.dispatch(fetchConfig()); }