From 0879222aa23816bad8428da75f57870f36cf60c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Mon, 19 Dec 2022 14:10:13 +0100 Subject: [PATCH] Improve permissions check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/features/groups/index.tsx | 6 +++--- .../features/ui/components/panels/new-group-panel.tsx | 7 ++++--- app/soapbox/normalizers/account.ts | 1 - app/soapbox/reducers/accounts-meta.ts | 4 +++- app/soapbox/utils/permissions.ts | 8 +++++--- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/soapbox/features/groups/index.tsx b/app/soapbox/features/groups/index.tsx index 393dcf66b..5fb621b7f 100644 --- a/app/soapbox/features/groups/index.tsx +++ b/app/soapbox/features/groups/index.tsx @@ -9,7 +9,7 @@ import { openModal } from 'soapbox/actions/modals'; import GroupCard from 'soapbox/components/group-card'; import ScrollableList from 'soapbox/components/scrollable-list'; import { Button, Column, Spinner, Stack, Text } from 'soapbox/components/ui'; -import { useAppSelector, useOwnAccount } from 'soapbox/hooks'; +import { useAppSelector } from 'soapbox/hooks'; import { PERMISSION_CREATE_GROUPS, hasPermission } from 'soapbox/utils/permissions'; import PlaceholderGroupCard from '../placeholder/components/placeholder-group-card'; @@ -32,9 +32,9 @@ const getOrderedGroups = createSelector([ const Groups: React.FC = () => { const dispatch = useDispatch(); - const account = useOwnAccount(); const { groups, isLoading } = useAppSelector((state) => getOrderedGroups(state)); + const canCreateGroup = useAppSelector((state) => hasPermission(state, PERMISSION_CREATE_GROUPS)); useEffect(() => { dispatch(fetchGroups()); @@ -74,7 +74,7 @@ const Groups: React.FC = () => { return ( - {hasPermission(account, PERMISSION_CREATE_GROUPS) && ( + {canCreateGroup && (