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

Connect: Fix fetching access requests when leaf cluster is selected #48433

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ import {
import { RequestFlags } from 'shared/components/AccessRequests/ReviewRequests';

import { Timestamp } from 'gen-proto-ts/google/protobuf/timestamp_pb';
import { LoggedInUser } from 'gen-proto-ts/teleport/lib/teleterm/v1/cluster_pb';
import { AccessRequest as TshdAccessRequest } from 'gen-proto-ts/teleport/lib/teleterm/v1/access_request_pb';

import * as types from 'teleterm/ui/services/workspacesService';
import {
AssumedRequest,
LoggedInUser,
AccessRequest as TshdAccessRequest,
} from 'teleterm/services/tshd/types';
import { AssumedRequest } from 'teleterm/services/tshd/types';

import { useAppContext } from 'teleterm/ui/appContextProvider';
import { retryWithRelogin } from 'teleterm/ui/utils';
Expand All @@ -45,11 +43,7 @@ export default function useAccessRequests(doc: types.DocumentAccessRequests) {
const ctx = useAppContext();
ctx.clustersService.useState();

const {
localClusterUri: clusterUri,
rootClusterUri,
documentsService,
} = useWorkspaceContext();
const { rootClusterUri, documentsService } = useWorkspaceContext();

const assumed = ctx.clustersService.getAssumedRequests(rootClusterUri);
const loggedInUser = useWorkspaceLoggedInUser();
Expand All @@ -74,12 +68,14 @@ export default function useAccessRequests(doc: types.DocumentAccessRequests) {

const getRequests = async () => {
try {
const response = await retryWithRelogin(ctx, clusterUri, async () => {
const { response } = await ctx.tshd.getAccessRequests({ clusterUri });
const response = await retryWithRelogin(ctx, rootClusterUri, async () => {
const { response } = await ctx.tshd.getAccessRequests({
clusterUri: rootClusterUri,
});
return response.requests;
});
setAttempt({ status: 'success' });
// transform tshd access request to the webui access request and add flags
// Transform tshd access request to the webui access request and add flags.
const requests = response.map(r => makeUiAccessRequest(r));
setAccessRequests(requests);
} catch (err) {
Expand All @@ -91,11 +87,11 @@ export default function useAccessRequests(doc: types.DocumentAccessRequests) {
};

useEffect(() => {
// only fetch when visitng RequestList
// Only fetch when visiting RequestList.
if (doc.state === 'browsing') {
getRequests();
}
}, [doc.state, clusterUri]);
}, [doc.state]);

useEffect(() => {
// if assumed object changes, we update which roles have been assumed in the table
Expand Down
Loading