Skip to content
Closed
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
7 changes: 6 additions & 1 deletion testgen/common/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from uuid import UUID, uuid4

import streamlit as st
from sqlalchemy import Boolean, Column, String, asc, func, select, update
from sqlalchemy import Boolean, Column, String, asc, func, select, text, update
from sqlalchemy.dialects import postgresql

from testgen.common.models import get_current_session
Expand All @@ -22,6 +22,7 @@ class User(Entity):
password: str = Column(String)
is_global_admin: bool = Column(Boolean, nullable=False, default=False)
latest_login: datetime = Column(postgresql.TIMESTAMP)
preferences: dict = Column(postgresql.JSONB, nullable=False, server_default=text("'{}'"))

_get_by = "username"
_default_order_by = (asc(func.lower(username)),)
Expand All @@ -41,6 +42,10 @@ def save(self, update_latest_login: bool = False) -> None:
self.latest_login = datetime.now(UTC)
super().save()

def update_preferences(self) -> None:
query = update(User).where(User.id == self.id).values(preferences=self.preferences)
get_current_session().execute(query)

@classmethod
@st.cache_data(show_spinner=False)
def get(cls, identifier: str) -> Self | None:
Expand Down
18 changes: 18 additions & 0 deletions testgen/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,24 @@
Disables sending usage data when set to any value except "true" and "yes". Defaults to "yes"
"""

DISABLE_FEEDBACK_POPUP: bool = os.getenv("TG_DISABLE_FEEDBACK_POPUP", "no").lower() in ("yes", "true")
"""
When set to "yes" or "true", suppresses the periodic feedback popup entirely.
Intended for enterprise customers who block outbound network calls.

from env variable: `TG_DISABLE_FEEDBACK_POPUP`
defaults to: `no`
"""

SLACK_FEEDBACK_WEBHOOK: str | None = os.getenv("TG_SLACK_FEEDBACK_WEBHOOK")
"""
Slack Incoming Webhook URL to post feedback submissions.
When set, each submitted feedback is posted to the configured Slack channel.

from env variable: `TG_SLACK_FEEDBACK_WEBHOOK`
defaults to: `None` (no Slack notification)
"""

ANALYTICS_JOB_SOURCE: str = os.getenv("TG_JOB_SOURCE", "CLI")
"""
Identifies the job trigger for analytics purposes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,8 @@ CREATE TABLE auth_users (
name VARCHAR(256),
password VARCHAR(120),
is_global_admin BOOLEAN NOT NULL DEFAULT FALSE,
latest_login TIMESTAMP
latest_login TIMESTAMP,
preferences JSONB NOT NULL DEFAULT '{}'
);

ALTER TABLE auth_users
Expand Down
15 changes: 15 additions & 0 deletions testgen/template/dbupgrade/0180_incremental_upgrade.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SET SEARCH_PATH TO {SCHEMA_NAME};

DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = '{SCHEMA_NAME}'
AND table_name = 'auth_users'
AND column_name = 'preferences'
) THEN
ALTER TABLE auth_users
ADD COLUMN preferences JSONB NOT NULL DEFAULT '{}';
END IF;
END $$;
Loading
Loading