isAdmin and isModerator utils

stable/1.0.x
Alex Gleason 2020-04-27 15:05:07 -05:00
rodzic edf22b921c
commit 9f4891fef0
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 64 dodań i 6 usunięć

Wyświetl plik

@ -1,4 +1,10 @@
import { getDomain, acctFull, isStaff } from '../accounts';
import {
getDomain,
acctFull,
isStaff,
isAdmin,
isModerator,
} from '../accounts';
import { fromJS } from 'immutable';
describe('getDomain', () => {
@ -62,3 +68,49 @@ describe('isStaff', () => {
});
});
});
describe('isAdmin', () => {
describe('with empty user', () => {
const account = fromJS({});
it('returns false', () => {
expect(isAdmin(account)).toBe(false);
});
});
describe('with Pleroma admin', () => {
const admin = fromJS({ pleroma: { is_admin: true } });
it('returns true', () => {
expect(isAdmin(admin)).toBe(true);
});
});
describe('with Pleroma moderator', () => {
const mod = fromJS({ pleroma: { is_moderator: true } });
it('returns false', () => {
expect(isAdmin(mod)).toBe(false);
});
});
});
describe('isModerator', () => {
describe('with empty user', () => {
const account = fromJS({});
it('returns false', () => {
expect(isModerator(account)).toBe(false);
});
});
describe('with Pleroma admin', () => {
const admin = fromJS({ pleroma: { is_admin: true } });
it('returns false', () => {
expect(isModerator(admin)).toBe(false);
});
});
describe('with Pleroma moderator', () => {
const mod = fromJS({ pleroma: { is_moderator: true } });
it('returns true', () => {
expect(isModerator(mod)).toBe(true);
});
});
});

Wyświetl plik

@ -17,8 +17,14 @@ export const acctFull = account => {
return [user, domain].join('@');
};
export const isStaff = (account = ImmutableMap()) => {
return ['is_admin', 'is_moderator'].some(key => (
account.getIn(['pleroma', key]) === true
));
};
export const isStaff = (account = ImmutableMap()) => (
[isAdmin, isModerator].some(f => f(account) === true)
);
export const isAdmin = account => (
account.getIn(['pleroma', 'is_admin']) === true
);
export const isModerator = account => (
account.getIn(['pleroma', 'is_moderator']) === true
);