docstr: Sets up a dashboard to be embeddable.
  Upsert is used to preserve the embedded_dashboard uuid across updates.
docstr_tok: ["Sets","up","a","dashboard","to","be","embeddable",".","Upsert","is","used","to","preserve","the","embedded_dashboard","uuid","across","updates","."]
code: def upsert(
      dashboard: Dashboard, allowed_domains: list[str]
  ) -> EmbeddedDashboard:
      """
      Sets up a dashboard to be embeddable.
      Upsert is used to preserve the embedded_dashboard uuid across updates.
      """
      embedded: EmbeddedDashboard = (
          dashboard.embedded[0]
          if dashboard.embedded
          else EmbeddedDashboard()
      )
      embedded.allow_domain_list = ",".join(allowed_domains)
      dashboard.embedded = [embedded]
      db.session.commit()
      return embedded
  
imports: from __future__ import annotations
  import json
  import logging
  from datetime import datetime
  from typing import Any
  from flask import g
  from flask_appbuilder.models.sqla.interface import SQLAInterface
  from superset import is_feature_enabled, security_manager
  from superset.commands.dashboard.exceptions import DashboardAccessDeniedError, DashboardForbiddenError, DashboardNotFoundError
  from superset.daos.base import BaseDAO
  from superset.dashboards.filters import DashboardAccessFilter, is_uuid
  from superset.exceptions import SupersetSecurityException
  from superset.extensions import db
  from superset.models.core import FavStar, FavStarClassName
  from superset.models.dashboard import Dashboard, id_or_slug_filter
  from superset.models.embedded_dashboard import EmbeddedDashboard
  from superset.models.slice import Slice
  from superset.utils.core import get_user_id
  from superset.utils.dashboard_filter_scopes_converter import copy_filter_scopes
label_desc: Use image node_id 1 for calling the EmbeddedDashboardDAO obj's underlying member method code with example usage: obj.upsert(dashboard, allowed_domains) and returns: embedded