Example #1
0
def can_haz_door_access(account, doors=[]):

    # If called with no doors, this basically checks if you are paying member
    # or employed at a company. It is used to show the buttons on the front page
    # for now, in the future, we probably want to make those dependant on access,
    # so you only see buttons you have access to.

    # Employed people have access to all doors for now
    if Company.is_account_employed(account.id):
        return True

    # If you aren't a paying member, you have access to no doors
    # Check paying membership
    if not StripePayment.is_account_paying_member(account.id):
        return False

    # Find all circles the account is a member of, then iterate the doors and check
    memberships = {
        circle.name
        for circle in account_management.get_circles_for_account(account.id)
    }

    for door in doors:
        if not memberships & door.circles:
            # No overlap, so we lack access to this door, lets return false
            return False

    # If we get here, we had access to all doors, so return True
    return True
Example #2
0
def profile_to_json(account: Account,
                    circles: List[Circle],
                    badges: Optional[List[AccountBadge]],
                    full=False):
    from .badge_blueprint import badge_to_json
    json = {
        "account": account_to_json(account),
        "avatar": create_avatar_url(account.email or account.username),
        "circles": {c.id: {
            "id": c.id,
            "name": c.name
        }
                    for c in circles},
        "badges": {b.id: badge_to_json(b)
                   for b in badges} if badges else None,
    }

    if full:
        json["active_member"] = active_member(account)
        json["membership_fee"] = get_membership_fee(account)
        json["has_door_access"] = authz_management.can_haz_door_access(account)
        json["is_paying_member"] = StripePayment.is_account_paying_member(
            account.id)
        json["is_employed"] = Company.is_account_employed(account.id)

    return json
Example #3
0
def active_member(account: Account = None) -> bool:
    """
    Verify that user is an active member of Bitraf either by paying or member of company
    """

    # Check paying membership
    if StripePayment.is_account_paying_member(account.id):
        return True

    # Check company membership
    if Company.is_account_employed(account.id):
        return True

    return False