diff --git a/app/soapbox/features/groups/index.tsx b/app/soapbox/features/groups/index.tsx index 45d0c5bab1..393dcf66bf 100644 --- a/app/soapbox/features/groups/index.tsx +++ b/app/soapbox/features/groups/index.tsx @@ -9,7 +9,8 @@ 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 } from 'soapbox/hooks'; +import { useAppSelector, useOwnAccount } from 'soapbox/hooks'; +import { PERMISSION_CREATE_GROUPS, hasPermission } from 'soapbox/utils/permissions'; import PlaceholderGroupCard from '../placeholder/components/placeholder-group-card'; @@ -31,6 +32,7 @@ const getOrderedGroups = createSelector([ const Groups: React.FC = () => { const dispatch = useDispatch(); + const account = useOwnAccount(); const { groups, isLoading } = useAppSelector((state) => getOrderedGroups(state)); @@ -72,15 +74,17 @@ const Groups: React.FC = () => { return ( - + {hasPermission(account, PERMISSION_CREATE_GROUPS) && ( + + )} { const dispatch = useAppDispatch(); + const account = useOwnAccount(); const createGroup = () => { dispatch(openModal('MANAGE_GROUP')); }; + if (!hasPermission(account, PERMISSION_CREATE_GROUPS)) return null; + return ( diff --git a/app/soapbox/normalizers/account.ts b/app/soapbox/normalizers/account.ts index fb6a042551..14255d762e 100644 --- a/app/soapbox/normalizers/account.ts +++ b/app/soapbox/normalizers/account.ts @@ -47,6 +47,7 @@ export const AccountRecord = ImmutableRecord({ mute_expires_at: null as string | null, note: '', pleroma: ImmutableMap(), + role: ImmutableMap(), source: ImmutableMap(), statuses_count: 0, uri: '', diff --git a/app/soapbox/utils/permissions.ts b/app/soapbox/utils/permissions.ts new file mode 100644 index 0000000000..3ceed1b4ae --- /dev/null +++ b/app/soapbox/utils/permissions.ts @@ -0,0 +1,17 @@ +import type { Account } from 'soapbox/types/entities'; + +export const PERMISSION_CREATE_GROUPS = 0x0000000000100000; +export const PERMISSION_INVITE_USERS = 0x0000000000010000; +export const PERMISSION_MANAGE_USERS = 0x0000000000000400; +export const PERMISSION_MANAGE_REPORTS = 0x0000000000000010; + +type Permission = typeof PERMISSION_CREATE_GROUPS | typeof PERMISSION_INVITE_USERS | typeof PERMISSION_MANAGE_USERS | typeof PERMISSION_MANAGE_REPORTS + +export const hasPermission = (account: Account | null, permission: Permission) => { + if (!account) return false; + + const permissions = account.getIn(['role', 'permissions']) as number; + + if (!permission) return true; + return (permissions & permission) === permission; +};