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

fix username not shown for OIDC users #4324

Merged
merged 5 commits into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions webui/src/lib/components/auth/nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ export const GroupNav = ({ groupId, page = 'groups' }) => {
);
};


export const UserHeader = ({ userId, page }) => {
export const UserHeader = ({ userEmail, userId, page }) => {
return (
<div className="mb-4">
<Breadcrumb>
<Link component={BreadcrumbItem} href='/auth/users'>
Users
</Link>
<Link component={BreadcrumbItem} href={{pathname: '/auth/users/:userId', params: {userId}}}>
{userId}
{userEmail}
</Link>
</Breadcrumb>

Expand Down
79 changes: 59 additions & 20 deletions webui/src/pages/auth/users/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect, useState} from "react";
import React, {createContext, useCallback, useEffect, useState} from "react";
import {Route, Switch} from "react-router-dom";

import Button from "react-bootstrap/Button";
Expand All @@ -24,22 +24,22 @@ import {
import UserPage from "./user";
import validator from "validator/es";

const USER_NOT_FOUND = "unknown";
export const GetUserEmailByIdContext = createContext();

const UsersContainer = () => {

const UsersContainer = ({nextPage, refresh, setRefresh, error, loading, userListResults}) => {
const { user } = useUser();
const currentUser = user;

const router = useRouter();
const after = (router.query.after) ? router.query.after : "";
const [selected, setSelected] = useState([]);
const [deleteError, setDeleteError] = useState(null);
const [showCreate, setShowCreate] = useState(false);
const [showInvite, setShowInvite] = useState(false);
const [refresh, setRefresh] = useState(false);

const router = useRouter();
const after = (router.query.after) ? router.query.after : "";
const { results, loading, error, nextPage } = useAPIWithPagination(() => {
return auth.listUsers('', after);
}, [after, refresh]);



useEffect(() => { setSelected([]); }, [refresh, after]);

Expand Down Expand Up @@ -105,7 +105,7 @@ const UsersContainer = () => {
/>

<DataTable
results={results}
results={userListResults}
headers={['', 'User ID', 'Created At']}
keyFn={user => user.id}
rowFn={user => [
Expand Down Expand Up @@ -157,24 +157,63 @@ const UserActionsActionGroup = ({canInviteUsers, selected, onClickInvite, onClic
);
}

const UsersPage = () => {
const UsersPage = ({nextPage, refresh, setRefresh, error, loading, userListResults}) => {
return (
<AuthLayout activeTab="users">
<UsersContainer/>
<UsersContainer
refresh={refresh}
loading={loading}
error={error}
nextPage={nextPage}
setRefresh={setRefresh}
userListResults={userListResults}
/>
</AuthLayout>
);
};

const UsersIndexPage = () => {
const [refresh, setRefresh] = useState(false);
const [usersList, setUsersList] = useState([]);
const router = useRouter();
const after = (router.query.after) ? router.query.after : "";
const { results, loading, error, nextPage } = useAPIWithPagination(() => {
return auth.listUsers('', after);
}, [after, refresh]);

useEffect(() => {
setUsersList(results);
}, [results, refresh]);

const getUserEmailById = useCallback((id) => {
const userRecord = usersList.find(user => user.id === id);
// return something, so we don't completely break the state
// this can help us track down issues later on
if (!userRecord) {
return USER_NOT_FOUND;
}

return userRecord.email || userRecord.id;
}, [usersList]);

return (
<Switch>
<Route path="/auth/users/:userId">
<UserPage/>
</Route>
<Route path="/auth/users">
<UsersPage/>
</Route>
</Switch>
<GetUserEmailByIdContext.Provider value={getUserEmailById}>
<Switch>
<Route path="/auth/users/:userId">
<UserPage getUserEmailById={getUserEmailById} />
</Route>
<Route path="/auth/users">
<UsersPage
refresh={refresh}
loading={loading}
error={error}
nextPage={nextPage}
setRefresh={setRefresh}
userListResults={usersList}
/>
</Route>
</Switch>
</GetUserEmailByIdContext.Provider>
)
}

Expand Down
4 changes: 2 additions & 2 deletions webui/src/pages/auth/users/user/credentials.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useState} from "react";

import {AuthLayout} from "../../../../lib/components/auth/layout";
import {UserHeader} from "../../../../lib/components/auth/nav";
import { UserHeaderWithContext } from "./userHeaderWithContext";
import {auth} from "../../../../lib/api";
import {CredentialsShowModal, CredentialsTable} from "../../../../lib/components/auth/credentials";
import useUser from "../../../../lib/hooks/user";
Expand Down Expand Up @@ -46,7 +46,7 @@ const UserCredentialsList = ({ userId, after, onPaginate }) => {

return (
<>
<UserHeader userId={userId} page={'credentials'}/>
<UserHeaderWithContext userId={userId} page={'credentials'}/>

<ActionsBar>
<ActionGroup orientation="left">
Expand Down
4 changes: 2 additions & 2 deletions webui/src/pages/auth/users/user/effectivePolicies.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useState} from "react";

import {AuthLayout} from "../../../../lib/components/auth/layout";
import {UserHeader} from "../../../../lib/components/auth/nav";
import { UserHeaderWithContext } from "./userHeaderWithContext";
import {useAPIWithPagination} from "../../../../lib/hooks/api";
import {auth} from "../../../../lib/api";
import {Paginator} from "../../../../lib/components/pagination";
Expand Down Expand Up @@ -48,7 +48,7 @@ const UserEffectivePoliciesList = ({ userId, after, onPaginate }) => {

return (
<>
<UserHeader userId={userId} page={'effectivePolicies'}/>
<UserHeaderWithContext userId={userId} page={'effectivePolicies'}/>

<ActionsBar>
<ActionGroup orientation="left">
Expand Down
6 changes: 3 additions & 3 deletions webui/src/pages/auth/users/user/groups.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import {AuthLayout} from "../../../../lib/components/auth/layout";
import {UserHeader} from "../../../../lib/components/auth/nav";
import { UserHeaderWithContext } from "./userHeaderWithContext";
import {
ActionGroup,
ActionsBar,
Expand Down Expand Up @@ -85,7 +85,7 @@ const UserGroupsList = ({ userId, after, onPaginate }) => {

return (
<>
<UserHeader userId={userId} page={'groups'}/>
<UserHeaderWithContext userId={userId} page={'groups'}/>

<ActionsBar>
<ActionGroup orientation="left">
Expand Down Expand Up @@ -118,7 +118,7 @@ const UserGroupsContainer = () => {
const UserGroupsPage = () => {
return (
<AuthLayout activeTab="users">
<UserGroupsContainer/>
<UserGroupsContainer />
</AuthLayout>
);
};
Expand Down
8 changes: 4 additions & 4 deletions webui/src/pages/auth/users/user/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ export default function UserPage() {
<UserRedirect subPath="/groups"/>
</Route>
<Route exact path="/auth/users/:userId/groups">
<UserGroupsPage/>
<UserGroupsPage />
</Route>
<Route exact path="/auth/users/:userId/policies">
<UserPoliciesPage/>
<UserPoliciesPage />
</Route>
<Route exact path="/auth/users/:userId/policies/effective">
<UserEffectivePoliciesPage/>
<UserEffectivePoliciesPage />
</Route>
<Route exact path="/auth/users/:userId/credentials">
<UserCredentialsPage/>
<UserCredentialsPage />
</Route>
</Switch>
);
Expand Down
6 changes: 3 additions & 3 deletions webui/src/pages/auth/users/user/policies.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import {AuthLayout} from "../../../../lib/components/auth/layout";
import {UserHeader} from "../../../../lib/components/auth/nav";
import {UserHeaderWithContext} from "./userHeaderWithContext";
import {
ActionGroup,
ActionsBar,
Expand Down Expand Up @@ -86,7 +86,7 @@ const UserPoliciesList = ({ userId, after, onPaginate }) => {

return (
<>
<UserHeader userId={userId} page={'policies'}/>
<UserHeaderWithContext userId={userId} page={'policies'}/>

<ActionsBar>
<ActionGroup orientation="left">
Expand Down Expand Up @@ -119,7 +119,7 @@ const UserPoliciesContainer = () => {
const UserPoliciesPage = () => {
return (
<AuthLayout activeTab="users">
<UserPoliciesContainer/>
<UserPoliciesContainer />
</AuthLayout>
);
};
Expand Down
16 changes: 16 additions & 0 deletions webui/src/pages/auth/users/user/userHeaderWithContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { FC, useContext } from "react";
import {UserHeader} from "../../../../lib/components/auth/nav";
import { GetUserEmailByIdContext } from "../index";

export interface UserHeaderWithContextProps {
userId: string;
page: string;
}

export const UserHeaderWithContext: FC<UserHeaderWithContextProps> = ({ userId, page }) => {
const getUserEmailById = useContext(GetUserEmailByIdContext);
const email = getUserEmailById(userId);
return (
<UserHeader userId={userId} userEmail={email} page={page} />
);
};