Skip to content
Snippets Groups Projects
Unverified Commit 6fa30ddc authored by Rafael Tapia's avatar Rafael Tapia Committed by GitHub
Browse files

fix: check if 2FA is enabled to allow TOTP reset (#29723)

parent 7a4fdf41
No related branches found
No related tags found
No related merge requests found
---
"@rocket.chat/meteor": patch
---
Hide Reset TOTP option if 2FA is disabled
...@@ -1034,6 +1034,10 @@ API.v1.addRoute( ...@@ -1034,6 +1034,10 @@ API.v1.addRoute(
throw new Meteor.Error('error-not-allowed', 'Not allowed'); throw new Meteor.Error('error-not-allowed', 'Not allowed');
} }
if (!settings.get('Accounts_TwoFactorAuthentication_Enabled')) {
throw new Meteor.Error('error-two-factor-not-enabled', 'Two factor authentication is not enabled');
}
const user = await getUserFromParams(this.bodyParams); const user = await getUserFromParams(this.bodyParams);
if (!user) { if (!user) {
throw new Meteor.Error('error-invalid-user-id', 'Invalid user id'); throw new Meteor.Error('error-invalid-user-id', 'Invalid user id');
......
import type { IUser } from '@rocket.chat/core-typings'; import type { IUser } from '@rocket.chat/core-typings';
import { useSetModal, usePermission, useEndpoint, useTranslation, useToastMessageDispatch } from '@rocket.chat/ui-contexts'; import { useSetModal, usePermission, useSetting, useEndpoint, useTranslation, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import React, { useCallback } from 'react'; import React, { useCallback } from 'react';
import GenericModal from '../../../../components/GenericModal'; import GenericModal from '../../../../components/GenericModal';
...@@ -10,6 +10,7 @@ export const useResetTOTPAction = (userId: IUser['_id']): Action | undefined => ...@@ -10,6 +10,7 @@ export const useResetTOTPAction = (userId: IUser['_id']): Action | undefined =>
const setModal = useSetModal(); const setModal = useSetModal();
const dispatchToastMessage = useToastMessageDispatch(); const dispatchToastMessage = useToastMessageDispatch();
const canResetTOTP = usePermission('edit-other-user-totp'); const canResetTOTP = usePermission('edit-other-user-totp');
const twoFactorEnabled = useSetting('Accounts_TwoFactorAuthentication_Enabled');
const resetTOTPRequest = useEndpoint('POST', '/v1/users.resetTOTP'); const resetTOTPRequest = useEndpoint('POST', '/v1/users.resetTOTP');
const resetTOTP = useCallback(async () => { const resetTOTP = useCallback(async () => {
...@@ -31,7 +32,7 @@ export const useResetTOTPAction = (userId: IUser['_id']): Action | undefined => ...@@ -31,7 +32,7 @@ export const useResetTOTPAction = (userId: IUser['_id']): Action | undefined =>
); );
}, [resetTOTP, t, setModal]); }, [resetTOTP, t, setModal]);
return canResetTOTP return canResetTOTP && twoFactorEnabled
? { ? {
icon: 'key', icon: 'key',
label: t('Reset_TOTP'), label: t('Reset_TOTP'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment