Beispiel #1
0
def add_account_to_circle(account: Account, circle: Circle, admin: Account,
                          comment: str):
    logger.info("Adding %s to circle %s, admin=%s" %
                (account.username, circle.name, admin.username))

    _assert_can_admin_circle(admin, circle)

    circle.add_member(account, comment)
Beispiel #2
0
def add_account_to_circle(account: Account, circle: Circle, admin: Account,
                          comment: str):
    logger.info("Adding %s to circle %s, admin=%s" %
                (account.username, circle.name, admin.username))

    _assert_can_admin_circle(admin, circle)

    if is_account_in_circle(account, circle):
        raise P2k16UserException(
            "Account is already a member of the cirlce, cannot be added again")

    circle.add_member(account, comment)
Beispiel #3
0
def create_circle(name: str,
                  description: str,
                  comment_required_for_membership,
                  management_style: CircleManagementStyle,
                  admin_circle_name: Optional[str] = None,
                  username: Optional[str] = None,
                  comment: Optional[str] = None) -> Circle:
    c = Circle(name, description, comment_required_for_membership,
               management_style)

    if management_style == CircleManagementStyle.ADMIN_CIRCLE:
        if admin_circle_name is None:
            raise P2k16UserException(
                "An admin circle is required when management style is set to ADMIN_CIRCLE"
            )

        admin_circle = Circle.find_by_name(admin_circle_name)

        if admin_circle is None:
            raise P2k16UserException(
                "No such circle: {}".format(admin_circle_name))

        c.admin_circle = admin_circle

    elif management_style == CircleManagementStyle.SELF_ADMIN:
        if username is None:
            raise P2k16UserException(
                "An initial member's username is required when management style is set to "
                "SELF_ADMIN")

        account = Account.find_account_by_username(username)

        if account is None:
            raise P2k16UserException("No such account: {}".format(username))

        c.add_member(account, comment or "")

    db.session.add(c)

    return c