class User(Entity):
    id: Id
    first_name: str
    last_name: str
    email: Email
    organization: t.List[Organization]
    is_staff: bool  # has additional privileges to invite

    is_active = where('active') == True
    is_deleted = where('active') == False

    @property
    def full_name(self):
        return f"{self.first_name} f{self.last_name}"
예제 #2
0
 def get_by_email(self, email):
     data = self.dao.get(
         where('email') == email &
         entities.User.is_active &
         self.is_from_my_organization
     )
     return entities.User(**data)
예제 #3
0
class InvitationRepo(AbstractRepo):
    dao: IDao = Inject(qualifier=entities.Invitation)
    session: ISession = Inject()

    q_inviter_from_same_organization = where('inviter.organization') == where('organization')
    q_valid_inviter = q_inviter_from_same_organization | where('inviter.is_staff') == True

    def get_by_email(self, email: entities.Email, organization: entities.Organization):
        data = self.dao.get(
            (where('email') == email) &
            (where('organization') == organization)
        )
        return entities.Invitation(**data)

    def get_by_token(self, token: entities.InvitationToken):
        data = self.dao.get(where('token') == token)
        return entities.Invitation(**data)
class Invitation(Entity):
    id: Id('email', 'organization')
    token: InvitationToken
    email: Email
    inviter: User
    organization: Organization
    sent_at: datetime.datetime
    expires_at: datetime.date

    is_inviter_from_same_organization = where('inviter.organization') == where('organization')
    is_valid_inviter = is_inviter_from_same_organization | where('inviter.is_staff') == True

    @property
    def _today(self):
        return datetime.date.today()

    @property
    def is_active(self):
        return self._today <= self.expires_at
예제 #5
0
class UserRepo(AbstractRepo):
    dao: IDao = Inject(qualifier=entities.User)
    session: ISession = Inject()

    is_active = where('active') == True
    is_deleted = where('active') == False

    @property
    def is_from_my_organization(self):
        organization = self.session.user.organization
        return where('organization.id') == organization.id

    def get_by_email(self, email):
        data = self.dao.get(
            where('email') == email &
            entities.User.is_active &
            self.is_from_my_organization
        )
        return entities.User(**data)

    def is_email_taken(self, email):
        return self.dao.exists(where('email') == email)
예제 #6
0
 def get_by_token(self, token: entities.InvitationToken):
     data = self.dao.get(where('token') == token)
     return entities.Invitation(**data)
예제 #7
0
 def get_by_email(self, email: entities.Email, organization: entities.Organization):
     data = self.dao.get(
         (where('email') == email) &
         (where('organization') == organization)
     )
     return entities.Invitation(**data)
예제 #8
0
 def is_email_taken(self, email):
     return self.dao.exists(where('email') == email)
예제 #9
0
 def is_from_my_organization(self):
     organization = self.session.user.organization
     return where('organization.id') == organization.id
def predicate_foo_bar():
    return where('foo') == 'bar'
def predicate_attr_2_sub():
    return (where('attr_1') == 'attr_1') & (where('attr_2') == 'attr_2_sub')
def predicate_attr_2_super():
    return where('attr_2') == 'attr_2_super'