You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by va...@apache.org on 2025/05/22 03:44:43 UTC

(superset) branch fix/all-entities/make-button-visibility-dynamic created (now 394e86a773)

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

vavila pushed a change to branch fix/all-entities/make-button-visibility-dynamic
in repository https://gitbox.apache.org/repos/asf/superset.git


      at 394e86a773 fix(AllEntities): Display action buttons according to the user permissions

This branch includes the following new commits:

     new 394e86a773 fix(AllEntities): Display action buttons according to the user permissions

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(superset) 01/01: fix(AllEntities): Display action buttons according to the user permissions

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vavila pushed a commit to branch fix/all-entities/make-button-visibility-dynamic
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 394e86a77329e8402d93a2da3c77762dad24328a
Author: Vitor Avila <vi...@preset.io>
AuthorDate: Thu May 22 00:44:30 2025 -0300

    fix(AllEntities): Display action buttons according to the user permissions
---
 .../features/allEntities/AllEntitiesTable.test.tsx | 22 ++++++++++++++++++-
 .../src/features/allEntities/AllEntitiesTable.tsx  | 20 +++++++++++------
 superset-frontend/src/pages/AllEntities/index.tsx  | 25 +++++++++++++++-------
 superset/views/all_entities.py                     |  3 ++-
 4 files changed, 53 insertions(+), 17 deletions(-)

diff --git a/superset-frontend/src/features/allEntities/AllEntitiesTable.test.tsx b/superset-frontend/src/features/allEntities/AllEntitiesTable.test.tsx
index 7143c90887..6883ee7045 100644
--- a/superset-frontend/src/features/allEntities/AllEntitiesTable.test.tsx
+++ b/superset-frontend/src/features/allEntities/AllEntitiesTable.test.tsx
@@ -91,12 +91,13 @@ describe('AllEntitiesTable', () => {
     jest.restoreAllMocks();
   });
 
-  it('renders when empty', () => {
+  it('renders when empty with button to tag if user has perm', () => {
     render(
       <AllEntitiesTable
         search=""
         setShowTagModal={mockSetShowTagModal}
         objects={mockObjects}
+        canEditTag
       />,
       { useRouter: true },
     );
@@ -108,12 +109,31 @@ describe('AllEntitiesTable', () => {
     expect(screen.getByText('Add tag to entities')).toBeInTheDocument();
   });
 
+  it('renders when empty without button to tag if user does not have perm', () => {
+    render(
+      <AllEntitiesTable
+        search=""
+        setShowTagModal={mockSetShowTagModal}
+        objects={mockObjects}
+        canEditTag={false}
+      />,
+      { useRouter: true },
+    );
+
+    expect(
+      screen.getByText('No entities have this tag currently assigned'),
+    ).toBeInTheDocument();
+
+    expect(screen.queryByText('Add tag to entities')).not.toBeInTheDocument();
+  });
+
   it('renders the correct tags for each object type, excluding the current tag', () => {
     render(
       <AllEntitiesTable
         search=""
         setShowTagModal={mockSetShowTagModal}
         objects={mockObjectsWithTags}
+        canEditTag
       />,
       { useRouter: true },
     );
diff --git a/superset-frontend/src/features/allEntities/AllEntitiesTable.tsx b/superset-frontend/src/features/allEntities/AllEntitiesTable.tsx
index 71088d3f80..2e45f838b4 100644
--- a/superset-frontend/src/features/allEntities/AllEntitiesTable.tsx
+++ b/superset-frontend/src/features/allEntities/AllEntitiesTable.tsx
@@ -53,12 +53,14 @@ interface AllEntitiesTableProps {
   search?: string;
   setShowTagModal: (show: boolean) => void;
   objects: TaggedObjects;
+  canEditTag: boolean;
 }
 
 export default function AllEntitiesTable({
   search = '',
   setShowTagModal,
   objects,
+  canEditTag,
 }: AllEntitiesTableProps) {
   type objectType = 'dashboard' | 'chart' | 'query';
 
@@ -142,13 +144,17 @@ export default function AllEntitiesTable({
           {renderTable('query')}
         </>
       ) : (
-        <EmptyState
-          image="dashboard.svg"
-          size="large"
-          title={t('No entities have this tag currently assigned')}
-          buttonAction={() => setShowTagModal(true)}
-          buttonText={t('Add tag to entities')}
-        />
+        <>
+          <EmptyState
+            image="dashboard.svg"
+            size="large"
+            title={t('No entities have this tag currently assigned')}
+            {...(canEditTag && {
+              buttonAction: () => setShowTagModal(true),
+              buttonText: t('Add tag to entities'),
+            })}
+          />
+        </>
       )}
     </AllEntitiesTableContainer>
   );
diff --git a/superset-frontend/src/pages/AllEntities/index.tsx b/superset-frontend/src/pages/AllEntities/index.tsx
index 77391746ee..2fa63c0472 100644
--- a/superset-frontend/src/pages/AllEntities/index.tsx
+++ b/superset-frontend/src/pages/AllEntities/index.tsx
@@ -35,6 +35,8 @@ import { fetchObjectsByTagIds, fetchSingleTag } from 'src/features/tags/tags';
 import Loading from 'src/components/Loading';
 import getOwnerName from 'src/utils/getOwnerName';
 import { TaggedObject, TaggedObjects } from 'src/types/TaggedObject';
+import { store } from 'src/views/store';
+import { findPermission } from 'src/utils/findPermission';
 
 const additionalItemsStyles = (theme: SupersetTheme) => css`
   display: flex;
@@ -100,6 +102,10 @@ function AllEntities() {
     query: [],
   });
 
+  const state = store?.getState();
+  const user = state?.user;
+  const canEditTag = findPermission('can_write', 'Tag', user?.roles);
+
   const editableTitleProps = {
     title: tag?.name || '',
     placeholder: 'testing',
@@ -211,14 +217,16 @@ function AllEntities() {
           }
           rightPanelAdditionalItems={
             <>
-              <Button
-                data-test="bulk-select-action"
-                buttonStyle="secondary"
-                onClick={() => setShowTagModal(true)}
-                showMarginRight={false}
-              >
-                {t('Edit Tag')}{' '}
-              </Button>
+              {canEditTag && (
+                <Button
+                  data-test="bulk-select-action"
+                  buttonStyle="secondary"
+                  onClick={() => setShowTagModal(true)}
+                  showMarginRight={false}
+                >
+                  {t('Edit Tag')}{' '}
+                </Button>
+              )}
             </>
           }
           menuDropdownProps={{
@@ -232,6 +240,7 @@ function AllEntities() {
           search={tag?.name || ''}
           setShowTagModal={setShowTagModal}
           objects={objects}
+          canEditTag={canEditTag}
         />
       </div>
     </AllEntitiesContainer>
diff --git a/superset/views/all_entities.py b/superset/views/all_entities.py
index 5ca7e41e1d..d78c638589 100644
--- a/superset/views/all_entities.py
+++ b/superset/views/all_entities.py
@@ -22,6 +22,7 @@ from flask_appbuilder.models.sqla.interface import SQLAInterface
 from flask_appbuilder.security.decorators import has_access
 
 from superset import is_feature_enabled
+from superset.constants import RouteMethod
 from superset.superset_typing import FlaskResponse
 from superset.tags.models import Tag
 from superset.views.base import SupersetModelView
@@ -33,7 +34,7 @@ class TaggedObjectsModelView(SupersetModelView):
     route_base = "/superset/all_entities"
     datamodel = SQLAInterface(Tag)
     class_permission_name = "Tags"
-    include_route_methods = {"list"}
+    include_route_methods = {RouteMethod.LIST}
 
     @has_access
     @expose("/")