Пример #1
0
def _data_tool_save():
    circle_name = request.json["circle"]
    circle = Circle.find_by_name(circle_name)

    if not circle:
        raise P2k16UserException("No such circle: {}".format(circle_name))

    _id = request.json.get("id", None)

    if _id:
        tool = ToolDescription.find_by_id(_id)

        if tool is None:
            abort(404)

        logger.info("Updating tool: {}".format(tool))
        tool.name = request.json["name"]
        tool.circle = circle
        tool.description = request.json["description"]
    else:
        logger.info("Creating new tooldescription: {}".format(
            request.json["name"]))
        tool = ToolDescription(request.json["name"],
                               request.json["description"], circle)

    db.session.add(tool)
    db.session.commit()
    db.session.flush()
    logger.info("Update tool: {}".format(tool.name))

    return jsonify(tool_to_json(tool))
Пример #2
0
def _check_is_circle_admin(circle: Circle, admin: Account):
    admin_circle = Circle.find_by_name(circle.name + '-admin')

    if admin_circle is None:
        raise P2k16UserException(
            'There is no admin circle (%s-admin") for circle "%s"'.format(
                circle.name, circle.name))

    if not is_account_in_circle(admin, admin_circle):
        raise P2k16UserException('Account %s is not an administrator of %s' %
                                 (admin.username, circle.description))
Пример #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