zeroflag commented on code in PR #713:
URL: https://github.com/apache/knox/pull/713#discussion_r1064559699
##
knox-token-management-ui/token-management/app/token.management.component.ts:
##
@@ -42,6 +55,53 @@ export class TokenManagementComponent implements OnInit {
}
constructor(private tokenManagementService: TokenManagementService) {
+let isMatch: (record: KnoxToken, filter: String, impersonated:
boolean) => boolean = (record, filter, impersonated) => {
+ let normalizedFilter = filter.trim().toLocaleLowerCase();
+ let matchesTokenId =
record.tokenId.toLocaleLowerCase().includes(normalizedFilter);
+ let matchesComment = record.metadata.comment &&
record.metadata.comment.toLocaleLowerCase().includes(normalizedFilter);
+ let matchesCustomMetadata = false;
+ if (record.metadata.customMetadataMap) {
+for (let entry of
Array.from(Object.entries(record.metadata.customMetadataMap))) {
+ if (entry[0].toLocaleLowerCase().includes(normalizedFilter)
|| entry[1].toLocaleLowerCase().includes(normalizedFilter)) {
+ matchesCustomMetadata = true;
+ break;
+ }
+}
+ } else {
+matchesCustomMetadata = true; // nothing to match
+ }
+
+ let matchesImpersonatedUserName = false; // doAs username should be
checked only if impersonation is enabled
+ if (impersonated) {
+ matchesImpersonatedUserName =
record.metadata.userName.toLocaleLowerCase().includes(normalizedFilter);
+ }
+
+ return matchesTokenId || matchesComment || matchesCustomMetadata ||
matchesImpersonatedUserName;
+};
+
+this.knoxTokens.filterPredicate = function (record, filter) {
+ return isMatch(record, filter, false);
+};
+
+this.doAsKnoxTokens.filterPredicate = function (record, filter) {
+ return isMatch(record, filter, true);
+};
+
+this.knoxTokens.sortingDataAccessor = (item, property) => {
+ switch(property) {
+ case 'metadata.comment': return item.metadata.comment;
+ default: return item[property];
+ }
+};
+
+this.doAsKnoxTokens.sortingDataAccessor = (item, property) => {
+ let normalizedPropertyName = property.replace('impersonation.',
'');
Review Comment:
nit: wrong indentation
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscr...@knox.apache.org
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org