def _manage_circle_membership(create: bool): username = request.json.get("accountUsername", None) if username is not None: account = Account.get_by_username(username) else: account = Account.get_by_id(request.json["accountId"]) circle = Circle.get_by_id(request.json["circleId"]) admin = flask_login.current_user.account if create: comment = request.json.get("comment", "") account_management.add_account_to_circle(account, circle, admin, comment) else: account_management.remove_account_from_circle(account, circle, admin) db.session.commit() return jsonify(circle_to_json(circle, include_members=True))
def remove_circle(admin: Account, circle: Circle): _assert_can_admin_circle(admin, circle) logger.info("Removing circle, id={}, admin={}".format(circle.id, admin.id)) c = Circle.get_by_id(circle.id) if c.management_style == CircleManagementStyle.SELF_ADMIN: ok = len(c.members) == 1 and c.members[0].account == admin if not ok: raise P2k16UserException( "A circle which is self-administrated must only contain the remover." ) elif c.management_style == CircleManagementStyle.ADMIN_CIRCLE: if len(c.members) != 0: raise P2k16UserException( "The circle has to be empty to be removed.") else: raise P2k16UserException("Unknown management style") Circle.delete_by_id(circle.id)
def data_circle(circle_id): circle = Circle.get_by_id(circle_id) return jsonify(circle_to_json(circle, include_members=True))