sforkowany z mirror/soapbox
isAdmin and isModerator utils
rodzic
edf22b921c
commit
9f4891fef0
|
@ -1,4 +1,10 @@
|
||||||
import { getDomain, acctFull, isStaff } from '../accounts';
|
import {
|
||||||
|
getDomain,
|
||||||
|
acctFull,
|
||||||
|
isStaff,
|
||||||
|
isAdmin,
|
||||||
|
isModerator,
|
||||||
|
} from '../accounts';
|
||||||
import { fromJS } from 'immutable';
|
import { fromJS } from 'immutable';
|
||||||
|
|
||||||
describe('getDomain', () => {
|
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('@');
|
return [user, domain].join('@');
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isStaff = (account = ImmutableMap()) => {
|
export const isStaff = (account = ImmutableMap()) => (
|
||||||
return ['is_admin', 'is_moderator'].some(key => (
|
[isAdmin, isModerator].some(f => f(account) === true)
|
||||||
account.getIn(['pleroma', key]) === true
|
);
|
||||||
));
|
|
||||||
};
|
export const isAdmin = account => (
|
||||||
|
account.getIn(['pleroma', 'is_admin']) === true
|
||||||
|
);
|
||||||
|
|
||||||
|
export const isModerator = account => (
|
||||||
|
account.getIn(['pleroma', 'is_moderator']) === true
|
||||||
|
);
|
||||||
|
|
Ładowanie…
Reference in New Issue