Ejemplo n.º 1
0
def get_available_social_auth_providers() -> Dict[str, bool]:
    github: bool = bool(settings.SOCIAL_AUTH_GITHUB_KEY
                        and settings.SOCIAL_AUTH_GITHUB_SECRET)
    gitlab: bool = bool(settings.SOCIAL_AUTH_GITLAB_KEY
                        and settings.SOCIAL_AUTH_GITLAB_SECRET)
    google: bool = False

    if getattr(settings, "SOCIAL_AUTH_GOOGLE_OAUTH2_KEY", None) and getattr(
            settings,
            "SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET",
            None,
    ):
        if settings.MULTI_TENANCY:
            google = True
        else:

            try:
                from ee.models.license import License
            except ImportError:
                pass
            else:
                license = License.objects.first_valid()
                if license is not None and "google_login" in license.available_features:
                    google = True
                else:
                    print_warning([
                        "You have Google login set up, but not the required premium PostHog plan!"
                    ])

    return {"google-oauth2": google, "github": github, "gitlab": gitlab}
Ejemplo n.º 2
0
def render_template(template_name: str, request: HttpRequest, context: Dict = {}) -> HttpResponse:
    from posthog.models import Team

    template = get_template(template_name)

    # Get the current user's team (or first team in the instance) to set opt out capture & self capture configs
    team: Optional[Team] = None
    try:
        team = request.user.team  # type: ignore
    except (Team.DoesNotExist, AttributeError):
        team = Team.objects.first()

    context["opt_out_capture"] = os.getenv("OPT_OUT_CAPTURE", False)

    # TODO: BEGINS DEPRECATED CODE
    # Code deprecated in favor of posthog.api.authentication.AuthenticationSerializer
    # Remove after migrating login to React
    if settings.SOCIAL_AUTH_GITHUB_KEY and settings.SOCIAL_AUTH_GITHUB_SECRET:
        context["github_auth"] = True
    if settings.SOCIAL_AUTH_GITLAB_KEY and settings.SOCIAL_AUTH_GITLAB_SECRET:
        context["gitlab_auth"] = True
    if getattr(settings, "SOCIAL_AUTH_GOOGLE_OAUTH2_KEY", None) and getattr(
        settings, "SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET", None
    ):
        if settings.MULTI_TENANCY:
            context["google_auth"] = True
        else:
            google_login_paid_for = False
            try:
                from ee.models.license import License
            except ImportError:
                pass
            else:
                license = License.objects.first_valid()
                if license is not None and "google_login" in license.available_features:
                    google_login_paid_for = True
            if google_login_paid_for:
                context["google_auth"] = True
            else:
                print_warning(["You have Google login set up, but not the required premium PostHog plan!"])
    # ENDS DEPRECATED CODE

    if os.environ.get("SENTRY_DSN"):
        context["sentry_dsn"] = os.environ["SENTRY_DSN"]

    if settings.DEBUG and not settings.TEST:
        context["debug"] = True
        context["git_rev"] = get_git_commit()
        context["git_branch"] = get_git_branch()

    if settings.SELF_CAPTURE:
        if team:
            context["js_posthog_api_key"] = f"'{team.api_token}'"
            context["js_posthog_host"] = "window.location.origin"
    else:
        context["js_posthog_api_key"] = "'sTMFPsFhdP1Ssg'"
        context["js_posthog_host"] = "'https://app.posthog.com'"

    html = template.render(context, request=request)
    return HttpResponse(html)
Ejemplo n.º 3
0
    raise exceptions.NotFound(detail="Endpoint not found.")


router = OptionalTrailingSlashRouter()
router.register(r"annotation", annotation.AnnotationsViewSet)
router.register(r"event", event.EventViewSet)
router.register(r"element", element.ElementViewSet)
router.register(r"person", person.PersonViewSet)
router.register(r"action", action.ActionViewSet)
router.register(r"feature_flag", feature_flag.FeatureFlagViewSet)
router.register(r"funnel", funnel.FunnelViewSet)
router.register(r"dashboard", dashboard.DashboardsViewSet)
router.register(r"dashboard_item", dashboard.DashboardItemsViewSet)
router.register(r"cohort", cohort.CohortViewSet)
router.register(r"paths", paths.PathsViewSet, basename="paths")
router.register(r"personal_api_keys", personal_api_key.PersonalAPIKeyViewSet, basename="personal_api_keys")
router.register(r"team/user", team_user.TeamUserViewSet)
router.register(r"insight", insight.InsightViewSet)

if check_ee_enabled():
    try:
        from ee.clickhouse.views import ClickhouseActions, ClickhouseEvents, ClickhouseInsights, ClickhousePerson

        # router.register(r"action", ClickhouseActions, basename="action")
        # router.register(r"event", ClickhouseEvents, basename="event")
        # router.register(r"insight", ClickhouseInsights, basename="insight")
        # router.register(r"person", ClickhousePerson, basename="person")

    except ImportError:
        print_warning(("ClickHouse enabled, but enterprise features missing!", "Defaulting to Postgres."))