dosubot[bot] commented on issue #29879: URL: https://github.com/apache/superset/issues/29879#issuecomment-2272986489
<!-- Answer --> To ensure that a Superset dashboard is only accessible through a custom new URL slug and that the old default URL is no longer accessible, you can update the URL slug in the dashboard properties. Here is how you can do it: 1. Open the dashboard properties modal. 2. Update the "URL slug" field with the new custom slug. 3. Save the changes. Here is the relevant code snippet from the `PropertiesModal` component that shows how to update the URL slug: ```tsx <StyledFormItem label={t('URL slug')} name="slug"> <Input type="text" disabled={isLoading} /> </StyledFormItem> <p className="help-block"> {t('A readable URL for your dashboard')} </p> ``` By updating the "URL slug" field, the dashboard will be accessible through the new custom URL, and the old default URL will no longer be valid. Additionally, the `Dashboard` model in `superset/models/dashboard.py` ensures that the dashboard URL is generated based on the slug if it exists, otherwise it defaults to the dashboard ID: ```py class Dashboard(AuditMixinNullable, ImportExportMixin, Model): ... @property def url(self) -> str: return f"/superset/dashboard/{self.slug or self.id}/" @staticmethod def get_url(id_: int, slug: str | None = None) -> str: return f"/superset/dashboard/{slug or id_}/" ... ``` This ensures that once the slug is updated, the old URL (based on the dashboard ID) will no longer be valid. Furthermore, the `Dashboard` view in `superset/views/dashboard/views.py` handles the routing and ensures that the dashboard can be accessed via the new slug: ```py class Dashboard(BaseSupersetView): ... @expose("/<dashboard_id_or_slug>/embedded") @event_logger.log_this_with_extra_payload def embedded( self, dashboard_id_or_slug: str, add_extra_log_payload: Callable[..., None] = lambda **kwargs: None, ) -> FlaskResponse: ... add_extra_log_payload( dashboard_id=dashboard_id_or_slug, dashboard_version="v2", ) ... return self.render_template( "superset/spa.html", entry="embedded", bootstrap_data=json.dumps( bootstrap_data, default=json.pessimistic_json_iso_dttm_ser ), ) ``` This ensures that the dashboard is accessible via the new slug and the old URL is no longer valid <sup>[[1]](https://github.com/apache/superset/blob/master/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/superset/models/dashboard.py)</sup><sup>[[3]](https://github.com/apache/superset/blob/master/superset/views/dashboard/views.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* -- 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: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org