apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
61.51k stars 13.42k forks source link

🐛 RLS form not showing all datasets available #28638

Open hanslemm opened 3 months ago

hanslemm commented 3 months ago

Bug description

When trying to create a new RLS rule, in the rule pop-up (check image for reference), there is the drop-down field for datasets. If you start filling this pop-up through the dataset field (which would be natural since this the obligatory field), in my version of Superset (and since 3.0.0 tbh I already detected this), not all datasets registered in Superset are available in the drop-down menu. Yet, if you rather start filling this pop-up through the role drop-down, then all the datasets will be visible.

image

How to reproduce the bug

Preconditions: have RBAC enabled in your Superset config.

  1. Create a new dataset.
  2. Go to RLS and press the + button to create a new rule.
  3. In the new pop-up, there will be the dataset drop-down. Click it, and the new dataset will be missing. 3.1. If you set the role drop-down first, then all datasets will be available to the dataset drop-down.

Screenshots/recordings

No response

Superset version

4.0.1

Python version

3.10

Node version

I don't know

Browser

Chrome

Additional context

No response

Checklist

dosubot[bot] commented 3 months ago

To resolve the issue where the dataset drop-down in the RLS rule creation pop-up in Superset does not show all available datasets unless a role is selected first, ensure that the AsyncSelect component for datasets is properly configured to load options independently of the role selection.

Check the loadTableOptions function to ensure it correctly fetches the dataset options:

const loadTableOptions = useMemo(
  () =>
    (input = '', page: number, pageSize: number) => {
      const query = rison.encode({
        filter: input,
        page,
        page_size: pageSize,
      });
      return SupersetClient.get({
        endpoint: `/api/v1/rowlevelsecurity/related/tables?q=${query}`,
      }).then(response => {
        const list = response.json.result.map(
          (item: { value: number; text: string }) => ({
            label: item.text,
            value: item.value,
          }),
        );
        return { data: list, totalCount: response.json.count };
      });
    },
  [],
);

<AsyncSelect
  ariaLabel={t('Tables')}
  mode="multiple"
  onChange={onTablesChange}
  value={(currentRule?.tables as SelectValue[]) || []}
  options={loadTableOptions}
/>

Ensure that loadTableOptions is fetching and returning the dataset options independently of the role selection.

Additionally, verify that the RowLevelSecurityModal component is correctly set up to fetch related tables and roles independently. The endpoints for fetching related tables and roles should be correctly implemented and tested:

const getRelatedTablesEndpoint =
  'glob:*/api/v1/rowlevelsecurity/related/tables?q*';
const getRelatedRolesEndpoint =
  'glob:*/api/v1/rowlevelsecurity/related/roles?q*';

fetchMock.get(getRelatedTablesEndpoint, mockGetTablesResult);
fetchMock.get(getRelatedRolesEndpoint, mockGetRolesResult);

User permissions or RBAC configurations might also influence the visibility of datasets. Ensure that the API endpoints respect the user's permissions and roles.

Recent changes in the superset-frontend repository might also affect the behavior of the dataset drop-down. Relevant pull requests include:

  1. #20449 - Fix: RLS new db migration downgrade fails on SQLite.
  2. #20432 - Feat: add name, description, and non-null tables to RLS.
  3. #22325 - Feat(RLS): RESTful APIs and react view for RLS.
  4. #22818 - Fix: revert RESTful APIs and react view for RLS.
  5. #25400 - Fix: Info Tooltip + Button Alignment on RLS Modal.

These updates might impact the dataset drop-down behavior in the RLS rule creation pop-up.

#### Details **Sources** - [superset-frontend/src/features/rls/RowLevelSecurityModal.tsx](https://github.com/apache/superset/blob/master/superset-frontend/src/features/rls/RowLevelSecurityModal.tsx) - [superset-frontend/src/features/rls/RowLevelSecurityModal.test.tsx](https://github.com/apache/superset/blob/master/superset-frontend/src/features/rls/RowLevelSecurityModal.test.tsx) - [superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/DatasetSelect.tsx](https://github.com/apache/superset/blob/master/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/DatasetSelect.tsx) - [superset-frontend/src/components/Select/AsyncSelect.tsx](https://github.com/apache/superset/blob/master/superset-frontend/src/components/Select/AsyncSelect.tsx) - [superset-frontend/src/components/Select/AsyncSelect.test.tsx](https://github.com/apache/superset/blob/master/superset-frontend/src/components/Select/AsyncSelect.test.tsx) - [superset-frontend/src/components/Select/AsyncSelect.stories.tsx](https://github.com/apache/superset/blob/master/superset-frontend/src/components/Select/AsyncSelect.stories.tsx) - [superset/datasets/api.py](https://github.com/apache/superset/blob/master/superset/datasets/api.py) - [superset/commands/dataset/warm_up_cache.py](https://github.com/apache/superset/blob/master/superset/commands/dataset/warm_up_cache.py) - [superset/security/manager.py](https://github.com/apache/superset/blob/master/superset/security/manager.py) - [superset/commands/security/create.py](https://github.com/apache/superset/blob/master/superset/commands/security/create.py) - [superset/row_level_security/api.py](https://github.com/apache/superset/blob/master/superset/row_level_security/api.py) - [superset-frontend/src/utils/cachedSupersetGet.ts](https://github.com/apache/superset/blob/master/superset-frontend/src/utils/cachedSupersetGet.ts) - [tests/integration_tests/cachekeys/api_tests.py](https://github.com/apache/superset/blob/master/tests/integration_tests/cachekeys/api_tests.py) - [superset/cachekeys/api.py](https://github.com/apache/superset/blob/master/superset/cachekeys/api.py) - [superset-frontend/packages/superset-ui-core/src/connection/callApi/callApi.ts](https://github.com/apache/superset/blob/master/superset-frontend/packages/superset-ui-core/src/connection/callApi/callApi.ts) - [CHANGELOG/2.1.0.md](https://github.com/apache/superset/blob/master/CHANGELOG/2.1.0.md) - [CHANGELOG/3.0.1.md](https://github.com/apache/superset/blob/master/CHANGELOG/3.0.1.md)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.