2022-12-19 05:10:13 -08:00
|
|
|
import type { RootState } from 'soapbox/store';
|
2022-12-18 09:18:26 -08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-12-19 05:10:13 -08:00
|
|
|
export const hasPermission = (state: RootState, permission: Permission) => {
|
|
|
|
const account = state.accounts_meta.get(state.me as string)!;
|
|
|
|
|
2023-03-02 08:28:31 -08:00
|
|
|
if (!account?.role) return true;
|
2022-12-18 09:18:26 -08:00
|
|
|
|
|
|
|
const permissions = account.getIn(['role', 'permissions']) as number;
|
|
|
|
|
|
|
|
if (!permission) return true;
|
|
|
|
return (permissions & permission) === permission;
|
|
|
|
};
|