Skip to content

Commit

Permalink
[v15] Connect: Fix fetching access requests when leaf cluster is sele…
Browse files Browse the repository at this point in the history
…cted (#48442)

* Always fetch access requests from root cluster

* Replace deprecated imports
  • Loading branch information
ravicious authored Nov 5, 2024
1 parent 8fc6ca2 commit d212204
Showing 1 changed file with 11 additions and 15 deletions.
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

0 comments on commit d212204

Please sign in to comment.