You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@knox.apache.org by GitBox <gi...@apache.org> on 2023/01/09 12:27:07 UTC

[GitHub] [knox] smolnar82 commented on a diff in pull request #713: KNOX-2859 - Token Management UI improvements

smolnar82 commented on code in PR #713:
URL: https://github.com/apache/knox/pull/713#discussion_r1064586511


##########
knox-token-management-ui/token-management/app/token.management.component.ts:
##########
@@ -57,13 +117,29 @@ export class TokenManagementComponent implements OnInit {
     }
 
     fetchAllKnoxTokens(): void {
-        this.fetchKnoxTokens(true);
         this.fetchKnoxTokens(false);
+        this.fetchKnoxTokens(true);
     }
 
     fetchKnoxTokens(impersonated: boolean): void {
         this.tokenManagementService.getKnoxTokens(this.userName, impersonated)
-            .then(tokens => impersonated ? this.doAsKnoxTokens = tokens : this.knoxTokens = tokens);
+            .then(tokens => this.populateTokens(impersonated, tokens));
+    }
+
+    populateTokens(impersonated: boolean, tokens: KnoxToken[]) {
+	    if (impersonated) {

Review Comment:
   Fixed.



##########
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:
   Fixed.



-- 
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-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org