isAdmin and isModerator utils
This commit is contained in:
parent
edf22b921c
commit
9f4891fef0
2 changed files with 64 additions and 6 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue