UserProfile Model

Account UserProfile model.

class smarter.apps.account.models.user_profile.SmarterBaseModelManager(*args, **kwargs)[source]

Bases: Manager

Custom manager for MetaDataWithOwnershipModel that returns a.

SmarterBaseQuerySetWithPermissions to enable permission-based filtering by user_profile.

alias(*args, **kwargs)[source]

Returns a SmarterBaseQuerySetWithPermissions with alias applied.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

annotate(*args, **kwargs)[source]

Returns a SmarterBaseQuerySetWithPermissions with annotate applied.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

complex_filter(filter_obj)[source]

Returns a SmarterBaseQuerySetWithPermissions with the applied complex filter.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

difference(*other_qs)[source]

Returns a SmarterBaseQuerySetWithPermissions representing the difference of querysets.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

distinct(*field_names)[source]

Returns a SmarterBaseQuerySetWithPermissions with distinct applied.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

exclude(*args, **kwargs)[source]

Returns a SmarterBaseQuerySetWithPermissions with the applied exclusion.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

filter(*args, **kwargs)[source]

Returns a SmarterBaseQuerySetWithPermissions with the applied filter.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

get_queryset()[source]

Returns a SmarterBaseQuerySetWithPermissions for the model.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

intersection(*other_qs)[source]

Returns a SmarterBaseQuerySetWithPermissions representing the intersection of querysets.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

none()[source]

Returns an empty SmarterBaseQuerySetWithPermissions.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

order_by(*field_names)[source]

Returns a SmarterBaseQuerySetWithPermissions with order_by applied.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

Returns a SmarterBaseQuerySetWithPermissions with prefetch_related applied.

Overloads:
select_for_update(nowait=False, skip_locked=False, of=(), no_key=False)[source]

Returns a SmarterBaseQuerySetWithPermissions with select_for_update applied.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

Returns a SmarterBaseQuerySetWithPermissions with select_related applied.

Overloads:
union(*other_qs, all=False)[source]

Returns a SmarterBaseQuerySetWithPermissions representing the union of querysets.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

with_ownership_permission_for(user)[source]

Returns a queryset of resources that the authenticated user in the given request has full management (ownership) permission for.

Permission logic:

  • If the user is not authenticated, they have no access.

  • If the user is a superuser, they have ownership permission for all resources.

  • If the user is a staff user, they have ownership permission for resources that are:
    • Owned by their UserProfile, OR

    • Owned by any UserProfile within their Account.

  • If the user is a regular authenticated user, they have ownership permission only for resources they own.

Parameters:

user (User) – django.contrib.auth.models.User The user to check.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

Returns:

django.db.models.QuerySet A queryset of this resource if the user has permission to fully manage it, or an empty queryset if not.

with_read_permission_for(user)[source]

A custom Smarter pipeline for filtering any MetaDataWithOwnership queryset based on the Smarter permissions scheme for the authenticated user in the given request.

Returns a queryset of the resource if the user has permission to read it, or an empty queryset if not.

Permission logic:

  • If the user is not authenticated, they have no access.

  • If the user is a superuser, they have access to all resources.

  • If the user is a regular authenticated user, they have access to resources that are:
    • Owned by their UserProfile, OR

    • Owned by their Account admin UserProfile, OR

    • Owned by the Smarter admin UserProfile.

Parameters:
  • user (User) – django.contrib.auth.models.User The user to check.

  • queryset – Optional[django.db.models.QuerySet] An optional queryset to filter. If not provided, the method will default to filtering all instances

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

Returns:

django.db.models.QuerySet A queryset of this resource if the user has permission to read it, or an empty queryset if not.

class smarter.apps.account.models.user_profile.SmarterBaseQuerySetWithPermissions(model=None, query=None, using=None, hints=None)[source]

Bases: QuerySet

Custom queryset for permission-based resource filtering by user profile.

This queryset adds permission-aware filtering for resources owned by a specific user profile.

See also

with_ownership_permission_for(user)[source]

Returns a queryset of resources that the authenticated user in the given request has full management (ownership) permission for.

Only users with staff or superuser status are permitted to manage resources.

Parameters:

user (User) – django.contrib.auth.models.User The user to check.

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

Returns:

django.db.models.QuerySet A queryset of this resource if the user has permission to fully manage it, or an empty queryset if not.

with_read_permission_for(user)[source]

A pipeline for filtering a queryset of this resource based on the permissions of the authenticated user in the given request.

Return a queryset of this resource if the user has permission to read it, or an empty queryset if not.

Parameters:
  • user (User) – django.contrib.auth.models.User The user to check.

  • queryset – Optional[django.db.models.QuerySet] An optional queryset to filter. If not provided, the method will default to filtering all instances

Return type:

SmarterBaseQuerySetWithPermissions[_GenericTypeVar]

Returns:

django.db.models.QuerySet A queryset of this resource if the user has permission to read it, or an empty queryset if not.

class smarter.apps.account.models.user_profile.UserProfile(*args, **kwargs)[source]

Bases: MetaDataModel

UserProfile model for associating Django users with Smarter accounts.

Establishes a link between a Django User and an Account, enabling centralized management of billing, identity, and resource ownership.

Parameters:
  • user – ForeignKey to django.contrib.auth.models.User. The user associated with this profile.

  • account – ForeignKey to Account. The related Smarter account.

  • profile_image_url – URLField. The profile image that the oauth provider supplied at login.

  • profile_image – ImageField. The profile image that the user uploaded. Takes precedence over profile_image_url.

  • is_test – Boolean. Indicates if this profile is for testing purposes.

  • welcomed_at – DateTimeField. When the user closed the web console’s welcome dialog, or None if they haven’t seen it yet. See smarter.apps.dashboard.views.views.api.welcome.

  • language – CharField. The user’s preferred language, a code of settings.LANGUAGES, e.g. es. Defaults to English. The emails that the user is sent, such as the welcome email, are written in it. A console sign-up stores the language of the sign-up request (see active_language()).

Important

The combination of user and account must be unique. Duplicate profiles for the same user and account are not allowed.

Example usage:

from smarter.apps.account.models import UserProfile
profile = UserProfile.objects.create(user=user, account=account)
profile.add_to_account_contacts(is_primary=True)
Parameters:
  • id (Unknown) – Primary key: ID

  • created_at (Unknown) – Created at

  • updated_at (Unknown) – Updated at

  • name (Unknown) – Name. Name in camelCase, e.g., ‘apiKey’, no special characters.

  • description (Unknown) – Description. A brief description of this resource. Be verbose, but not too verbose.

  • version (Unknown) – Version. Semantic version in the format MAJOR.MINOR.PATCH, e.g., ‘1.0.0’.

  • is_account_admin (Unknown) – Is account admin. Whether the user administers this account, and only this one: they manage every resource in it. Unlike User.is_staff, it gives no access to the Django admin site, and no rights in the user’s other accounts.

  • show_welcome_at_startup (Unknown) – Show welcome at startup. Whether the web console’s welcome dialog opens by itself each time the user signs in: its Show at startup box. Unticked, it opens by itself only until the user first closes it.

  • console_language (Unknown) – Console language. The language that the user chose in the web console’s language menu, which the console restores when the browser has no language cookie, e.g. on another device. Empty until they choose one.

Relationship fields:

Parameters:
  • tags (Unknown) – Tags. Tags for categorizing and organizing this resource. (related name: userprofile)

  • tagged_items (Unknown) – Tagged items (related name: +)

Reverse relationships:

Parameters:
  • smarterauthtoken (Unknown) – All API Keys of this user profile (related name of user_profile)

  • repository_applies (Unknown) – All repository applies of this user profile (related name of user_profile)

  • connectionbase (Unknown) – All connection bases of this user profile (related name of user_profile)

  • guardrail (Unknown) – All Guardrails of this user profile (related name of user_profile)

  • llmclientcustomdomain (Unknown) – All LLMClient Custom Domains of this user profile (related name of user_profile)

  • llmclient (Unknown) – All LLMClients of this user profile (related name of user_profile)

  • llmhostcompute (Unknown) – All LLMHost Compute of this user profile (related name of user_profile)

  • llmhost (Unknown) – All LLMHosts of this user profile (related name of user_profile)

  • mcpclient (Unknown) – All MCPClients of this user profile (related name of user_profile)

  • orchestrator (Unknown) – All Orchestrators of this user profile (related name of user_profile)

  • orchestration_runs (Unknown) – All orchestration runs of this user profile (related name of started_by)

  • pluginmeta (Unknown) – All Plugins of this user profile (related name of user_profile)

  • prompt (Unknown) – All Prompts of this user profile (related name of user_profile)

  • provider (Unknown) – All Providers of this user profile (related name of user_profile)

  • proxy (Unknown) – All Proxies of this user profile (related name of user_profile)

  • secrets (Unknown) – All secrets of this user profile (related name of user_profile)

  • vectorsearch (Unknown) – All Vectorsearches of this user profile (related name of user_profile)

  • vectorstoremeta (Unknown) – All Vectorstores of this user profile (related name of user_profile)

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

account

ForeignKey to Account

Account (related name: user_profiles)

Type:

Type

account_id

Internal field, use account instead.

add_to_account_contacts(is_primary=False)[source]

Add the user to the account’s contact list.

Creates or updates an AccountContact entry for the user, ensuring their email and name are registered with the account. Optionally sets the contact as primary. A new contact is sent the welcome email, in the user’s language.

Parameters:

is_primary (bool) – Boolean. If True, marks the contact as the primary contact for the account. Defaults to False.

Important

Ensures every user associated with an account is also listed as a contact, supporting notifications and account management.

Example usage:

profile.add_to_account_contacts(is_primary=True)

See also

AccountContact

classmethod admin_for_account(account)[source]

Return the designated user for the given account.

This method finds the first administrator of the account, by is_account_admin or User.is_staff. If there is none, it returns the first available user. If the account has no users, it creates an administrator of the account’s own, with get_cached_admin_user_for_account(), and never adds the platform’s admin to it.

Parameters:

account (Account) – Instance of Account. The account for which to find the designated user.

Return type:

User

Returns:

django.contrib.auth.models.User The designated user for the account.

Attention

If no staff or regular users exist for the account, an admin user is automatically created. You must set the password manually.

Error

Logs an error if no admin or user is found for the account.

Example usage:

user = UserProfile.admin_for_account(account)

See also

UserProfile

property administers_account: bool

manages every resource in it.

See user_administers_account().

Returns:

True if the user may manage every resource of this profile’s account.

Type:

Whether this profile’s user administers its account

property avatar_url: str

Return the url of the image that represents this user in the web console.

In order of precedence: the image that the user uploaded, the image that the oauth provider (Google, GitHub, LinkedIn) supplied at login, and the default profile image.

An uploaded image’s url is absolute under S3, but a relative path under FileSystemStorage (no AWS configured), which is joined onto smarter_settings.environment_url.

Returns:

An absolute url, or the static url of the default profile image.

Return type:

str

Example usage:

<img src="{{ user_profile.avatar_url }}" />
property cached_account: Account

Retrieve the associated Account instance with caching.

This significantly reduces the number of database queries when accessing the account from the user profile.

Returns:

Account The associated Account instance.

Example usage:

account = user_profile.cached_account
if account:
    print(account.company_name)
property cached_user: User

Retrieve the associated User instance with caching.

This significantly reduces the number of database queries when accessing the user from the user profile.

Returns:

User The associated User instance.

Example usage:

user = profile.cached_user
if user:
    print(user.email)
connectionbase_set

Reverse ForeignKey from ConnectionBase

All connection bases of this user profile (related name of user_profile)

Type:

Type

console_language

CharField

Console language. The language that the user chose in the web console’s language menu, which the console restores when the browser has no language cookie, e.g. on another device. Empty until they choose one.

Choices:

  • en

  • es

  • fr

  • pt-br

Type:

Type

created_at

DateTimeField

Created at

Timestamp indicating when the model instance was created.

This field is automatically set to the current date and time when the instance is first created. It is indexed in the database for efficient querying.

Type:

Type

description

TextField

Description. A brief description of this resource. Be verbose, but not too verbose.

Type:

Type

classmethod get_cached_object(*args, invalidate=False, pk=None, name=None, user=None, username=None, account=None, **kwargs)[source]

Retrieve a model instance by primary key or name, using caching to optimize performance.

This method is selectively overridden in models that inherit from MetaDataModel to provide class-specific function parameters.

Given a user (or username) and no account, it returns the profile that the user chose in the web console’s user menu, for this request (see get_selected_object()), else the user’s newest profile.

Example usage:

# Retrieve by primary key
instance = MyModel.get_cached_object(pk=1)
# Retrieve by name
instance = MyModel.get_cached_object(name="exampleName")
Parameters:
  • pk (int | None) – The primary key of the model instance to retrieve.

  • name (str | None) – The name of the model instance to retrieve.

Returns:

The model instance if found, otherwise None.

Return type:

UserProfile

classmethod get_cached_objects(invalidate=False, user=None, **kwargs)[source]

Retrieve a queryset of UserProfile instances associated with the given user, using caching to optimize performance.

Parameters:
  • invalidate (bool | None) – Boolean. If True, invalidates the cache for the user’s profiles before retrieving.

  • user (User | None) – Optional[User]. If provided, retrieves profiles associated with this user. If not provided, retrieves all profiles.

Returns:

QuerySet[UserProfile]. A queryset of UserProfile instances associated with the given user, or all profiles if no user is specified.

Return type:

QuerySet[UserProfile]

get_console_language_display(*, field=<django.db.models.CharField: console_language>)

Shows the label of the console_language. See get_FOO_display() for more information.

get_language_display(*, field=<django.db.models.CharField: language>)

Shows the label of the language. See get_FOO_display() for more information.

classmethod get_selected_object(user_id)[source]

Return the UserProfile that the user chose in the web console’s user menu, if any.

A user with more than one UserProfile can choose which one the console acts as, with the user menu’s Change Profile item, which stores its id in the session. For the length of a request, the id is in selected_user_profile_id. See smarter.apps.account.profile_selection.

Parameters:

user_id (int | None) – The primary key of the user whose profile is being resolved.

Returns:

The chosen UserProfile, or None if the request has no choice, the user is another user, or the chosen profile no longer exists.

Return type:

UserProfile | None

Example usage:

user_profile = UserProfile.get_selected_object(request.user.pk) or newest_user_profile
guardrail_set

Reverse ForeignKey from Guardrail

All Guardrails of this user profile (related name of user_profile)

Type:

Type

id: int

BigAutoField

Primary key: ID

The row’s primary key, which Django adds to every concrete model. Declared, without a value, only so that type checkers know it: Django ignores a bare annotation.

Type:

Type

is_account_admin

BooleanField

Is account admin. Whether the user administers this account, and only this one: they manage every resource in it. Unlike User.is_staff, it gives no access to the Django admin site, and no rights in the user’s other accounts.

Type:

Type

is_test

BooleanField

Is test. Indicates if this profile is used for unit testing purposes.

Type:

Type

language

CharField

Language. The user’s preferred language, in which they are sent emails, e.g. the welcome email.

Choices:

  • en

  • es

  • fr

  • pt-br

Type:

Type

llmclient_set

Reverse ForeignKey from LLMClient

All LLMClients of this user profile (related name of user_profile)

Type:

Type

llmclientcustomdomain_set

Reverse ForeignKey from LLMClientCustomDomain

All LLMClient Custom Domains of this user profile (related name of user_profile)

Type:

Type

llmhost_set

Reverse ForeignKey from LLMHost

All LLMHosts of this user profile (related name of user_profile)

Type:

Type

llmhostcompute_set

Reverse ForeignKey from LLMHostCompute

All LLMHost Compute of this user profile (related name of user_profile)

Type:

Type

mcpclient_set

Reverse ForeignKey from MCPClient

All MCPClients of this user profile (related name of user_profile)

Type:

Type

name

CharField

Name. Name in camelCase, e.g., ‘apiKey’, no special characters.

Type:

Type

objects: SmarterBaseModelManager = <smarter.apps.account.models.user_profile.SmarterBaseModelManager object>
orchestration_runs

Reverse ForeignKey from OrchestrationRun

All orchestration runs of this user profile (related name of started_by)

Type:

Type

orchestrator_set

Reverse ForeignKey from Orchestrator

All Orchestrators of this user profile (related name of user_profile)

Type:

Type

pluginmeta_set

Reverse ForeignKey from PluginMeta

All Plugins of this user profile (related name of user_profile)

Type:

Type

profile_image

ImageField

Profile image. The user’s own profile image, uploaded in the web console. Takes precedence over profile_image_url.

Type:

Type

profile_image_url

URLField

Profile image url. URL to the user’s profile image, provided via oauth.

Type:

Type

prompt_set

Reverse ForeignKey from Prompt

All Prompts of this user profile (related name of user_profile)

Type:

Type

provider_set

Reverse ForeignKey from Provider

All Providers of this user profile (related name of user_profile)

Type:

Type

proxy_set

Reverse ForeignKey from Proxy

All Proxies of this user profile (related name of user_profile)

Type:

Type

repository_applies

Reverse ForeignKey from RepositoryApply

All repository applies of this user profile (related name of user_profile)

Type:

Type

save(*args, **kwargs)[source]

Save the UserProfile instance and ensure account contacts are updated.

This method validates that both user and account are set, saves the profile, and, if newly created, adds the user to the account’s contact list. It also emits a signal for new user creation.

Parameters:
  • args – Positional arguments passed to the parent save method.

  • kwargs – Keyword arguments passed to the parent save method.

Note

On first save, ensures at least one primary contact exists for the account.

Example usage:

profile.save()
secrets

Reverse ForeignKey from Secret

All secrets of this user profile (related name of user_profile)

Type:

Type

show_welcome_at_startup

BooleanField

Show welcome at startup. Whether the web console’s welcome dialog opens by itself each time the user signs in: its Show at startup box. Unticked, it opens by itself only until the user first closes it.

Type:

Type

smarterauthtoken_set

Reverse ForeignKey from SmarterAuthToken

All API Keys of this user profile (related name of user_profile)

Type:

Type

tagged_items

Reverse GenericRelation from UserProfile

All + of this tagged item (related name of tagged_items)

Type:

Type

tags = <taggit.managers._TaggableManager object>
updated_at

DateTimeField

Updated at

Timestamp indicating when the model instance was last updated.

This field is automatically updated to the current date and time whenever the instance is saved. It is indexed in the database for efficient querying.

Type:

Type

user

ForeignKey to User

User (related name: user_profile)

Type:

Type

user_id

Internal field, use user instead.

vectorsearch_set

Reverse ForeignKey from Vectorsearch

All Vectorsearches of this user profile (related name of user_profile)

Type:

Type

vectorstoremeta_set

Reverse ForeignKey from VectorstoreMeta

All Vectorstores of this user profile (related name of user_profile)

Type:

Type

version

CharField

Version. Semantic version in the format MAJOR.MINOR.PATCH, e.g., ‘1.0.0’.

Type:

Type

welcomed_at

DateTimeField

Welcomed at. When the user first closed the web console’s welcome dialog. Empty until they have seen it.

Type:

Type

smarter.apps.account.models.user_profile.user_administers_account(user, user_profile)[source]

Whether a user administers an account: manages every resource in it.

A superuser administers every account. A user with User.is_staff administers each account they belong to, which is how an account’s administrator has been marked, and which also opens the Django admin site, and no other: staff of one account have no say in another, so their own profile in the account is required, as for anyone else. A user whose own profile in the account has is_account_admin administers that account only, and opens nothing else: the role for a department’s administrator in an organization of several accounts (ADR-036).

Parameters:
  • user (object) – The user, e.g. a request’s. None, or an anonymous user, administers nothing.

  • user_profile (UserProfile | None) – The user’s profile in the account, if any. None, or a profile of another user, makes anyone but a superuser administer nothing.

Return type:

bool

Returns:

True if the user may manage every resource of the account.