Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enterprise Search] Add User management feature #103173

Conversation

scottybollinger
Copy link
Contributor

closes https://github.com/elastic/enterprise-search-team/issues/597

closes https://github.com/elastic/enterprise-search-team/issues/599

closes https://github.com/elastic/enterprise-search-team/issues/668

closes https://github.com/elastic/enterprise-search-team/issues/669

closes https://github.com/elastic/enterprise-search-team/issues/654

closes https://github.com/elastic/enterprise-search-team/issues/678

Summary

This is the remaining monster PR for the User management feature in Kibana. It follows #102826 and is a combined port of https://github.com/elastic/ent-search/pull/3861 and https://github.com/elastic/ent-search/pull/3853.

There are also some bugfix ports added as the last several commits. When applicable, a link to the ent-search equivalent and/or issue is linked.

This is a DRYtemare so please ignore duplicated code.

Checklist

This is shared with the forthcoming user flyouts

closeRoleMappingFlyout -> closeUsersAndRolesFlyout
- Showing and hiding flyouts
- Select and text input values
- User created state to turn flyout into a success message state
- Users & roles -> Users and roles
- roleId -> roleMappingId (matches other places in code)
- also added a missing prop to the actions col
The UI sets the default group on page load but did not cover the case where the user has chosen a group in a previous interaction and the closed the flyout. This commit adds a method that resets that state when the flyout is closed

Part of porting of https://github.com/elastic/ent-search/pull/3865

Specifically:
https://github.com/elastic/ent-search/commit/a4131b95dab7c0df97bd78e660f25e09ac3e7cec
Role-> RoleTypes
🤷🏽‍♀️
Wasn’t needed in ent-search; already done for RomeMappingFlyout. Hide whitespace changes plskthx
Since we're moving fully into Kibana, we're losing our concept of auth providers. In 8.0, role mappings the specify an auth provider will no
longer work, so this adds a small deprecation warning in the role mappings table.

https://github.com/elastic/ent-search/pull/3885
After a slack discussion, it was determined that email should be optional.

This commit also fixes another instance of the App Search role type being wrong.
@scottybollinger scottybollinger added Feature:Plugins release_note:skip Skip the PR/issue when compiling release notes v7.14.0 auto-backport Deprecated - use backport:version if exact versions are needed labels Jun 23, 2021
@scottybollinger scottybollinger requested review from a team June 23, 2021 19:54
@kibanamachine
Copy link
Contributor

⏳ Build in-progress, with failures

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

3 similar comments
@kibanamachine
Copy link
Contributor

⏳ Build in-progress, with failures

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

⏳ Build in-progress, with failures

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

⏳ Build in-progress, with failures

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@scottybollinger
Copy link
Contributor Author

@elasticmachine merge upstream

} = useValues(RoleMappingsLogic);

useEffect(() => {
initializeRoleMappings();
return resetState;
}, []);

const hasUsers = singleUserRoleMappings.length > 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional techdebt for the future] I've recently been refactoring flags like these to Kea selectors, it just generally feels nicer to have them in Kea

Need to change folder and file names but will punt until after 7.14FF

I did throw in updating the logic file path
@scottybollinger
Copy link
Contributor Author

@elasticmachine merge upstream

@scottybollinger
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
enterpriseSearch 1455 1457 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
enterpriseSearch 2.1MB 2.2MB +31.9KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Comment on lines +26 to +27
const standardRoles = (['owner', 'admin'] as unknown) as RoleTypes[];
const advancedRoles = (['dev', 'editor', 'analyst'] as unknown) as RoleTypes[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, fun with Typescript - this is where enums are a little nicer to use than string unions I think (not a change request, just me rambling out loud)

Comment on lines +46 to +47
setMockActions({
handleSaveUser,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[not a change request, just a comment] in general in AS we put our actions in a single obj, similar to mockValues, so they don't need to be redeclared individually here:

const mockActions = { a: jest.fn(), b: jest.fn() } // etc
setMockActions(mockActions);

just a little less repetitive is all

import { RoleRules } from '../types';

import './role_mappings_table.scss';

const AUTH_PROVIDER_DOCUMENTATION_URL = `${docLinks.enterpriseSearchBase}/users-access.html`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] It might be nice to move documentation links to constants.ts as well for organization

<EuiLink href={AUTH_PROVIDER_DOCUMENTATION_URL} target="_blank">
<EuiIconTip type="alert" color="warning" content={AUTH_PROVIDER_TOOLTIP} />
</EuiLink>
</span>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is QAing well for me 👍

Comment on lines +69 to +72
it('renders without email', () => {
const wrapper = shallow(<UserAddedInfo {...props} email="" />);

expect(wrapper).toMatchInlineSnapshot(`
Copy link
Contributor

@cee-chen cee-chen Jun 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, glad you got to use inline snapshots so soon! these test names are great for helping understand/look for the rendered diffs, thanks for that 💯

@@ -19,6 +19,8 @@ interface Props {
roleType: string;
}

const noItemsPlaceholder = <EuiTextColor color="subdued">&mdash;</EuiTextColor>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional/personal preference] If this isn't being reused in multiple places, maybe just leave it in inline? 🤷

Comment on lines +96 to +97
<EuiPortal>
<EuiFlyout ownFocus onClose={closeUserFlyout} size="s" aria-labelledby="userFlyoutTitle">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch on this EuiPortal!

Super optional, but as of EUI 34.x I believe EuiFlyout now defaults to ownFocus={true} so you could leave it out if you wanted. Don't worry if you'd rather not though, there's plenty of other flyouts in our app that still have ownFocus, so we could opt to clean it up across the board in a separate PR

}

export const RoleMappingsLogic = kea<MakeLogicType<RoleMappingsValues, RoleMappingsActions>>({
path: ['enterprise_search', 'app_search', 'role_mappings'],
path: ['enterprise_search', 'app_search', 'users_and_roles'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[not a change request] I wonder if we should similarly change all our folder/file names (e.g. components/role_mappings -> components/user_and_roles). Might make more sense in 7.15 when we're cleaning/DRYing things out though, especially if we split up the logic files into role_mappings_logic vs users_logic

Comment on lines +412 to +414
const singleUserRoleMapping = values.singleUserRoleMappings.find(
({ roleMapping }) => roleMapping.id === roleMappingId
);
Copy link
Contributor

@cee-chen cee-chen Jun 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[not a change request] in a future refactor, do you think it would be worth storing a map copy of of user roles with id as key so lookup is immediate rather than having to search through an array?... 🤔

... i'm definitely overthinking this. just give me my own paragraph in this blog post already :neckbeard:

EDIT: HMMM wait tho, we're already using Set() in this logic file! I mean, if we're ALREADY being all cool and microperfing, I'm just sayin'

Comment on lines +524 to +525
const user = values.elasticsearchUsers.find((u) => u.username === username);
if (user) actions.setElasticsearchUser(user);
Copy link
Contributor

@cee-chen cee-chen Jun 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional, just me being a jerk] i'm generally not a super huge fan of single letter vars, maybe this could help w/ specificity?

Suggested change
const user = values.elasticsearchUsers.find((u) => u.username === username);
if (user) actions.setElasticsearchUser(user);
const selectedUser = values.elasticsearchUsers.find((user) => user.username === username);
if (selectedUser) actions.setElasticsearchUser(selectedUser);

Copy link
Contributor

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional comments only!! My QA was not super thorough but from what I could tell everything on AS worked with both role mappings and users 🎉

Seriously can't applaud y'all for getting this out as fast as you did, huge kudos!

@scottybollinger scottybollinger merged commit a50d949 into elastic:master Jun 24, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Jun 24, 2021
* Rename method to close both flyouts

This is shared with the forthcoming user flyouts

closeRoleMappingFlyout -> closeUsersAndRolesFlyout

* Add logic for elasticsearch users and single user role mappings

* Add logic for various form states

- Showing and hiding flyouts
- Select and text input values
- User created state to turn flyout into a success message state

* Add User server routes

* Add logic for saving a user

* Add User components

* Add User list and User flyout to RoleMappings view

* Fix path

* Rename things

- Users & roles -> Users and roles
- roleId -> roleMappingId (matches other places in code)
- also added a missing prop to the actions col

* Set default group when modal closed

The UI sets the default group on page load but did not cover the case where the user has chosen a group in a previous interaction and the closed the flyout. This commit adds a method that resets that state when the flyout is closed

Part of porting of elastic/ent-search#3865

Specifically:
elastic/ent-search@a4131b9

* Adds tooltip for external attribute

This was missed from the design

Part of porting of elastic/ent-search#3865

Specifically:
elastic/ent-search@03aa349

* Fix invitations link

* Fix incorrect role type

Role-> RoleTypes
🤷🏽‍♀️

* Add EuiPortal to Flyout

Wasn’t needed in ent-search; already done for RomeMappingFlyout. Hide whitespace changes plskthx

* Auth provider deprecation warning in mapping UI

Since we're moving fully into Kibana, we're losing our concept of auth providers. In 8.0, role mappings the specify an auth provider will no
longer work, so this adds a small deprecation warning in the role mappings table.

elastic/ent-search#3885

* Email is no longer required

After a slack discussion, it was determined that email should be optional.

This commit also fixes another instance of the App Search role type being wrong.

* Existing users’ usernames should not be editable

* Use EuiLink instead of anchor

* Add validation tests

* Change URL for users_and_roles

Need to change folder and file names but will punt until after 7.14FF

I did throw in updating the logic file path

* Remove unused import

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

@scottybollinger
Copy link
Contributor Author

Thanks @constancecchen! CI issues yesterday had me worried and I have PRs depending on this so I merged and just made notes of all the change requests in the refactor doc for 7.15.

@scottybollinger scottybollinger deleted the scottybollinger/es-user-management branch June 24, 2021 13:02
kibanamachine added a commit that referenced this pull request Jun 24, 2021
* Rename method to close both flyouts

This is shared with the forthcoming user flyouts

closeRoleMappingFlyout -> closeUsersAndRolesFlyout

* Add logic for elasticsearch users and single user role mappings

* Add logic for various form states

- Showing and hiding flyouts
- Select and text input values
- User created state to turn flyout into a success message state

* Add User server routes

* Add logic for saving a user

* Add User components

* Add User list and User flyout to RoleMappings view

* Fix path

* Rename things

- Users & roles -> Users and roles
- roleId -> roleMappingId (matches other places in code)
- also added a missing prop to the actions col

* Set default group when modal closed

The UI sets the default group on page load but did not cover the case where the user has chosen a group in a previous interaction and the closed the flyout. This commit adds a method that resets that state when the flyout is closed

Part of porting of elastic/ent-search#3865

Specifically:
elastic/ent-search@a4131b9

* Adds tooltip for external attribute

This was missed from the design

Part of porting of elastic/ent-search#3865

Specifically:
elastic/ent-search@03aa349

* Fix invitations link

* Fix incorrect role type

Role-> RoleTypes
🤷🏽‍♀️

* Add EuiPortal to Flyout

Wasn’t needed in ent-search; already done for RomeMappingFlyout. Hide whitespace changes plskthx

* Auth provider deprecation warning in mapping UI

Since we're moving fully into Kibana, we're losing our concept of auth providers. In 8.0, role mappings the specify an auth provider will no
longer work, so this adds a small deprecation warning in the role mappings table.

elastic/ent-search#3885

* Email is no longer required

After a slack discussion, it was determined that email should be optional.

This commit also fixes another instance of the App Search role type being wrong.

* Existing users’ usernames should not be editable

* Use EuiLink instead of anchor

* Add validation tests

* Change URL for users_and_roles

Need to change folder and file names but will punt until after 7.14FF

I did throw in updating the logic file path

* Remove unused import

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Scotty Bollinger <scotty.bollinger@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Plugins release_note:skip Skip the PR/issue when compiling release notes v7.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants