Skip to content

Commit b91395a

Browse files
authored
Hide review box if user cannot review access requests (#49785)
oss counterpart for gravitational/teleport.e#5628 This adds some testing to the view as well as the equivalent to the web solution for Connect. Connect was missing the [recently added](#48536) `ReviewRequests` field in the user ACL, so I added it here. Because this is handled in the tsh code, we don't have to worry about backward compatibility here for Connect right?
1 parent 331938d commit b91395a

File tree

12 files changed

+272
-159
lines changed

12 files changed

+272
-159
lines changed

gen/proto/go/teleport/lib/teleterm/v1/cluster.pb.go

Lines changed: 45 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/proto/ts/teleport/lib/teleterm/v1/cluster_pb.ts

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/teleterm/clusters/cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func (c *Cluster) GetWithDetails(ctx context.Context, authClient authclient.Clie
213213
Dbs: convertToAPIResourceAccess(userACL.DBServers),
214214
Kubeservers: convertToAPIResourceAccess(userACL.KubeServers),
215215
AccessRequests: convertToAPIResourceAccess(userACL.AccessRequests),
216+
ReviewRequests: userACL.ReviewRequests,
216217
}
217218

218219
withDetails := &ClusterWithDetails{

proto/teleport/lib/teleterm/v1/cluster.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ message ACL {
141141
ResourceAccess recorded_sessions = 13;
142142
// active_sessions defines access to active sessions.
143143
ResourceAccess active_sessions = 14;
144+
// review_requests defines the ability to review requests
145+
bool review_requests = 15;
144146
}
145147

146148
// ResourceAccess describes access verbs
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Teleport
3+
* Copyright (C) 2024 Gravitational, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
import { render, screen } from 'design/utils/testing';
20+
21+
import { makeEmptyAttempt, makeSuccessAttempt } from 'shared/hooks/useAsync';
22+
23+
import { requestRolePending } from '../../fixtures';
24+
25+
import { RequestView, RequestViewProps } from './RequestView';
26+
import { RequestFlags } from './types';
27+
28+
const sampleFlags: RequestFlags = {
29+
canAssume: false,
30+
isAssumed: false,
31+
canDelete: false,
32+
canReview: true,
33+
ownRequest: false,
34+
isPromoted: false,
35+
};
36+
37+
const props: RequestViewProps = {
38+
user: 'loggedInUsername',
39+
fetchRequestAttempt: makeSuccessAttempt(requestRolePending),
40+
submitReviewAttempt: makeEmptyAttempt(),
41+
getFlags: () => sampleFlags,
42+
confirmDelete: false,
43+
toggleConfirmDelete: () => null,
44+
submitReview: () => null,
45+
assumeRole: () => null,
46+
fetchSuggestedAccessListsAttempt: makeSuccessAttempt([]),
47+
assumeRoleAttempt: makeEmptyAttempt(),
48+
assumeAccessList: () => null,
49+
deleteRequestAttempt: makeEmptyAttempt(),
50+
deleteRequest: () => null,
51+
};
52+
53+
const reviewBoxText = `${props.user} - add a review`;
54+
55+
test('renders review box if user can review', async () => {
56+
render(<RequestView {...props} />);
57+
expect(screen.getByText(reviewBoxText)).toBeInTheDocument();
58+
});
59+
60+
test('does not render review box if user cannot review', async () => {
61+
render(
62+
<RequestView
63+
{...props}
64+
getFlags={() => ({
65+
...sampleFlags,
66+
canReview: false,
67+
})}
68+
/>
69+
);
70+
expect(screen.queryByText(reviewBoxText)).not.toBeInTheDocument();
71+
});

0 commit comments

Comments
 (0)