aminghadersohi commented on code in PR #45375:
URL: https://github.com/apache/superset/pull/45375#discussion_r4333632100


##########
superset-frontend/src/features/roles/utils.ts:
##########
@@ -58,7 +58,11 @@ export const updateRoleName = async (roleId: number, name: 
string) =>
 export const formatPermissionLabel = (
   permissionName: string,
   viewMenuName: string,
-) => `${permissionName.replace(/_/g, ' ')} ${viewMenuName.replace(/_/g, ' ')}`;
+) =>
+  `${permissionName.replace(/_/g, ' ')} ${viewMenuName.replace(/_/g, ' 
')}`.replace(
+    /%2e/gi,
+    '.',
+  );

Review Comment:
   The third query embeds `%2E` directly in `?q=`, which Flask decodes back to 
`.`, so `demo.metrics` still misses `[database].[demo%2Emetrics]`. The query 
needs transport escaping; the mock must also decode URL parameters before 
parsing rison.



##########
superset-frontend/src/features/roles/utils.test.ts:
##########
@@ -31,6 +32,65 @@ afterEach(() => {
   clearPermissionSearchCache();
 });
 
+test('formatPermissionLabel displays encoded dots without decoding other 
characters', () => {
+  expect(
+    formatPermissionLabel(
+      'catalog_access',
+      '[database].[demo%2Emetrics%2emain%2Fbranch]',
+    ),
+  ).toBe('catalog access [database].[demo.metrics.main%2Fbranch]');
+});
+
+test('fetchPermissionOptions displays encoded dots and preserves permission 
IDs', async () => {
+  getMock.mockResolvedValue({
+    json: {
+      count: 1,
+      result: [
+        {
+          id: 42,
+          permission: { name: 'catalog_access' },
+          view_menu: { name: '[database].[demo%2Emetrics]' },
+        },
+      ],
+    },
+  } as any);
+
+  expect(await fetchPermissionOptions('', 0, 100, jest.fn())).toEqual({
+    data: [{ value: 42, label: 'catalog access [database].[demo.metrics]' }],
+    totalCount: 1,
+  });
+});
+
+test('fetchPermissionOptions finds encoded names using their displayed dots', 
async () => {
+  getMock.mockImplementation(({ endpoint }: { endpoint: string }) => {
+    const query = rison.decode(endpoint.split('?q=')[1]) as {
+      filters: { value: string }[];
+    };

Review Comment:
   This mock skips URL decoding, so it matches `demo%2Emetrics` even though 
Flask receives `demo.metrics` and returns no permission. Parse `q` as a URL 
parameter before decoding rison.
   
   ```suggestion
       const query = rison.decode(
         new URL(endpoint, 'http://localhost').searchParams.get('q') ?? '',
       ) as {
         filters: { value: string }[];
       };
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to