-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 access request searching logic #43159
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { AccessRequest, Resource } from 'shared/services/accessRequests'; | ||
|
||
// TODO | ||
// places that use this need to be replaced with server-side filtering like | ||
// done in RequestList.tsx: | ||
// https://github.com/gravitational/teleport.e/blob/a776b3e65e6e8e11ca6938025e63fc3676238fb2/web/teleport/src/Workflow/ReviewRequests/RequestList/RequestList.tsx#L72 | ||
export function requestMatcher( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to rewrite it to make it more safe, but I ultimately couldn't find a good solution. It'd have been trivial if export function requestMatcher(
accessRequest: AccessRequest,
searchValue: string,
propName: keyof AccessRequest
) {
if (propName === 'roles') {
return accessRequest[propName].some(role =>
role.toUpperCase().includes(searchValue)
);
}
if (propName === 'resources') {
return accessRequest[propName].some(r =>
Object.values(r.id)
.concat(Object.values(r.details.hostname || {}))
.concat(Object.values(r.details.friendlyName || {}))
.some(v => v.toUpperCase().includes(searchValue))
);
}
} |
||
targetValue: any, | ||
searchValue: string, | ||
propName: keyof AccessRequest | ||
) { | ||
if (propName === 'roles') { | ||
return targetValue.some((role: string) => | ||
role.toUpperCase().includes(searchValue) | ||
); | ||
} | ||
|
||
if (propName === 'resources') { | ||
return targetValue.some((r: Resource) => | ||
Object.values(r.id) | ||
.concat(Object.values(r.details.hostname || {})) | ||
.concat(Object.values(r.details.friendlyName || {})) | ||
.some(v => v.toUpperCase().includes(searchValue)) | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ import { | |
BlockedByStartTimeButton, | ||
ButtonPromotedInfo, | ||
} from 'shared/components/AccessRequests/Shared/Shared'; | ||
import { requestMatcher } from 'shared/components/AccessRequests/NewRequest/matcher'; | ||
|
||
export function RequestList({ | ||
attempt, | ||
|
@@ -142,24 +143,6 @@ export function RequestList({ | |
); | ||
} | ||
|
||
function requestMatcher( | ||
targetValue: any, | ||
searchValue: string, | ||
propName: keyof AccessRequest & string | ||
) { | ||
if (propName === 'roles') { | ||
return targetValue.some((role: string) => | ||
role.toUpperCase().includes(searchValue) | ||
); | ||
} | ||
|
||
if (propName === 'resources') { | ||
return targetValue.some((r: any) => | ||
Object.keys(r).some(k => r[k].toUpperCase().includes(searchValue)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was the issue |
||
); | ||
} | ||
} | ||
|
||
const renderActionCell = ( | ||
request: AccessRequest, | ||
flags: RequestFlags, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used only in teleterm, so I don't think we should keep this function in
shared
- we can fix the one we have inDocumentAccessRequests/RequestList/RequestList.tsx
.I would also add TODO about replacing it with server-side filtering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added TODO comment (keeping file in shared because of comment)