Support Mastodon permissions system(?)
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
6b92d5f3a5
commit
f6f056e0fe
|
@ -9,7 +9,8 @@ import { openModal } from 'soapbox/actions/modals';
|
||||||
import GroupCard from 'soapbox/components/group-card';
|
import GroupCard from 'soapbox/components/group-card';
|
||||||
import ScrollableList from 'soapbox/components/scrollable-list';
|
import ScrollableList from 'soapbox/components/scrollable-list';
|
||||||
import { Button, Column, Spinner, Stack, Text } from 'soapbox/components/ui';
|
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';
|
import PlaceholderGroupCard from '../placeholder/components/placeholder-group-card';
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ const getOrderedGroups = createSelector([
|
||||||
|
|
||||||
const Groups: React.FC = () => {
|
const Groups: React.FC = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
const account = useOwnAccount();
|
||||||
|
|
||||||
const { groups, isLoading } = useAppSelector((state) => getOrderedGroups(state));
|
const { groups, isLoading } = useAppSelector((state) => getOrderedGroups(state));
|
||||||
|
|
||||||
|
@ -72,15 +74,17 @@ const Groups: React.FC = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack className='gap-4'>
|
<Stack className='gap-4'>
|
||||||
<Button
|
{hasPermission(account, PERMISSION_CREATE_GROUPS) && (
|
||||||
className='sm:w-fit sm:self-end xl:hidden'
|
<Button
|
||||||
icon={require('@tabler/icons/circles.svg')}
|
className='sm:w-fit sm:self-end xl:hidden'
|
||||||
onClick={createGroup}
|
icon={require('@tabler/icons/circles.svg')}
|
||||||
theme='secondary'
|
onClick={createGroup}
|
||||||
block
|
theme='secondary'
|
||||||
>
|
block
|
||||||
<FormattedMessage id='new_group_panel.action' defaultMessage='Create group' />
|
>
|
||||||
</Button>
|
<FormattedMessage id='new_group_panel.action' defaultMessage='Create group' />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<ScrollableList
|
<ScrollableList
|
||||||
scrollKey='groups'
|
scrollKey='groups'
|
||||||
emptyMessage={emptyMessage}
|
emptyMessage={emptyMessage}
|
||||||
|
|
|
@ -3,15 +3,19 @@ import { FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
import { openModal } from 'soapbox/actions/modals';
|
import { openModal } from 'soapbox/actions/modals';
|
||||||
import { Button, Stack, Text } from 'soapbox/components/ui';
|
import { Button, Stack, Text } from 'soapbox/components/ui';
|
||||||
import { useAppDispatch } from 'soapbox/hooks';
|
import { useAppDispatch, useOwnAccount } from 'soapbox/hooks';
|
||||||
|
import { PERMISSION_CREATE_GROUPS, hasPermission } from 'soapbox/utils/permissions';
|
||||||
|
|
||||||
const NewGroupPanel = () => {
|
const NewGroupPanel = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
const account = useOwnAccount();
|
||||||
|
|
||||||
const createGroup = () => {
|
const createGroup = () => {
|
||||||
dispatch(openModal('MANAGE_GROUP'));
|
dispatch(openModal('MANAGE_GROUP'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!hasPermission(account, PERMISSION_CREATE_GROUPS)) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack space={2}>
|
<Stack space={2}>
|
||||||
<Stack>
|
<Stack>
|
||||||
|
|
|
@ -47,6 +47,7 @@ export const AccountRecord = ImmutableRecord({
|
||||||
mute_expires_at: null as string | null,
|
mute_expires_at: null as string | null,
|
||||||
note: '',
|
note: '',
|
||||||
pleroma: ImmutableMap<string, any>(),
|
pleroma: ImmutableMap<string, any>(),
|
||||||
|
role: ImmutableMap<string, any>(),
|
||||||
source: ImmutableMap<string, any>(),
|
source: ImmutableMap<string, any>(),
|
||||||
statuses_count: 0,
|
statuses_count: 0,
|
||||||
uri: '',
|
uri: '',
|
||||||
|
|
|
@ -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;
|
||||||
|
};
|
Loading…
Reference in New Issue