Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add user data to version endpoint #5056

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion api/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@
VERSIONS_INFO_FILE_LOCATION = ".versions.json"


class SelfHostedData(TypedDict):
has_users: bool
has_logins: bool
is_bootstrapped: bool


class VersionInfo(TypedDict):
ci_commit_sha: str
image_tag: str
has_email_provider: bool
is_enterprise: bool
is_saas: bool
self_hosted_data: SelfHostedData | None


def create_hash() -> str:
Expand Down Expand Up @@ -49,6 +56,8 @@ def get_version_info() -> VersionInfo:
version_json = {}
image_tag = UNKNOWN

_is_saas = is_saas()

manifest_versions_content: str = _get_file_contents(VERSIONS_INFO_FILE_LOCATION)

if manifest_versions_content != UNKNOWN:
Expand All @@ -61,9 +70,22 @@ def get_version_info() -> VersionInfo:
"image_tag": image_tag,
"has_email_provider": has_email_provider(),
"is_enterprise": is_enterprise(),
"is_saas": is_saas(),
"is_saas": _is_saas,
"self_hosted_data": None,
}

if not _is_saas:
from users.models import FFAdminUser

version_json["self_hosted_data"] = {
"has_users": FFAdminUser.objects.count() > 0,
"has_logins": FFAdminUser.objects.filter(last_login__isnull=False).exists(),
"is_bootstrapped": (
settings.ALLOW_ADMIN_INITIATION_VIA_CLI is True
and FFAdminUser.objects.filter(email=settings.ADMIN_EMAIL).exists()
),
}

return version_json


Expand Down
7 changes: 6 additions & 1 deletion api/tests/unit/app/test_unit_app_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app.utils import get_version_info


def test_get_version_info(fs: FakeFilesystem) -> None:
def test_get_version_info(fs: FakeFilesystem, db: None) -> None:
# Given
expected_manifest_contents = {
".": "2.66.2",
Expand All @@ -28,6 +28,11 @@ def test_get_version_info(fs: FakeFilesystem) -> None:
"is_enterprise": True,
"is_saas": False,
"package_versions": {".": "2.66.2"},
"self_hosted_data": {
"has_users": False,
"has_logins": False,
"is_bootstrapped": False,
},
}


Expand Down
Loading