apache / superset

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

Disable the download as image feature. #30513

Closed praveer38 closed 1 day ago

praveer38 commented 1 day ago

Bug description

How can i disable the download as image feature for charts and dashboards?

Screenshots/recordings

No response

Superset version

4.0.2

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

dosubot[bot] commented 1 day ago

To disable the "Download as image" feature for charts and dashboards in Superset version 4.0.2, you need to modify the code where the menu items are defined. Specifically, locate the following part of the code and remove or comment out the section related to the "DOWNLOAD_AS_IMAGE" menu key:

<Menu.Item
  key={MENU_KEYS.DOWNLOAD_AS_IMAGE}
  icon={<Icons.FileImageOutlined css={iconReset} />}
>
  {t('Download as image')}
</Menu.Item>

This change will remove the "Download as image" option from the menu, effectively disabling the feature [1].

To continue talking to Dosu, mention @dosu.

praveer38 commented 1 day ago

@dosu is there a way to disable it from the superset_config.py?

dosubot[bot] commented 1 day ago

There isn't a specific configuration option in superset_config.py to disable the "Download as image" feature directly. The feature is controlled through the frontend code, and there is no feature flag or configuration setting in superset_config.py that can be used to disable it [1].

To continue talking to Dosu, mention @dosu.

praveer38 commented 1 day ago

@dosu please tell me a way to disable it if I'm running superset as a docker container?

dosubot[bot] commented 1 day ago

To disable the "Download as image" feature while running Superset as a Docker container, you will need to modify the frontend code within the Docker environment. Here's how you can do it:

  1. Access the Frontend Code:

    • Set the environment variable BUILD_SUPERSET_FRONTEND_IN_DOCKER to true to build the Superset frontend in development mode inside the Docker container. This allows you to access and modify the frontend code.
  2. Modify the Code:

    • Locate the part of the code where the "Download as image" menu item is defined and remove or comment out the relevant section. For example, in the file where the menu items are defined, you would remove or comment out the section related to the "DOWNLOAD_AS_IMAGE" menu key.
  3. Rebuild the Frontend:

    • After making the changes, rebuild the frontend by running the following commands inside the Docker container:
      npm install
      npm run dev
  4. Restart the Docker Container:

    • Restart the Docker container to apply the changes.

By following these steps, you can disable the "Download as image" feature in a Dockerized Superset environment [1].

To continue talking to Dosu, mention @dosu.

praveer38 commented 1 day ago

FROM apache/superset:4.0.2

USER root

RUN apt-get update RUN apt-get install -y build-essential g++ nano RUN mkdir /app/custom_scripts_rc COPY public_user_perms.py /app/custom_scripts_rc/public_user_perms.py RUN pip install mysqlclient Authlib pymssql apache-superset[cors] Flask-OAuthlib psycopg2 pystan==2.19.1.1 prophet

COPY ./docker-init.sh /superset-init.sh COPY docker-bootstrap.sh /app/docker/docker-bootstrap.sh

COPY zdnlk0yk.png /app/superset/static/assets/images/superset.png COPY zdnlk0yk.png /app/superset/static/assets/images/superset-logo-horiz.png

COPY superset_config.py /app/pythonpath/superset_config.py COPY superset_config.py /app/

COPY utils.py /app/superset/connectors/sqla/utils.py COPY models.py /app/superset/connectors/sqla/models.py

ENV SUPERSET_CONFIG_PATH /app/superset_config.py ENV PYTHONPATH="/app/pythonpath" ENV BUILD_SUPERSET_FRONTEND_IN_DOCKER=True

USER superset

CMD ["sh", "-c", "python /app/custom_scripts_rc/public_user_perms.py & /superset-init.sh"] These are the contents of my dockerfile. Please help with the changes. @dosu

dosubot[bot] commented 1 day ago

To disable the "Download as image" feature in your Dockerized Superset setup, you need to modify the frontend code and rebuild it within the Docker container. Here’s how you can adjust your Dockerfile and process:

  1. Ensure Frontend Code is Accessible:

    • You already have BUILD_SUPERSET_FRONTEND_IN_DOCKER=True, which is correct for building the frontend inside the Docker container.
  2. Modify the Frontend Code:

    • You need to access the frontend code within the Docker container. You can do this by running a shell in the container and navigating to the frontend directory:
      docker exec -it <container_id> /bin/bash
      cd /app/superset-frontend
  3. Edit the Code:

    • Locate the file where the "Download as image" feature is implemented, such as superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadAsImage.tsx, and comment out or remove the relevant code that adds this feature to the menu.
  4. Rebuild the Frontend:

    • After making the changes, rebuild the frontend:
      npm install
      npm run dev
  5. Restart the Container:

    • Once the frontend is rebuilt, restart your Docker container to apply the changes.

Your Dockerfile doesn't need changes for this specific task, as it already sets up the environment to build the frontend inside the container. Just ensure you follow the steps above to modify and rebuild the frontend code.

To continue talking to Dosu, mention @dosu.

praveer38 commented 1 day ago

@dosu but the container only has package.json under superset-frontend

dosubot[bot] commented 1 day ago

To modify the frontend code in your Dockerized Superset setup, you need to ensure that the full source code is available in the container. If only package.json is present, it suggests that the source files might not be included in the image or volume.

Here's how you can proceed:

  1. Ensure Source Code Availability:

    • Make sure that the superset-frontend directory with all its source files is available in the Docker container. You might need to mount the local superset-frontend directory into the container using Docker volumes. Update your docker-compose.yml or Docker run command to include a volume mount for the frontend code.
  2. Modify the Frontend Code:

    • Once the source code is accessible, navigate to the superset-frontend directory inside the container:
      docker exec -it <container_id> /bin/bash
      cd /app/superset-frontend
  3. Edit the Code:

    • Locate and edit the file src/dashboard/components/menu/DownloadMenuItems/DownloadAsImage.tsx to comment out or remove the code related to the "Download as image" feature.
  4. Rebuild the Frontend:

    • After editing, rebuild the frontend:
      npm install
      npm run dev
  5. Restart the Container:

    • Restart the Docker container to apply the changes.

If the source code is not included in the Docker image, you may need to build the image locally with the source code included or adjust your Docker setup to ensure the source files are available for modification.

To continue talking to Dosu, mention @dosu.

sfirke commented 1 day ago

Sorry Dosu always wants people to edit the codebase. There is a permission named "can csv on Superset", try removing that from the role(s) that you want to modify in this way.

sfirke commented 1 day ago

Also this should not be a bug report as it is a question. Please post questions on Slack and/or GitHub Discussions. I found the answer searching Slack. I see you have opened a few bug reports today - please be judicious as the Superset project struggles when it comes to triaging bug reports. Valid, complete bug reports are welcome but it is a help if you keep them to a minimum.

praveer38 commented 1 day ago

I understand. Thanks for the pointer, although we do want to export the data as csv as well as excel but we want to eliminate the option to export it as an image. But I'll post this as a discussion on GitHub. Thanks!