Let isStaff accept an undefined value

This commit is contained in:
Alex Gleason 2020-04-21 14:00:31 -05:00
parent 6ad116c0f9
commit cafa014018
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 10 additions and 1 deletions

View file

@ -54,4 +54,11 @@ describe('isStaff', () => {
expect(isStaff(mod)).toBe(true);
});
});
describe('with undefined', () => {
const account = undefined;
it('returns false', () => {
expect(isStaff(account)).toBe(false);
});
});
});

View file

@ -1,3 +1,5 @@
import { Map as ImmutableMap } from 'immutable';
export const getDomain = account => {
let re = /https?:\/\/(.*?)\//i;
return re.exec(account.get('url'))[1];
@ -15,7 +17,7 @@ export const acctFull = account => {
return [user, domain].join('@');
};
export const isStaff = account => {
export const isStaff = (account = ImmutableMap()) => {
return ['is_admin', 'is_moderator'].some(key => (
account.getIn(['pleroma', key]) === true
));