Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Showing Workspace Section For User Having LiveChat Manager Permission #27188

Merged
merged 9 commits into from
Jan 3, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ const AdministrationList: FC<AdministrationListProps> = ({
const showAudit = hasAuditPermission || hasAuditLogPermission;
const showManageApps = hasManageApps || !!appBoxItems.length;
const showAdmin = hasAdminPermission || !!adminBoxItems.length;
const showWorkspace = hasAdminPermission;

const list = [
showAdmin && <AdministrationModelList showAdmin={showAdmin} accountBoxItems={adminBoxItems} closeList={closeList} />,
showAdmin && (
<AdministrationModelList showWorkspace={showWorkspace} showAdmin={showAdmin} accountBoxItems={adminBoxItems} closeList={closeList} />
),
showManageApps && <AppsModelList appBoxItems={appBoxItems} closeList={closeList} showManageApps={showManageApps} />,
showAudit && <AuditModelList showAudit={hasAuditPermission} showAuditLog={hasAuditLogPermission} closeList={closeList} />,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import ListItem from '../Sidebar/ListItem';

type AdministrationModelListProps = {
accountBoxItems: AccountBoxItem[];
showWorkspace: boolean;
showAdmin: boolean;
closeList: () => void;
};

const INFO_PERMISSIONS = ['view-statistics'];

const AdministrationModelList: FC<AdministrationModelListProps> = ({ accountBoxItems, showAdmin, closeList }) => {
const AdministrationModelList: FC<AdministrationModelListProps> = ({ accountBoxItems, showWorkspace, showAdmin, closeList }) => {
const t = useTranslation();
const { tabType, trialEndDate, isLoading } = useUpgradeTabParams();
const shouldShowEmoji = isFullyFeature(tabType);
Expand Down Expand Up @@ -51,20 +52,22 @@ const AdministrationModelList: FC<AdministrationModelListProps> = ({ accountBoxI
}}
/>
)}
<ListItem
icon='cog'
text={t('Workspace')}
action={(): void => {
if (hasInfoPermission) {
infoRoute.push();
closeList();
return;
}
{showWorkspace && (
<ListItem
icon='cog'
text={t('Workspace')}
action={(): void => {
if (hasInfoPermission) {
infoRoute.push();
closeList();
return;
}

adminRoute.push({ context: '/' });
closeList();
}}
/>
adminRoute.push({ context: '/' });
closeList();
}}
/>
)}
</>
)}
{accountBoxItems.length > 0 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,22 @@ const defaultConfig = {
describe('components/AdministrationList/AdministrationModelList', () => {
it('should render administration', async () => {
const AdministrationModelList = proxyquire.load(COMPONENT_PATH, defaultConfig).default;
render(<AdministrationModelList closeList={() => null} accountBoxItems={[]} showAdmin={true} />);
render(<AdministrationModelList closeList={() => null} accountBoxItems={[]} showAdmin={true} showWorkspace={true} />);

expect(screen.getByText('Administration')).to.exist;
expect(screen.getByText('Workspace')).to.exist;
expect(screen.getByText('Upgrade')).to.exist;
});

it('should not render workspace', async () => {
const AdministrationModelList = proxyquire.load(COMPONENT_PATH, defaultConfig).default;
render(<AdministrationModelList closeList={() => null} accountBoxItems={[]} showAdmin={true} showWorkspace={false} />);

expect(screen.getByText('Administration')).to.exist;
expect(screen.queryByText('Workspace')).to.not.exist;
expect(screen.getByText('Upgrade')).to.exist;
});

it('should not render workspace and upgrade when does not have permission', async () => {
const AdministrationModelList = proxyquire.load(COMPONENT_PATH, defaultConfig).default;
render(<AdministrationModelList closeList={() => null} accountBoxItems={[]} showAdmin={false} />);
Expand All @@ -60,7 +69,7 @@ describe('components/AdministrationList/AdministrationModelList', () => {
const AdministrationModelList = proxyquire.load(COMPONENT_PATH, defaultConfig).default;
render(
<RouterContextMock pushRoute={pushRoute}>
<AdministrationModelList closeList={closeList} accountBoxItems={[]} showAdmin={true} />
<AdministrationModelList closeList={closeList} accountBoxItems={[]} showAdmin={true} showWorkspace={true} />
</RouterContextMock>,
);
const button = screen.getByText('Workspace');
Expand All @@ -82,7 +91,7 @@ describe('components/AdministrationList/AdministrationModelList', () => {
}).default;
render(
<RouterContextMock pushRoute={pushRoute}>
<AdministrationModelList closeList={closeList} accountBoxItems={[]} showAdmin={true} />
<AdministrationModelList closeList={closeList} accountBoxItems={[]} showAdmin={true} showWorkspace={true} />
</RouterContextMock>,
);
const button = screen.getByText('Workspace');
Expand Down