-
Notifications
You must be signed in to change notification settings - Fork 704
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add NTLM Credentials support (#2710)
- Loading branch information
1 parent
193e6e4
commit ec21350
Showing
12 changed files
with
236 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { Reducer } from 'redux'; | ||
|
||
import type { ActionOf } from '../../store/actions'; | ||
import { | ||
APP_ALLOWED_NTLM_CREDENTIALS_DOMAINS_SET, | ||
APP_SETTINGS_LOADED, | ||
} from '../actions'; | ||
|
||
type allowedNTLMCredentialsDomainsAction = | ||
| ActionOf<typeof APP_SETTINGS_LOADED> | ||
| ActionOf<typeof APP_ALLOWED_NTLM_CREDENTIALS_DOMAINS_SET>; | ||
|
||
export const allowedNTLMCredentialsDomains: Reducer< | ||
string | null, | ||
allowedNTLMCredentialsDomainsAction | ||
> = (state = null, action) => { | ||
switch (action.type) { | ||
case APP_SETTINGS_LOADED: { | ||
const { allowedNTLMCredentialsDomains = state } = action.payload; | ||
return allowedNTLMCredentialsDomains; | ||
} | ||
|
||
case APP_ALLOWED_NTLM_CREDENTIALS_DOMAINS_SET: { | ||
if (action.payload === null) return null; | ||
return action.payload; | ||
} | ||
|
||
default: | ||
return state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/ui/components/SettingsView/features/NTLMCredentials.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Field, InputBox, ToggleSwitch } from '@rocket.chat/fuselage'; | ||
import React, { | ||
useCallback, | ||
type ChangeEvent, | ||
type Dispatch, | ||
type FC, | ||
} from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
|
||
import { APP_ALLOWED_NTLM_CREDENTIALS_DOMAINS_SET } from '../../../../app/actions'; | ||
import type { RootAction } from '../../../../store/actions'; | ||
import type { RootState } from '../../../../store/rootReducer'; | ||
import { SETTINGS_NTLM_CREDENTIALS_CHANGED } from '../../../actions'; | ||
|
||
type Props = { | ||
className?: string; | ||
}; | ||
|
||
export const NTLMCredentials: FC<Props> = (props) => { | ||
const isNTLMCredentialsEnabled = useSelector( | ||
({ isNTLMCredentialsEnabled }: RootState) => isNTLMCredentialsEnabled | ||
); | ||
const allowedNTLMCredentialsDomains = useSelector( | ||
({ allowedNTLMCredentialsDomains }: RootState) => | ||
allowedNTLMCredentialsDomains | ||
); | ||
const { t } = useTranslation(); | ||
const dispatch = useDispatch<Dispatch<RootAction>>(); | ||
|
||
const handleToggleChange = useCallback( | ||
(event: ChangeEvent<HTMLInputElement>) => { | ||
const isChecked = event.currentTarget.checked; | ||
dispatch({ | ||
type: SETTINGS_NTLM_CREDENTIALS_CHANGED, | ||
payload: isChecked, | ||
}); | ||
}, | ||
[dispatch] | ||
); | ||
|
||
const handleDomainsChange = useCallback( | ||
(event: React.FocusEvent<HTMLInputElement>) => { | ||
const domains = event.target.value; | ||
dispatch({ | ||
type: APP_ALLOWED_NTLM_CREDENTIALS_DOMAINS_SET, | ||
payload: domains, | ||
}); | ||
}, | ||
[dispatch] | ||
); | ||
|
||
return ( | ||
<Field className={props.className}> | ||
<Field.Row> | ||
<ToggleSwitch | ||
onChange={handleToggleChange} | ||
checked={isNTLMCredentialsEnabled} | ||
/> | ||
<Field.Label htmlFor='toggle-switch'> | ||
{t('settings.options.ntlmCredentials.title')} | ||
</Field.Label> | ||
</Field.Row> | ||
<Field.Row> | ||
<Field.Hint> | ||
{t('settings.options.ntlmCredentials.description')} | ||
</Field.Hint> | ||
</Field.Row> | ||
<Field.Row> | ||
<Field.Row size={'100%'}> | ||
<InputBox | ||
defaultValue={allowedNTLMCredentialsDomains as string} | ||
onBlur={handleDomainsChange} | ||
type={'text'} | ||
disabled={!isNTLMCredentialsEnabled} | ||
placeholder='*example.com, *foobar.com, *baz' | ||
/> | ||
</Field.Row> | ||
</Field.Row> | ||
<Field.Row> | ||
<Field.Hint>{t('settings.options.ntlmCredentials.domains')}</Field.Hint> | ||
</Field.Row> | ||
</Field> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Reducer } from 'redux'; | ||
|
||
import { APP_SETTINGS_LOADED } from '../../app/actions'; | ||
import type { ActionOf } from '../../store/actions'; | ||
import { SETTINGS_NTLM_CREDENTIALS_CHANGED } from '../actions'; | ||
|
||
type isNTLMCredentialsEnabledAction = | ||
| ActionOf<typeof APP_SETTINGS_LOADED> | ||
| ActionOf<typeof SETTINGS_NTLM_CREDENTIALS_CHANGED>; | ||
|
||
export const isNTLMCredentialsEnabled: Reducer< | ||
boolean, | ||
isNTLMCredentialsEnabledAction | ||
> = (state = false, action) => { | ||
switch (action.type) { | ||
case APP_SETTINGS_LOADED: { | ||
const { isNTLMCredentialsEnabled = state } = action.payload; | ||
return isNTLMCredentialsEnabled; | ||
} | ||
|
||
case SETTINGS_NTLM_CREDENTIALS_CHANGED: { | ||
return action.payload; | ||
} | ||
|
||
default: | ||
return state; | ||
} | ||
}; |