Skip to content

Commit

Permalink
fix username not shown for OIDC users (#4324)
Browse files Browse the repository at this point in the history
Fix - email not shown on the user details page even when it's provided by the OIDC provider
  • Loading branch information
eladlachmi authored Oct 9, 2022
1 parent 2a377e9 commit 447c5e9
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 37 deletions.
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} />
);
};

0 comments on commit 447c5e9

Please sign in to comment.