From cafa014018aecf4b71363464b70331dfa4e7bc14 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 21 Apr 2020 14:00:31 -0500 Subject: [PATCH] Let isStaff accept an undefined value --- app/gabsocial/utils/__tests__/accounts-test.js | 7 +++++++ app/gabsocial/utils/accounts.js | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/gabsocial/utils/__tests__/accounts-test.js b/app/gabsocial/utils/__tests__/accounts-test.js index ad4614fd8..2708bd2cd 100644 --- a/app/gabsocial/utils/__tests__/accounts-test.js +++ b/app/gabsocial/utils/__tests__/accounts-test.js @@ -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); + }); + }); }); diff --git a/app/gabsocial/utils/accounts.js b/app/gabsocial/utils/accounts.js index 1aa0c922a..0c5a1f5e7 100644 --- a/app/gabsocial/utils/accounts.js +++ b/app/gabsocial/utils/accounts.js @@ -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 ));