Skip to content

Commit

Permalink
Check custom-roles license module
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva137 committed Dec 4, 2023
1 parent b90f871 commit 64365fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import { useRouteParameter, useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React from 'react';

import { useHasLicenseModule } from '../../../../ee/client/hooks/useHasLicenseModule';
import PageSkeleton from '../../../components/PageSkeleton';
import { useIsEnterprise } from '../../../hooks/useIsEnterprise';
import EditRolePage from './EditRolePage';
import { useRole } from './hooks/useRole';

const EditRolePageWithData = ({ roleId }: { roleId?: IRole['_id'] }): ReactElement => {
const t = useTranslation();
const role = useRole(roleId);
const context = useRouteParameter('context');
const { data, isLoading } = useIsEnterprise();
const hasCustomRolesModule = useHasLicenseModule('custom-roles');

if (!role && context === 'edit') {
return <Callout type='danger'>{t('error-invalid-role')}</Callout>;
}

if (isLoading || !data) {
if (hasCustomRolesModule === 'loading') {
return <PageSkeleton />;
}

return <EditRolePage key={roleId} role={role} isEnterprise={data.isEnterprise} />;
return <EditRolePage key={roleId} role={role} isEnterprise={hasCustomRolesModule} />;
};

export default EditRolePageWithData;
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useRouteParameter, useRoute, useTranslation, useSetModal } from '@rocke
import type { ReactElement } from 'react';
import React, { useEffect } from 'react';

import { useHasLicenseModule } from '../../../../ee/client/hooks/useHasLicenseModule';
import { Contextualbar, ContextualbarHeader, ContextualbarTitle, ContextualbarClose } from '../../../components/Contextualbar';
import { useIsEnterprise } from '../../../hooks/useIsEnterprise';
import CustomRoleUpsellModal from './CustomRoleUpsellModal';
import EditRolePageWithData from './EditRolePageWithData';

Expand All @@ -14,21 +14,20 @@ const PermissionsContextBar = (): ReactElement | null => {
const context = useRouteParameter('context');
const router = useRoute('admin-permissions');
const setModal = useSetModal();
const { data } = useIsEnterprise();
const isEnterprise = !!data?.isEnterprise;
const hasCustomRolesModule = useHasLicenseModule('custom-roles') === true;

const handleCloseContextualbar = useMutableCallback(() => {
router.push({});
});

useEffect(() => {
if (context !== 'new' || isEnterprise) {
if (context !== 'new' || hasCustomRolesModule) {
return;
}

setModal(<CustomRoleUpsellModal onClose={() => setModal(null)} />);
handleCloseContextualbar();
}, [context, isEnterprise, handleCloseContextualbar, setModal]);
}, [context, hasCustomRolesModule, handleCloseContextualbar, setModal]);

return (
(context && (
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/api/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ API.v1.addRoute(
{ authRequired: true },
{
async post() {
if (!License.hasValidLicense()) {
if (!License.hasModule('custom-roles')) {
throw new Meteor.Error('error-action-not-allowed', 'This is an enterprise feature');
}

Expand Down

0 comments on commit 64365fb

Please sign in to comment.