Skip to content

Commit

Permalink
Port #3920 to Kibana
Browse files Browse the repository at this point in the history
  • Loading branch information
scottybollinger committed Jun 24, 2021
1 parent f75af53 commit 6da677e
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('RoleMappingsLogic', () => {
userCreated: false,
userFormIsNewUser: true,
userFormUserIsExisting: true,
smtpSettingsPresent: false,
};

const mappingsServerProps = {
Expand All @@ -70,6 +71,7 @@ describe('RoleMappingsLogic', () => {
hasAdvancedRoles: false,
singleUserRoleMappings: [asSingleUserRoleMapping],
elasticsearchUsers,
smtpSettingsPresent: false,
};

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ export const RoleMappingsLogic = kea<MakeLogicType<RoleMappingsValues, RoleMappi
setUserFormIsNewUser: (_, { userFormIsNewUser }) => userFormIsNewUser,
},
],
smtpSettingsPresent: [
false,
{
setRoleMappingsData: (_, { smtpSettingsPresent }) => smtpSettingsPresent,
},
],
},
selectors: ({ selectors }) => ({
selectedOptions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const User: React.FC = () => {
roleMappingErrors,
userCreated,
userFormIsNewUser,
smtpSettingsPresent,
} = useValues(RoleMappingsLogic);

const roleTypes = hasAdvancedRoles ? [...standardRoles, ...advancedRoles] : standardRoles;
Expand Down Expand Up @@ -82,6 +83,7 @@ export const User: React.FC = () => {
<EuiForm isInvalid={roleMappingErrors.length > 0} error={roleMappingErrors}>
<UserSelector
isNewUser={userFormIsNewUser}
smtpSettingsPresent={smtpSettingsPresent}
elasticsearchUsers={elasticsearchUsers}
handleRoleChange={handleRoleChange}
elasticsearchUser={elasticsearchUser}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,14 @@ export const DEACTIVATED_USER_CALLOUT_DESCRIPTION = i18n.translate(
'This user is not currently active, and access has been temporarily revoked. Users can be re-activated via the User Management area of the Kibana console.',
}
);

export const SMTP_CALLOUT_LABEL = i18n.translate(
'xpack.enterpriseSearch.roleMapping.smtpCalloutLabel',
{
defaultMessage: 'Personalized invitations will be automatically sent when an Enterprise Search',
}
);

export const SMTP_LINK_LABEL = i18n.translate('xpack.enterpriseSearch.roleMapping.smtpLinkLabel', {
defaultMessage: 'SMTP configuration is provided',
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface RoleMappingsBaseServerDetails {
elasticsearchRoles: string[];
elasticsearchUsers: ElasticsearchUser[];
multipleAuthProvidersConfig: boolean;
smtpSettingsPresent: boolean;
}

export interface RoleMappingsBaseActions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react';

import {
EuiFieldText,
EuiLink,
EuiRadio,
EuiFormRow,
EuiSelect,
Expand All @@ -21,19 +22,25 @@ import { ElasticsearchUser } from '../../shared/types';
import { Role as WSRole } from '../../workplace_search/types';

import { USERNAME_LABEL, EMAIL_LABEL } from '../constants';
import { docLinks } from '../doc_links';

const SMTP_URL = `${docLinks.enterpriseSearchBase}/mailer-configuration.html`;

import {
NEW_USER_LABEL,
EXISTING_USER_LABEL,
USERNAME_NO_USERS_TEXT,
REQUIRED_LABEL,
ROLE_LABEL,
SMTP_CALLOUT_LABEL,
SMTP_LINK_LABEL,
} from './constants';

type SharedRole = WSRole | ASRole;

interface Props {
isNewUser: boolean;
smtpSettingsPresent: boolean;
userFormUserIsExisting: boolean;
elasticsearchUsers: ElasticsearchUser[];
elasticsearchUser: ElasticsearchUser;
Expand All @@ -48,6 +55,7 @@ interface Props {

export const UserSelector: React.FC<Props> = ({
isNewUser,
smtpSettingsPresent,
userFormUserIsExisting,
elasticsearchUsers,
elasticsearchUser,
Expand All @@ -66,6 +74,14 @@ export const UserSelector: React.FC<Props> = ({
}));
const hasElasticsearchUsers = elasticsearchUsers.length > 0;
const showNewUserExistingUserControls = userFormUserIsExisting && hasElasticsearchUsers;
const smptHelpText = !smtpSettingsPresent && (
<>
{SMTP_CALLOUT_LABEL}{' '}
<EuiLink href={SMTP_URL} target="_blank">
{SMTP_LINK_LABEL}
</EuiLink>
</>
);

const roleSelect = (
<EuiFormRow label={ROLE_LABEL}>
Expand All @@ -80,7 +96,7 @@ export const UserSelector: React.FC<Props> = ({
);

const emailInput = (
<EuiFormRow label={EMAIL_LABEL}>
<EuiFormRow label={EMAIL_LABEL} helpText={smptHelpText}>
<EuiFieldText
name={EMAIL_LABEL}
data-test-subj="EmailInput"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('RoleMappingsLogic', () => {
userCreated: false,
userFormIsNewUser: true,
userFormUserIsExisting: true,
smtpSettingsPresent: false,
};
const roleGroup = {
id: '123',
Expand All @@ -76,6 +77,7 @@ describe('RoleMappingsLogic', () => {
elasticsearchRoles: [],
singleUserRoleMappings: [wsSingleUserRoleMapping],
elasticsearchUsers,
smtpSettingsPresent: false,
};

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ export const RoleMappingsLogic = kea<MakeLogicType<RoleMappingsValues, RoleMappi
setUserFormIsNewUser: (_, { userFormIsNewUser }) => userFormIsNewUser,
},
],
smtpSettingsPresent: [
false,
{
setRoleMappingsData: (_, { smtpSettingsPresent }) => smtpSettingsPresent,
},
],
},
selectors: ({ selectors }) => ({
selectedOptions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const User: React.FC = () => {
roleMappingErrors,
userCreated,
userFormIsNewUser,
smtpSettingsPresent,
} = useValues(RoleMappingsLogic);

const showGroupAssignmentSelector = availableGroups.length > 0;
Expand Down Expand Up @@ -79,6 +80,7 @@ export const User: React.FC = () => {
<EuiForm isInvalid={roleMappingErrors.length > 0} error={roleMappingErrors}>
<UserSelector
isNewUser={userFormIsNewUser}
smtpSettingsPresent={smtpSettingsPresent}
elasticsearchUsers={elasticsearchUsers}
handleRoleChange={handleRoleChange}
elasticsearchUser={elasticsearchUser}
Expand Down

0 comments on commit 6da677e

Please sign in to comment.