Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 17x 17x 17x 17x 17x 17x 2x 17x 17x 17x 7x 17x 1x 1x 1x 1x 1x 1x 17x 3x 3x 3x 2x 2x 1x 1x 17x 17x 1x 34x 4x | /* * Copyright 2022 Harness Inc. All rights reserved. * Use of this source code is governed by the PolyForm Free Trial 1.0.0 license * that can be found in the licenses directory at the root of this repository, also available at * https://polyformproject.org/wp-content/uploads/2020/05/PolyForm-Free-Trial-1.0.0.txt. */ import React, { Dispatch, SetStateAction } from 'react' import cx from 'classnames' import { useParams } from 'react-router-dom' import { Layout, Text, Container, Switch, Collapse, Button, ButtonVariation, useConfirmationDialog } from '@wings-software/uicore' import { Color, Intent } from '@harness/design-system' import type { LoginSettings } from 'services/cd-ng' import { usePasswordExpirationModal } from '@auth-settings/modals/PasswordExpiration/usePasswordExpiration' import { usePutLoginSettings } from 'services/cd-ng' import type { AccountPathProps } from '@common/interfaces/RouteInterfaces' import { useStrings } from 'framework/strings' import { useToaster } from '@common/components' import useRBACError from '@rbac/utils/useRBACError/useRBACError' import cssConfiguration from '@auth-settings/pages/Configuration/Configuration.module.scss' import cssHarnessAccount from '@auth-settings/pages/Configuration/AccountAndOAuth/HarnessAccount/HarnessAccount.module.scss' interface Props { loginSettings: LoginSettings refetchAuthSettings: () => void canEdit: boolean setUpdating: Dispatch<SetStateAction<boolean>> } const PasswordExpire: React.FC<Props> = ({ loginSettings, refetchAuthSettings, canEdit, setUpdating }) => { const { getRBACErrorMessage } = useRBACError() const { getString } = useStrings() const { accountId } = useParams<AccountPathProps>() const { showSuccess, showError } = useToaster() const passwordExpirationSettings = loginSettings.passwordExpirationPolicy const onSuccess = (): void => { refetchAuthSettings() } const { openPasswordExpirationModal } = usePasswordExpirationModal({ onSuccess, loginSettings }) const { mutate: updateLoginSettings, loading: updatingLoginSettings } = usePutLoginSettings({ loginSettingsId: loginSettings.uuid, queryParams: { accountIdentifier: accountId } }) React.useEffect(() => { setUpdating(updatingLoginSettings) }, [updatingLoginSettings, setUpdating]) const { openDialog: confirmPasswordExpirySettings } = useConfirmationDialog({ titleText: getString('authSettings.disablePasswordExpiration'), contentText: getString('authSettings.confirmDisablePasswordExpiration'), confirmButtonText: getString('confirm'), cancelButtonText: getString('cancel'), intent: Intent.WARNING, onCloseDialog: async isConfirmed => { /* istanbul ignore else */ if (isConfirmed) { try { const response = await updateLoginSettings({ ...loginSettings, passwordExpirationPolicy: { ...passwordExpirationSettings, enabled: false } }) /* istanbul ignore else */ if (response) { refetchAuthSettings() showSuccess(getString('authSettings.passwordExpirationDisabled'), 5000) } } catch (e) { /* istanbul ignore next */ showError(getRBACErrorMessage(e), 5000) } } } }) const onChangePasswordExpiry = (e: React.FormEvent<HTMLInputElement>): void => { const enable = e.currentTarget.checked const currentState = passwordExpirationSettings.enabled if (!currentState && enable) { openPasswordExpirationModal(false) return } /* istanbul ignore else */ if (currentState && !enable) { confirmPasswordExpirySettings() } } const list = [ { label: getString('authSettings.daysBeforePasswordExpires'), value: passwordExpirationSettings.daysBeforePasswordExpires }, { label: getString('authSettings.daysBeforeUserNotified'), value: passwordExpirationSettings.daysBeforeUserNotifiedOfPasswordExpiration } ] return ( <Collapse isOpen={passwordExpirationSettings.enabled} collapseHeaderClassName={cx(cssConfiguration.collapseHeaderClassName, cssHarnessAccount.collapseIcon)} collapseClassName={cssConfiguration.collapseClassName} collapsedIcon="main-chevron-down" expandedIcon="main-chevron-up" heading={ <Switch label={getString('authSettings.periodicallyExpirePassword')} checked={passwordExpirationSettings.enabled} onChange={onChangePasswordExpiry} disabled={!canEdit || updatingLoginSettings} font={{ weight: 'semi-bold', size: 'normal' }} color={Color.GREY_800} data-testid="toggle-password-expire" /> } > <Layout.Vertical spacing="small" padding={{ left: 'xxxlarge', top: 'medium', bottom: 'medium', right: 'medium' }} margin={{ bottom: 'large' }} className={cssHarnessAccount.passwordChecksDiv} > <div className={cssHarnessAccount.editIcon}> <Button variation={ButtonVariation.ICON} icon="Edit" onClick={() => openPasswordExpirationModal(true)} data-testid="update-password-expire-settings" disabled={!canEdit} /> </div> <Text margin={{ bottom: 'xsmall' }} color={Color.BLACK}> {getString('authSettings.periodicallyExpirePasswordNote')} </Text> {list.map(({ label, value }) => ( <Container flex={{ justifyContent: 'flex-start' }} key={label}> <Text color={Color.GREY_800} icon="dot"> {label}: </Text> <Text color={Color.GREY_800} font={{ weight: 'bold' }} padding={{ left: 'xsmall' }}> {value} </Text> </Container> ))} </Layout.Vertical> </Collapse> ) } export default PasswordExpire |