Skip to content

Models

hypha.apply.users.models

UserQuerySet

Bases: QuerySet

active

active()
Source code in hypha/apply/users/models.py
def active(self):
    return self.filter(is_active=True)

staff

staff()
Source code in hypha/apply/users/models.py
def staff(self):
    return self.filter(groups__name=STAFF_GROUP_NAME, is_active=True)

staff_admin

staff_admin()
Source code in hypha/apply/users/models.py
def staff_admin(self):
    return self.filter(groups__name=TEAMADMIN_GROUP_NAME, is_active=True)

reviewers

reviewers()
Source code in hypha/apply/users/models.py
def reviewers(self):
    return self.filter(groups__name=REVIEWER_GROUP_NAME, is_active=True)

partners

partners()
Source code in hypha/apply/users/models.py
def partners(self):
    return self.filter(groups__name=PARTNER_GROUP_NAME, is_active=True)

community_reviewers

community_reviewers()
Source code in hypha/apply/users/models.py
def community_reviewers(self):
    return self.filter(groups__name=COMMUNITY_REVIEWER_GROUP_NAME, is_active=True)

applicants

applicants()
Source code in hypha/apply/users/models.py
def applicants(self):
    return self.filter(groups__name=APPLICANT_GROUP_NAME, is_active=True)

approvers

approvers()
Source code in hypha/apply/users/models.py
def approvers(self):
    return self.filter(groups__name=APPROVER_GROUP_NAME, is_active=True)

finances

finances()
Source code in hypha/apply/users/models.py
def finances(self):
    return self.filter(groups__name=FINANCE_GROUP_NAME, is_active=True)

contracting

contracting()
Source code in hypha/apply/users/models.py
def contracting(self):
    return self.filter(groups__name=CONTRACTING_GROUP_NAME, is_active=True)

UserManager

Bases: from_queryset(UserQuerySet)

use_in_migrations class-attribute instance-attribute

use_in_migrations = True

create_user

create_user(email, password=None, **extra_fields)
Source code in hypha/apply/users/models.py
def create_user(self, email, password=None, **extra_fields):
    extra_fields.setdefault("is_staff", False)
    extra_fields.setdefault("is_superuser", False)
    return self._create_user(email, password, **extra_fields)

create_superuser

create_superuser(email, password, **extra_fields)
Source code in hypha/apply/users/models.py
def create_superuser(self, email, password, **extra_fields):
    extra_fields.setdefault("is_staff", True)
    extra_fields.setdefault("is_superuser", True)

    if extra_fields.get("is_staff") is not True:
        raise ValueError("Superuser must have is_staff=True.")
    if extra_fields.get("is_superuser") is not True:
        raise ValueError("Superuser must have is_superuser=True.")

    return self._create_user(email, password, **extra_fields)

get_or_create_and_notify

get_or_create_and_notify(defaults=None, site=None, **kwargs)

Create or get an account for applicant and send activation email to applicant.

Parameters:

  • defaults (dict | None, default: None ) –

    Dict containing user attributes for user creation. Defaults to dict().

  • site –

    current site for sending activation email. Defaults to None.

Raises:

  • IntegrityError –

    if multiple account exist with same email

Returns:

  • –

    A tuple containing a user instance and a boolean that indicates

  • –

    whether the user was created or not.

Source code in hypha/apply/users/models.py
def get_or_create_and_notify(
    self, defaults: dict | None = None, site=None, **kwargs
):
    """Create or get an account for applicant and send activation email to applicant.

    Args:
        defaults: Dict containing user attributes for user creation. Defaults to dict().
        site: current site for sending activation email. Defaults to None.

    Raises:
        IntegrityError: if multiple account exist with same email

    Returns:
        A tuple containing a user instance and a boolean that indicates
        whether the user was created or not.
    """
    _created = False

    if defaults is None:
        defaults = {}

    email = kwargs.get("email")
    redirect_url = ""
    if "redirect_url" in kwargs:
        redirect_url = kwargs.pop("redirect_url")

    is_registered, _ = is_user_already_registered(email=email)

    if is_registered:
        user = get_user_by_email(email=email)
        # already handled in PageStreamBaseForm.
        if not user:
            raise IntegrityError("Found multiple account")
        elif not user.is_active:
            raise IntegrityError("Found an inactive account")
    else:
        if kwargs.get("full_name", False):
            kwargs["full_name"] = strip_html_and_nerf_urls(kwargs["full_name"])
        if "password" in kwargs:
            # Coming from registration without application
            temp_pass = kwargs.pop("password")
        else:
            temp_pass = get_random_string(length=32)

        temp_pass_hash = make_password(temp_pass)

        defaults.update(password=temp_pass_hash)
        try:
            params = dict(
                resolve_callables(self._extract_model_params(defaults, **kwargs))
            )
            user = self.create(**params)
        except IntegrityError:
            raise

        send_activation_email(user, site, redirect_url=redirect_url)
        _created = True

    return user, _created

User

Bases: AbstractUser

email class-attribute instance-attribute

email = EmailField(gettext_lazy('email address'), unique=True)

full_name class-attribute instance-attribute

full_name = CharField(verbose_name=gettext_lazy('Full name'), max_length=255, blank=True)

slack class-attribute instance-attribute

slack = CharField(verbose_name=gettext_lazy('Slack name'), blank=True, help_text=gettext_lazy('This is the name we should "@mention" when sending notifications'), max_length=50)

drupal_id class-attribute instance-attribute

drupal_id = IntegerField(null=True, blank=True, editable=False)

USERNAME_FIELD class-attribute instance-attribute

USERNAME_FIELD = 'email'

REQUIRED_FIELDS class-attribute instance-attribute

REQUIRED_FIELDS = []

username class-attribute instance-attribute

username = None

first_name class-attribute instance-attribute

first_name = None

last_name class-attribute instance-attribute

last_name = None

objects class-attribute instance-attribute

objects = UserManager()

wagtail_reference_index_ignore class-attribute instance-attribute

wagtail_reference_index_ignore = True

Meta

ordering class-attribute instance-attribute
ordering = ('full_name', 'email')

get_full_name

get_full_name()
Source code in hypha/apply/users/models.py
def get_full_name(self):
    return self.full_name.strip()

get_short_name

get_short_name()

Gets the local-part (username) of the user's email

ie. hyphaiscool@hypha.app returns "hyphaiscool"

Source code in hypha/apply/users/models.py
def get_short_name(self) -> str:
    """Gets the local-part (username) of the user's email

    ie. [email protected] returns "hyphaiscool"
    """
    return self.email.split("@")[0]

get_display_name

get_display_name()
Source code in hypha/apply/users/models.py
def get_display_name(self):
    return self.full_name.strip() if self.full_name else self.get_short_name()

get_role_names

get_role_names()
Source code in hypha/apply/users/models.py
def get_role_names(self):
    roles = []
    if self.is_apply_staff:
        roles.append(STAFF_GROUP_NAME)
    if self.is_reviewer:
        roles.append(REVIEWER_GROUP_NAME)
    if self.is_applicant:
        roles.append(APPLICANT_GROUP_NAME)
    if self.is_finance:
        roles.append(FINANCE_GROUP_NAME)
    if self.is_contracting:
        roles.append(CONTRACTING_GROUP_NAME)
    return roles

roles

roles()
Source code in hypha/apply/users/models.py
@cached_property
def roles(self):
    return list(self.groups.values_list("name", flat=True))

is_apply_staff

is_apply_staff()
Source code in hypha/apply/users/models.py
@cached_property
def is_apply_staff(self):
    return self.groups.filter(name=STAFF_GROUP_NAME).exists() or self.is_superuser

is_apply_staff_admin

is_apply_staff_admin()
Source code in hypha/apply/users/models.py
@cached_property
def is_apply_staff_admin(self):
    return (
        self.groups.filter(name=TEAMADMIN_GROUP_NAME).exists() or self.is_superuser
    )

is_reviewer

is_reviewer()
Source code in hypha/apply/users/models.py
@cached_property
def is_reviewer(self):
    return self.groups.filter(name=REVIEWER_GROUP_NAME).exists()

is_partner

is_partner()
Source code in hypha/apply/users/models.py
@cached_property
def is_partner(self):
    return self.groups.filter(name=PARTNER_GROUP_NAME).exists()

is_community_reviewer

is_community_reviewer()
Source code in hypha/apply/users/models.py
@cached_property
def is_community_reviewer(self):
    return self.groups.filter(name=COMMUNITY_REVIEWER_GROUP_NAME).exists()

is_applicant

is_applicant()
Source code in hypha/apply/users/models.py
@cached_property
def is_applicant(self):
    return self.groups.filter(name=APPLICANT_GROUP_NAME).exists()

is_approver

is_approver()
Source code in hypha/apply/users/models.py
@cached_property
def is_approver(self):
    return self.groups.filter(name=APPROVER_GROUP_NAME).exists()

is_finance

is_finance()
Source code in hypha/apply/users/models.py
@cached_property
def is_finance(self):
    return self.groups.filter(name=FINANCE_GROUP_NAME).exists()

is_org_faculty

is_org_faculty()
Source code in hypha/apply/users/models.py
@cached_property
def is_org_faculty(self):
    return self.is_apply_staff or self.is_finance or self.is_contracting

can_access_dashboard

can_access_dashboard()
Source code in hypha/apply/users/models.py
@cached_property
def can_access_dashboard(self):
    return (
        self.is_apply_staff
        or self.is_reviewer
        or self.is_partner
        or self.is_community_reviewer
        or self.is_finance
        or self.is_contracting
        or self.is_applicant
    )

is_contracting

is_contracting()
Source code in hypha/apply/users/models.py
@cached_property
def is_contracting(self):
    return self.groups.filter(name=CONTRACTING_GROUP_NAME).exists()

is_contracting_approver

is_contracting_approver()
Source code in hypha/apply/users/models.py
@cached_property
def is_contracting_approver(self):
    return (
        self.groups.filter(name=CONTRACTING_GROUP_NAME).exists()
        and self.groups.filter(name=APPROVER_GROUP_NAME).exists()
    )

get_absolute_url

get_absolute_url()

Used in the activities messages to generate URL for user instances.

Returns:

  • –

    url pointing to the wagtail admin, as there are no public urls for user.

Source code in hypha/apply/users/models.py
def get_absolute_url(self):
    """Used in the activities messages to generate URL for user instances.

    Returns:
       url pointing to the wagtail admin, as there are no public urls for user.
    """
    return reverse("wagtailusers_users:edit", args=[self.id])

AuthSettings

Bases: BaseGenericSetting

wagtail_reference_index_ignore class-attribute instance-attribute

wagtail_reference_index_ignore = True

consent_show class-attribute instance-attribute

consent_show = BooleanField(gettext_lazy('Show consent checkbox?'), default=False)

consent_text class-attribute instance-attribute

consent_text = CharField(max_length=255, blank=True)

consent_help class-attribute instance-attribute

consent_help = RichTextField(blank=True)

extra_text class-attribute instance-attribute

extra_text = RichTextField(gettext_lazy('Login extra text'), blank=True, help_text=gettext_lazy('Displayed along side login form'))

panels class-attribute instance-attribute

panels = [MultiFieldPanel([FieldPanel('consent_show'), FieldPanel('consent_text'), FieldPanel('consent_help')], gettext_lazy('User consent on login & register forms')), MultiFieldPanel([FieldPanel('extra_text')], gettext_lazy('Login form customizations'))]

Meta

verbose_name class-attribute instance-attribute
verbose_name = 'Auth Settings'

PendingSignup

Bases: Model

This model tracks pending passwordless self-signups, and is used to generate a one-time use URLfor each signup.

The URL is sent to the user via email, and when they click on it, they are redirected to the registration page, where a new is created.

Once the user is created, the PendingSignup instance is deleted.

email class-attribute instance-attribute

email = EmailField(unique=True)

created class-attribute instance-attribute

created = DateTimeField(auto_now_add=True)

modified class-attribute instance-attribute

modified = DateTimeField(auto_now=True)

token class-attribute instance-attribute

token = CharField(max_length=255, unique=True)

Meta

ordering class-attribute instance-attribute
ordering = ('created')
verbose_name_plural class-attribute instance-attribute
verbose_name_plural = 'Pending signups'

ConfirmAccessToken

Bases: Model

Once the user is created, the PendingSignup instance is deleted.

token class-attribute instance-attribute

token = CharField(max_length=6)

user class-attribute instance-attribute

user = ForeignKey(User, on_delete=CASCADE)

created class-attribute instance-attribute

created = DateTimeField(auto_now_add=True)

modified class-attribute instance-attribute

modified = DateTimeField(auto_now=True)

Meta

ordering class-attribute instance-attribute
ordering = ('modified')
verbose_name_plural class-attribute instance-attribute
verbose_name_plural = 'Confirm Access Tokens'