[ 
https://issues.apache.org/jira/browse/KNOX-2859?focusedWorklogId=837918&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-837918
 ]

ASF GitHub Bot logged work on KNOX-2859:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 09/Jan/23 12:27
            Start Date: 09/Jan/23 12:27
    Worklog Time Spent: 10m 
      Work Description: 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.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 837918)
    Time Spent: 40m  (was: 0.5h)

> Search/filter tokens on Token Management page
> ---------------------------------------------
>
>                 Key: KNOX-2859
>                 URL: https://issues.apache.org/jira/browse/KNOX-2859
>             Project: Apache Knox
>          Issue Type: Improvement
>          Components: TokenManagementUI
>    Affects Versions: 2.0.0
>            Reporter: Sandor Molnar
>            Assignee: Sandor Molnar
>            Priority: Major
>             Fix For: 2.1.0
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> In 2.0.0, the Knox team introduced a new UI where logged-in users can see 
> their own tokens as well as tokens generated by them on behalf of other users 
> (impersonated tokens).
> These tables show different useful information, such as custom metadata, in 
> tables where pagination is used. However, there is no way that end-users can 
> filter/search for specific tokens based on their needs. In the case of a huge 
> token list (e.g. when the token limit is disabled), it may be very hard for 
> them to find the token they are interested in (e.g. they want to 
> revoke/disable one).
> The scope of this task is to find another Angular DataTable implementation 
> where these features are supported and integrate them on the token management 
> page (we may want to do the same on tables on the Admin UI).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to