kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Add isStaff utility
rodzic
d3bef7038d
commit
c6b9968855
|
@ -1,4 +1,4 @@
|
|||
import { getDomain, acctFull } from '../accounts';
|
||||
import { getDomain, acctFull, isStaff } from '../accounts';
|
||||
import { fromJS } from 'immutable';
|
||||
|
||||
describe('getDomain', () => {
|
||||
|
@ -32,3 +32,26 @@ describe('acctFull', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isStaff', () => {
|
||||
describe('with empty user', () => {
|
||||
const account = fromJS({});
|
||||
it('returns false', () => {
|
||||
expect(isStaff(account)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with Pleroma admin', () => {
|
||||
const admin = fromJS({ pleroma: { is_admin: true } });
|
||||
it('returns true', () => {
|
||||
expect(isStaff(admin)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with Pleroma moderator', () => {
|
||||
const mod = fromJS({ pleroma: { is_moderator: true } });
|
||||
it('returns true', () => {
|
||||
expect(isStaff(mod)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,3 +14,9 @@ export const acctFull = account => {
|
|||
}
|
||||
return [user, domain].join('@');
|
||||
};
|
||||
|
||||
export const isStaff = account => {
|
||||
return ['is_admin', 'is_moderator'].some(key => (
|
||||
account.getIn(['pleroma', key]) === true
|
||||
));
|
||||
};
|
||||
|
|
Ładowanie…
Reference in New Issue