Source code for org.request

from functools import cached_property
from onegov.core.request import CoreRequest
from import Private
from import TANAccessCollection
from onegov.user import User
from sedate import utcnow

from typing import TYPE_CHECKING
    from import OrgApp
    from onegov.ticket import Ticket

[docs] class OrgRequest(CoreRequest): if TYPE_CHECKING: app: 'OrgApp' @cached_property
[docs] def is_manager(self) -> bool: """ Returns true if the current user is logged in, and has the role editor or admin. """ return self.has_role('admin', 'editor')
[docs] def is_manager_for_model(self, model: object) -> bool: return self.has_permission(model, Private)
[docs] def is_admin(self) -> bool: """ Returns true if the current user is an admin. """ return self.has_role('admin')
[docs] def is_editor(self) -> bool: """ Returns true if the current user is an editor. """ return self.has_role('editor')
[docs] def current_username(self) -> str | None: return self.identity .userid if self.identity else None
[docs] def current_user(self) -> User | None: if not self.identity: return None return ( self.session.query(User) .filter_by(username=self.identity.userid) .first() )
[docs] def first_admin_available(self) -> User | None: return self.session.query(User).filter_by(role='admin').order_by( User.created).first()
[docs] def auto_accept_user(self) -> User | None: username = user: User | None = None if username: user = ( self.session.query(User) .filter_by(username=username, role='admin') .first() ) return user or self.first_admin_available
[docs] def email_for_new_tickets(self) -> str | None: return
[docs] def active_mtan_session(self) -> bool: mtan_verified = self.browser_session.get('mtan_verified') if mtan_verified is None: return False session_duration = if mtan_verified + session_duration < utcnow(): return False return True
[docs] def mtan_accesses(self) -> TANAccessCollection: return TANAccessCollection( self.session, session_id=self.browser_session.mtan_number, )
[docs] def mtan_access_limit_exceeded(self) -> bool: limit = if limit is None: # no limit so we can't exceed it return False # if we're below the limit we're fine if self.mtan_accesses.count() < limit: return False # if we already accessed this url we are also still fine return self.mtan_accesses.by_url(self.path_url) is None
[docs] def auto_accept(self, ticket: 'Ticket') -> bool: if == 'role': roles = if not roles: return False return self.has_role(*roles) return ticket.handler_code in ( or ())