pl-fe: admin dashboard support on non-pleroma backends

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk
2025-02-22 22:46:04 +01:00
parent 38304b0f52
commit 9abc3b9a67
6 changed files with 20 additions and 7 deletions

View File

@ -33,7 +33,7 @@ const useAccount = (accountId?: string, opts: UseAccountOpts = {}) => {
{ enabled: !!accountId, transform: normalizeAccount },
);
const meta = useAppSelector((state) => accountId && state.accounts_meta[accountId]);
const meta = useAppSelector((state) => accountId ? state.accounts_meta[accountId] : undefined);
const {
relationship,
@ -49,7 +49,14 @@ const useAccount = (accountId?: string, opts: UseAccountOpts = {}) => {
const isUnavailable = (me === entity?.id) ? false : (isBlocked && !features.blockersVisible);
const account = useMemo(
() => entity ? { ...entity, relationship, scrobble, __meta: { meta, ...entity.__meta } } : undefined,
() => entity ? {
...entity,
relationship,
scrobble,
__meta: { meta, ...entity.__meta },
// @ts-ignore
is_admin: meta?.role ? (meta.role.permissions & 0x1) === 0x1 : entity.is_admin,
} : undefined,
[entity, relationship, scrobble],
);

View File

@ -1000,7 +1000,7 @@ const MenuButton: React.FC<IMenuButton> = ({
icon: require('@tabler/icons/outline/gavel.svg'),
});
if (isAdmin) {
if (isAdmin && features.pleromaAdminStatuses) {
menu.push({
text: intl.formatMessage(messages.admin_status),
href: `/pleroma/admin/#/statuses/${status.id}/`,

View File

@ -319,7 +319,7 @@ const EventHeader: React.FC<IEventHeader> = ({ status }) => {
icon: require('@tabler/icons/outline/gavel.svg'),
});
if (isAdmin) {
if (isAdmin && features.pleromaAdminStatuses) {
menu.push({
text: intl.formatMessage(messages.adminStatus),
action: handleModerateStatus,

View File

@ -11,7 +11,9 @@ import type { Account, CredentialAccount } from 'pl-api';
interface AccountMeta {
pleroma: Account['__meta']['pleroma'];
source: Account['__meta']['source'];
pleromaSource: Account['__meta']['source'];
source?: CredentialAccount['source'];
role?: CredentialAccount['role'];
}
type State = Immutable<Record<string, AccountMeta | undefined>>;
@ -22,7 +24,9 @@ const importAccount = (state: State, account: CredentialAccount): State =>
draft[account.id] = {
pleroma: account.__meta.pleroma ?? existing?.pleroma,
source: account.__meta.source ?? existing?.source,
pleromaSource: account.__meta.source ?? existing?.pleromaSource,
source: account.source ?? existing?.source,
role: account.role ?? existing?.role,
};
}, { enableAutoFreeze: true });

View File

@ -44,6 +44,8 @@ const makeGetAccount = () => createSelector([
...account,
relationship,
__meta: { meta, ...account.__meta },
// @ts-ignore
is_admin: meta?.role ? (meta.role.permissions & 0x1) === 0x1 : account.is_admin,
};
});

View File

@ -16,7 +16,7 @@ const getInstanceScopes = (instance: Instance, admin: boolean = true) => {
scopes = 'read write follow push write:bites';
break;
case PLEROMA:
scopes = 'read write follow push admin';
scopes = 'read write follow push';
break;
default:
scopes = 'read write follow push';