diff --git a/app/gabsocial/utils/__tests__/accounts-test.js b/app/gabsocial/utils/__tests__/accounts-test.js index 2f7bbb3dd..ad4614fd8 100644 --- a/app/gabsocial/utils/__tests__/accounts-test.js +++ b/app/gabsocial/utils/__tests__/accounts-test.js @@ -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); + }); + }); +}); diff --git a/app/gabsocial/utils/accounts.js b/app/gabsocial/utils/accounts.js index 42ad7a98c..1aa0c922a 100644 --- a/app/gabsocial/utils/accounts.js +++ b/app/gabsocial/utils/accounts.js @@ -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 + )); +};