diff --git a/app/gabsocial/utils/__tests__/accounts-test.js b/app/gabsocial/utils/__tests__/accounts-test.js index 2708bd2cd..d7477c133 100644 --- a/app/gabsocial/utils/__tests__/accounts-test.js +++ b/app/gabsocial/utils/__tests__/accounts-test.js @@ -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); + }); + }); +}); diff --git a/app/gabsocial/utils/accounts.js b/app/gabsocial/utils/accounts.js index 0c5a1f5e7..adc029981 100644 --- a/app/gabsocial/utils/accounts.js +++ b/app/gabsocial/utils/accounts.js @@ -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 +);