Ejemplo n.º 1
0
 def test_use_upstream_app_id_returns_correct_app(self):
     original_app, linked_app = self.setup_linked_app(
         set_upstream_app_id=True)
     downstream_app_id = get_downstream_app_id(self.downstream_domain,
                                               original_app._id,
                                               use_upstream_app_id=True)
     self.assertEqual(linked_app._id, downstream_app_id)
Ejemplo n.º 2
0
def migrate_linked_reports(upstream_domain=None):
    logger.setLevel(logging.INFO)
    if upstream_domain:
        domain_links = DomainLink.all_objects.filter(
            master_domain=upstream_domain)
    else:
        domain_links = DomainLink.all_objects.all()

    num_of_failed_attempts = 0
    for domain_link in domain_links:
        reports = get_report_configs_for_domain(domain_link.linked_domain)
        for report in reports:
            if report.report_meta.master_id and not report.config.meta.build.app_id:
                upstream_report = ReportConfiguration.get(
                    report.report_meta.master_id)
                upstream_datasource = DataSourceConfiguration.get(
                    upstream_report.config_id)
                downstream_app_id = get_downstream_app_id(
                    domain_link.linked_domain,
                    upstream_datasource.meta.build.app_id,
                )
                if not downstream_app_id:
                    # just as a backup in case upstream_app_id is not set but family_id is
                    downstream_app_id = get_downstream_app_id(
                        domain_link.linked_domain,
                        upstream_datasource.meta.build.app_id,
                        use_upstream_app_id=False)
                    if downstream_app_id:
                        logger.info(
                            f"Needed to use family_id to find downstream app {downstream_app_id}"
                        )

                if not downstream_app_id:
                    logger.warning(
                        f"Could not find downstream_app_id for upstream app"
                        f" {upstream_datasource.meta.build.app_id} "
                        f"in downstream domain {domain_link.linked_domain}")
                    num_of_failed_attempts += 1

                report.config.meta.build.app_id = downstream_app_id
                report.config.save()
    logger.info(
        f"Completed linked report migration with {num_of_failed_attempts} failed attempts"
    )
    return num_of_failed_attempts
Ejemplo n.º 3
0
def _replace_upstream_app_id(haystack, upstream_app_id, downstream_domain):
    if upstream_app_id in haystack:
        try:
            downstream_app_id = get_downstream_app_id(downstream_domain, upstream_app_id)
        except MultipleDownstreamAppsError:
            raise DomainLinkError(_("This report cannot be updated because it references an app "
                                    "that has multiple linked apps."))
        haystack = haystack.replace(upstream_app_id, downstream_app_id)
    return haystack
Ejemplo n.º 4
0
def create_linked_ucr(domain_link, report_config_id):
    if domain_link.is_remote:
        remote_configs = remote_get_ucr_config(domain_link, report_config_id)
        datasource = remote_configs["datasource"]
        report_config = remote_configs["report"]
    else:
        report_config = ReportConfiguration.get(report_config_id)
        datasource = DataSourceConfiguration.get(report_config.config_id)

    # grab the linked app this linked report references
    try:
        downstream_app_id = get_downstream_app_id(domain_link.linked_domain, datasource.meta.build.app_id)
    except MultipleDownstreamAppsError:
        raise DomainLinkError(_("This report cannot be linked because it references an app that has multiple "
                                "downstream apps."))

    new_datasource = _get_or_create_datasource_link(domain_link, datasource, downstream_app_id)
    new_report = _get_or_create_report_link(domain_link, report_config, new_datasource)
    return LinkedUCRInfo(datasource=new_datasource, report=new_report)
Ejemplo n.º 5
0
def _update_actions(domain_link, linked_keyword, keyword_actions):
    linked_keyword.keywordaction_set.all().delete()
    for keyword_action in keyword_actions:
        keyword_action.id = None
        keyword_action.keyword = linked_keyword
        if keyword_action.app_id is not None:
            try:
                app_id = get_downstream_app_id(domain_link.linked_domain,
                                               keyword_action.app_id)
            except MultipleDownstreamAppsError:
                raise DomainLinkError(
                    _("Keyword {keyword} references an application that has multiple linked "
                      "applications. It cannot be updated.").format(
                          keyword=linked_keyword.keyword))
            if not app_id:
                raise DomainLinkError(
                    _("Keyword {keyword} references an application "
                      "that has not been linked to {linked_domain}").format(
                          keyword=linked_keyword.keyword,
                          linked_domain=domain_link.linked_domain))
            keyword_action.app_id = app_id
        keyword_action.save()
Ejemplo n.º 6
0
 def test_use_upstream_app_id_returns_none_if_family_id_is_set(self):
     original_app, _ = self.setup_linked_app(set_family_id=True)
     downstream_app_id = get_downstream_app_id(self.downstream_domain,
                                               original_app._id,
                                               use_upstream_app_id=True)
     self.assertIsNone(downstream_app_id)