You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by as...@apache.org on 2026/08/27 22:01:53 UTC

(superset) 01/02: Merge branch 'alexandrusoare/feat/folders-testing-branch-v2' of https://github.com/apache/superset into alexandrusoare/feat/folders-testing-phase2

This is an automated email from the ASF dual-hosted git repository.

alexandrusoare pushed a commit to branch alexandrusoare/feat/folders-testing-phase2
in repository https://gitbox.apache.org/repos/asf/superset.git

commit da249207c3c13970b71c77ccca21ee952fe6c81b
Merge: f9fb95bfc12 063e9f93046
Author: alexandrusoare <al...@gmail.com>
AuthorDate: Fri Aug 28 01:01:05 2026 +0300

    Merge branch 'alexandrusoare/feat/folders-testing-branch-v2' of https://github.com/apache/superset into alexandrusoare/feat/folders-testing-phase2

 .../src/pages/AnalyticsList/CreateFolderModal.tsx  |  65 +++--
 .../{RenameFolderModal.tsx => EditFolderModal.tsx} |  77 ++++--
 .../pages/AnalyticsList/FolderPermissionsModal.tsx |  14 +-
 .../src/pages/AnalyticsList/RenameFolderModal.tsx  |  22 +-
 .../src/pages/AnalyticsList/TransferModal.tsx      |  11 +-
 .../src/pages/AnalyticsList/index.tsx              | 175 +++++++-----
 .../src/pages/AnalyticsList/styles.ts              |  12 -
 superset-frontend/src/pages/AnalyticsList/types.ts |   3 +-
 .../pages/components/FolderBreadcrumb.stories.tsx  |  83 ++++++
 .../src/pages/components/FolderBreadcrumb.test.tsx |  87 ++++++
 .../src/pages/components/FolderBreadcrumb.tsx      |  99 +++++++
 .../src/pages/components/FolderList.stories.tsx    | 298 +++++++++++++++++++++
 .../src/pages/components/FolderList.test.tsx       | 200 ++++++++++++++
 .../src/pages/components/FolderList.tsx            | 209 +++++++++++++++
 .../styles.ts => components/assetIcons.tsx}        |  30 +--
 .../styles.ts => components/index.ts}              |  31 +--
 superset-frontend/src/pages/components/types.ts    | 106 ++++++++
 superset/daos/folder.py                            | 146 +++++++---
 superset/folders/api.py                            | 170 +++++++++---
 superset/folders/hooks.py                          |  83 ++++--
 superset/security/manager.py                       |  29 ++
 21 files changed, 1665 insertions(+), 285 deletions(-)

diff --cc superset-frontend/src/pages/AnalyticsList/CreateFolderModal.tsx
index 9cf8c7f128d,4a59cd38077..90725fe4046
--- a/superset-frontend/src/pages/AnalyticsList/CreateFolderModal.tsx
+++ b/superset-frontend/src/pages/AnalyticsList/CreateFolderModal.tsx
@@@ -16,11 -16,14 +16,14 @@@
   * specific language governing permissions and limitations
   * under the License.
   */
- import { useCallback, useState } from 'react';
- import { SupersetClient } from '@superset-ui/core';
+ import { useCallback, useEffect, useState } from 'react';
+ import { SupersetClient, getClientErrorObject } from '@superset-ui/core';
  import { t } from '@apache-superset/core/translation';
 -import { Input } from '@superset-ui/core/components';
 +import { Checkbox, Input } from '@superset-ui/core/components';
  import { StandardModal } from 'src/components/Modal';
+ import { ModalFormField } from 'src/components/Modal/ModalFormField';
+ 
+ import { ModalContent } from './styles';
  
  interface CreateFolderModalProps {
    show: boolean;
@@@ -43,23 -44,33 +44,35 @@@ export default function CreateFolderMod
    addSuccessToast,
  }: CreateFolderModalProps) {
    const [name, setName] = useState('');
+   const [description, setDescription] = useState('');
+   const [nameError, setNameError] = useState('');
 +  const [isPrivate, setIsPrivate] = useState(false);
    const [saving, setSaving] = useState(false);
  
+   useEffect(() => {
+     if (show) {
+       setName('');
+       setDescription('');
+       setNameError('');
+     }
+   }, [show]);
+ 
    const handleSave = useCallback(async () => {
      if (!name.trim()) {
-       addDangerToast(t('Folder name is required'));
+       setNameError(t('Folder name is required'));
        return;
      }
+     setNameError('');
      setSaving(true);
      try {
        await SupersetClient.post({
          endpoint: '/api/v1/folders/',
          jsonPayload: {
            name: name.trim(),
+           description: description.trim() || null,
            folder_type: 'analytics',
            ...(parentFolderUuid ? { parent_uuid: parentFolderUuid } : {}),
 +          ...(isPrivate ? { is_private: true } : {}),
          },
        });
        addSuccessToast(t('Folder "%s" created', name.trim()));
@@@ -91,27 -104,27 +106,35 @@@
        saveLoading={saving}
      >
        <ModalContent>
-         <FormGroup>
-           <label htmlFor="create-folder-name">{t('Name')}</label>
+         <ModalFormField label={t('Name')} required error={nameError}>
            <Input
-             id="create-folder-name"
              placeholder={t('Folder name')}
              value={name}
-             onChange={e => setName(e.target.value)}
+             onChange={e => {
+               setName(e.target.value);
+               if (nameError) setNameError('');
+             }}
              onPressEnter={handleSave}
+             status={nameError ? 'error' : undefined}
              autoFocus
            />
-         </FormGroup>
+         </ModalFormField>
+         <ModalFormField label={t('Description')}>
+           <Input.TextArea
+             placeholder={t('Optional description')}
+             value={description}
+             onChange={e => setDescription(e.target.value)}
+             rows={3}
+           />
+         </ModalFormField>
 +        {!parentFolderUuid && (
-           <FormGroup>
-             <Checkbox
-               checked={isPrivate}
-               onChange={e => setIsPrivate(e.target.checked)}
-             >
-               {t('Private folder')}
-             </Checkbox>
-           </FormGroup>
++          <Checkbox
++            checked={isPrivate}
++            onChange={e => setIsPrivate(e.target.checked)}
++          >
++            {t('Private folder')}
++          </Checkbox>
 +        )}
        </ModalContent>
      </StandardModal>
    );
diff --cc superset-frontend/src/pages/AnalyticsList/TransferModal.tsx
index 48a055fb0b1,e7585f6649d..843643074f3
--- a/superset-frontend/src/pages/AnalyticsList/TransferModal.tsx
+++ b/superset-frontend/src/pages/AnalyticsList/TransferModal.tsx
@@@ -60,7 -60,7 +60,8 @@@ interface FolderOption 
    uuid: string;
    name: string;
    parent_uuid: string | null;
 +  is_private?: boolean;
+   user_permission?: 'editor' | 'viewer' | 'implicit' | null;
  }
  
  interface TransferModalProps {
diff --cc superset-frontend/src/pages/AnalyticsList/index.tsx
index e2e1898fb23,1c29c4b84a0..6519437dedb
--- a/superset-frontend/src/pages/AnalyticsList/index.tsx
+++ b/superset-frontend/src/pages/AnalyticsList/index.tsx
@@@ -51,14 -51,11 +51,12 @@@ import 
    ConfirmStatusChange,
    Dropdown,
    Flex,
+   InfoTooltip,
    Tooltip,
  } from '@superset-ui/core/components';
 +import { Alert } from '@apache-superset/core/components';
  import { Icons } from '@superset-ui/core/components/Icons';
- import {
-   FolderBreadcrumb,
-   type FolderBreadcrumbItem,
- } from '@superset-ui/core/components/Folders';
+ import { FolderBreadcrumb, type FolderBreadcrumbItem } from '../components';
  import SubMenu, { type SubMenuProps } from 'src/features/home/SubMenu';
  import withToasts from 'src/components/MessageToasts/withToasts';
  import {
@@@ -84,8 -81,7 +82,8 @@@ import type { ContentItem } from './typ
  interface Crumb {
    uuid: string | null;
    name: string;
-   user_permission?: 'editor' | 'viewer' | null;
+   user_permission?: 'editor' | 'viewer' | 'implicit' | null;
 +  is_only_me?: boolean;
  }
  
  interface SortColumn {
@@@ -453,8 -471,7 +473,8 @@@ function AnalyticsList(
              uuid: string;
              name: string;
              parent_uuid: string | null;
-             user_permission?: 'editor' | 'viewer' | null;
+             user_permission?: 'editor' | 'viewer' | 'implicit' | null;
 +            is_only_me?: boolean;
            };
            crumbs.unshift({
              uuid: folder.uuid,
@@@ -727,7 -746,7 +750,11 @@@
                });
              }
            }
-           if (canEditCurrentFolder && !original.is_only_me) {
 -          if (canEditCurrentFolder && original.user_permission !== 'implicit') {
++          if (
++            canEditCurrentFolder &&
++            !original.is_only_me &&
++            original.user_permission !== 'implicit'
++          ) {
              contextMenuItems.push({
                key: 'move',
                label: t('Move to…'),
@@@ -738,45 -757,31 +765,53 @@@
            const nameContent = (() => {
              if (original.type === 'folder') {
                return (
-                 <NameLink
-                   role="button"
-                   tabIndex={0}
-                   onClick={() => drillInto(original)}
-                   onKeyDown={e => {
-                     if (e.key === 'Enter') drillInto(original);
-                   }}
+                 <Tooltip
+                   title={
+                     original.user_permission === 'implicit'
+                       ? t('You have limited access to this folder')
+                       : undefined
+                   }
                  >
-                   {original.is_private ? (
-                     <Icons.LockOutlined
-                       iconSize="m"
-                       css={{ color: theme.colorTextSecondary }}
-                     />
-                   ) : (
-                     <Icons.FolderOutlined
-                       iconSize="m"
-                       css={{
-                         color: original.parent_uuid
-                           ? theme.colorWarning
-                           : theme.colorSuccess,
-                       }}
-                     />
-                   )}
-                   {highlightName(original.name)}
-                   {original.is_private && (
-                     <span
-                       css={{
-                         fontSize: theme.fontSizeXS,
-                         padding: `0 ${theme.sizeUnit}px`,
-                         borderRadius: theme.borderRadius,
-                         background: theme.colorBgLayout,
-                         color: theme.colorTextSecondary,
-                       }}
-                     >
-                       {t('Private')}
-                     </span>
-                   )}
-                   {pinIcon}
-                 </NameLink>
+                   <NameLink
+                     role="button"
+                     tabIndex={0}
+                     onClick={() => drillInto(original)}
+                     onKeyDown={e => {
+                       if (e.key === 'Enter') drillInto(original);
+                     }}
+                   >
 -                    <Icons.FolderOutlined
 -                      iconSize="m"
 -                      css={{
 -                        color: theme.colorSuccess,
 -                      }}
 -                    />
++                    {original.is_private ? (
++                      <Icons.LockOutlined
++                        iconSize="m"
++                        css={{ color: theme.colorTextSecondary }}
++                      />
++                    ) : (
++                      <Icons.FolderOutlined
++                        iconSize="m"
++                        css={{
++                          color: original.parent_uuid
++                            ? theme.colorWarning
++                            : theme.colorSuccess,
++                        }}
++                      />
++                    )}
+                     {highlightName(original.name)}
++                    {original.is_private && (
++                      <span
++                        css={{
++                          fontSize: theme.fontSizeXS,
++                          padding: `0 ${theme.sizeUnit}px`,
++                          borderRadius: theme.borderRadius,
++                          background: theme.colorBgLayout,
++                          color: theme.colorTextSecondary,
++                        }}
++                      >
++                        {t('Private')}
++                      </span>
++                    )}
+                     {pinIcon}
+                   </NameLink>
+                 </Tooltip>
                );
              }
              if (original.type === 'dashboard') {
@@@ -974,8 -985,8 +1015,8 @@@
                      </span>
                    </Tooltip>
                  )}
 -                {canEdit && (
 +                {canEdit && !original.is_only_me && (
-                   <Tooltip title={t('Rename folder')} placement="bottom">
+                   <Tooltip title={t('Edit folder')} placement="bottom">
                      <span
                        role="button"
                        tabIndex={0}
diff --cc superset-frontend/src/pages/AnalyticsList/types.ts
index b890354cb7a,a804b016327..fef4a72fe9e
--- a/superset-frontend/src/pages/AnalyticsList/types.ts
+++ b/superset-frontend/src/pages/AnalyticsList/types.ts
@@@ -43,10 -44,8 +44,10 @@@ export interface ContentItem 
    tags?: TagType[];
    asset_count?: number;
    children_count?: number;
-   user_permission?: 'editor' | 'viewer' | null;
+   user_permission?: 'editor' | 'viewer' | 'implicit' | null;
    parent_uuid?: string | null;
    inherits_permissions?: boolean;
 +  is_private?: boolean;
 +  is_only_me?: boolean;
    folder_path?: Array<{ uuid: string; name: string }>;
  }
diff --cc superset/daos/folder.py
index b633ff69288,49688037472..3303f2b7fff
--- a/superset/daos/folder.py
+++ b/superset/daos/folder.py
@@@ -200,20 -200,7 +200,20 @@@ class FolderDAO(BaseDAO[Folder])
                  fq = fq.where(Folder.changed_on >= modified_start)
              if modified_end:
                  fq = fq.where(Folder.changed_on <= modified_end)
 +            # Hide other users' private folders from everyone (including admins)
 +            if user_id:
 +                own_private_ids = (
 +                    select(folder_editors.c.folder_id).where(
 +                        folder_editors.c.user_id == user_id
 +                    )
 +                )
 +                fq = fq.where(
 +                    or_(
 +                        Folder.is_private.is_(False),
 +                        Folder.id.in_(own_private_ids),
 +                    )
 +                )
-             # Access filter: non-admins only see folders they are a member of
+             # Access filter: non-admins see member folders + implicit folders
              if not is_admin and user_id:
                  from superset.folders.utils import user_accessible_folder_ids
  
diff --cc superset/folders/api.py
index 60f866b87d4,b310ac4266f..2e1d7871b2c
--- a/superset/folders/api.py
+++ b/superset/folders/api.py
@@@ -149,12 -146,9 +154,10 @@@ def serialize_folder
          "changed_on_humanized": folder.changed_on_humanized,
          "created_by": _serialize_user(folder.created_by),
          "changed_by": _serialize_user(folder.changed_by),
-         "user_permission": _get_user_permission(folder),
+         "user_permission": _get_user_permission(folder, implicit_folder_ids),
          "inherits_permissions": _get_inherits_permissions(folder),
 +        "is_only_me": _is_only_me(folder),
-         "owners": [
-             _serialize_user(u) for u in (folder.editors or [])
-         ],
+         "owners": [_serialize_user(u) for u in (folder.editors or [])],
      }
  
  
@@@ -421,22 -427,50 +436,63 @@@ class FolderRestApi(BaseSupersetApi)
          folder_type = request.args.get("folder_type")
          folders = FolderDAO.get_folders(folder_type=folder_type)
  
-         # Filter folders by access — hide other users' private folders from everyone
-         if (user_id := get_user_id()):
-             folders = [
-                 f
-                 for f in folders
-                 if (
-                     not f.is_private
-                     or FolderPermissionDAO.user_has_folder_access(user_id, f.id)
+         # Non-admins see explicit member folders + implicit access folders
++        # Private folders are only visible to their own members
+         implicit_folder_ids: set[int] = set()
++        user_id = get_user_id()
+         if not security_manager.is_admin():
 -            user_id = get_user_id()
+             if user_id:
+                 # Batch query instead of N+1 per-folder checks
+                 all_folder_ids = [f.id for f in folders]
+                 editor_ids = (
+                     {
+                         r[0]
+                         for r in db.session.query(folder_editors.c.folder_id)
+                         .filter(
+                             folder_editors.c.user_id == user_id,
+                             folder_editors.c.folder_id.in_(all_folder_ids),
+                         )
+                         .all()
+                     }
+                     if all_folder_ids
+                     else set()
+                 )
+                 viewer_ids = (
+                     {
+                         r[0]
+                         for r in db.session.query(folder_viewers.c.folder_id)
+                         .filter(
+                             folder_viewers.c.user_id == user_id,
+                             folder_viewers.c.folder_id.in_(all_folder_ids),
+                         )
+                         .all()
+                     }
+                     if all_folder_ids
+                     else set()
                  )
-                 and (
-                     security_manager.is_admin()
-                     or FolderPermissionDAO.user_has_folder_access(user_id, f.id)
+                 member_ids = editor_ids | viewer_ids
+                 implicit_folder_ids = (
+                     FolderDAO.folders_with_accessible_assets(
+                         user_id, folder_type or "analytics"
+                     )
+                     - member_ids
                  )
+                 visible_ids = member_ids | implicit_folder_ids
+                 folders = [f for f in folders if f.id in visible_ids]
+             else:
+                 folders = []
++        # Hide other users' private folders (even for admins)
++        if user_id:
++            own_editor_ids = {
++                r[0]
++                for r in db.session.query(folder_editors.c.folder_id)
++                .filter(folder_editors.c.user_id == user_id)
++                .all()
++            }
++            folders = [
++                f for f in folders
++                if not f.is_private or f.id in own_editor_ids
 +            ]
-         else:
-             folders = []
  
          # Precompute counts to avoid N+1 queries
          folder_ids = [f.id for f in folders]
@@@ -514,14 -549,16 +571,22 @@@
                $ref: '#/components/responses/500'
          """
          folder_type = request.args.get("folder_type", DEFAULT_FOLDER_TYPE)
 +
 +        # Lazy-create the "Only Me" folder for eligible users
 +        user_id = get_user_id()
 +        if user_id and can_manage_folders(g.user):
 +            FolderDAO.get_or_create_only_me_folder(user_id)
 +
          parsed = _parse_rison_args(kwargs.get("rison", {}))
          rows, count = FolderDAO.get_contents(None, folder_type, **parsed)
+         # Compute implicit folder IDs for user_permission serialization
+         implicit_ids: set[int] = set()
+         if not security_manager.is_admin():
+             user_id = get_user_id()
+             if user_id:
+                 implicit_ids = FolderDAO.folders_with_accessible_assets(
+                     user_id, folder_type
+                 )
          result = (
              serialize_rows_with_paths(rows, None)
              if parsed.get("search")
diff --cc superset/folders/hooks.py
index 2c441840a49,e71a34c8b59..58e1573a551
--- a/superset/folders/hooks.py
+++ b/superset/folders/hooks.py
@@@ -53,52 -67,52 +67,67 @@@ def folder_raise_for_access_bypass(**kw
      if not user_id:
          return False
  
+     # Collect IDs from all sources
      dashboard = kwargs.get("dashboard")
      chart = kwargs.get("chart")
 +
 +    # Never bypass for assets in private folders unless the user is the owner
 +    if is_asset_in_private_folder(
 +        dashboard_id=dashboard.id if dashboard else None,
 +        chart_id=chart.id if chart else None,
 +    ):
 +        from superset.daos.folder_permissions import FolderPermissionDAO as _PDAO
 +
 +        has_access = _PDAO.user_has_folder_access_for_asset(
 +            user_id=user_id,
 +            dashboard_id=dashboard.id if dashboard else None,
 +            chart_id=chart.id if chart else None,
 +        )
 +        return has_access
 +
      query_context = kwargs.get("query_context")
-     viz = kwargs.get("viz")
-     datasource = kwargs.get("datasource")
+     form_data = (
+         query_context.form_data
+         if query_context
+         and hasattr(query_context, "form_data")
+         and query_context.form_data
+         else {}
+     )
  
-     if not datasource and query_context:
-         datasource = query_context.datasource
-     if not datasource and viz:
-         datasource = viz.datasource
+     from flask import request as flask_request
+ 
+     chart_ids = {
+         _safe_int(v)
+         for v in [
+             chart.id if chart else None,
+             form_data.get("slice_id"),
+             flask_request.args.get("slice_id"),
+         ]
+     } - {None}
+ 
+     dashboard_ids = {
+         _safe_int(v)
+         for v in [
+             dashboard.id if dashboard else None,
+             form_data.get("dashboardId"),
+             flask_request.args.get("dashboard_id"),
+         ]
+     } - {None}
+ 
+     # Check folder access for any collected ID
+     for chart_id in chart_ids:
+         if FolderPermissionDAO.user_has_folder_access_for_asset(
+             user_id=user_id,
+             chart_id=chart_id,
+         ):
+             return True
  
-     if FolderPermissionDAO.user_has_folder_access_for_asset(
-         user_id=user_id,
-         dashboard_id=dashboard.id if dashboard else None,
-         chart_id=chart.id if chart else None,
-         datasource_id=datasource.id if datasource else None,
-     ):
-         return True
- 
-     # Transitive access: datasource → chart → dashboard → folder.
-     # Grants access to datasources used by charts on dashboards in the
-     # user's folders, even if the chart is not directly in any folder.
-     if (
-         datasource
-         and current_app.config.get("FOLDER_DASHBOARD_TRANSITIVE_ACCESS")
-         and FolderPermissionDAO.user_has_transitive_dashboard_access(
+     for dashboard_id in dashboard_ids:
+         if FolderPermissionDAO.user_has_folder_access_for_asset(
              user_id=user_id,
-             datasource_id=datasource.id,
-         )
-     ):
-         return True
+             dashboard_id=dashboard_id,
+         ):
+             return True
  
      return False