Exemplo n.º 1
0
def new_team():
    result = {"error": None, "data": {}}

    parser = RequestParser()
    parser.argument("members", type=list, default=[], location="json")
    parser.argument("admins", type=list, default=[], location="json")
    parser.argument("description", type=str, required=True)
    parser.argument("name", type=str, required=True)
    parser.argument("slug", type=str, required=True)
    args = parser.parse()

    team = TeamService.get_by_slug(args["slug"])
    if team:
        return abort("team", "slug-exists")

    team = TeamService.create(args["name"], args["slug"], args["description"])

    for username in args["members"]:
        account = helpers.account(username)
        TeamService.add_member(team, account)
        if account.username in args["admins"]:
            PermissionService.add(account, "global", "publishing")

    result["data"] = team.dict(True)
    return result
Exemplo n.º 2
0
def add_member():
    result = {"error": None, "data": {}}

    parser = RequestParser()
    parser.argument("account", type=helpers.account, required=True)
    parser.argument("slug", type=helpers.team, required=True)
    args = parser.parse()

    account = args["account"]
    team = args["slug"]

    TeamService.add_member(team, account)
    result["data"] = team.dict(True)

    return result
Exemplo n.º 3
0
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("members", type=list, default=[], location="json")
        parser.add_argument("admins", type=list, default=[], location="json")
        parser.add_argument("avatar", type=FileStorage, location="files")
        parser.add_argument("description", type=str, required=True)
        parser.add_argument("name", type=str, required=True)
        parser.add_argument("slug", type=str, required=True)
        args = parser.parse_args()

        team = TeamService.get_by_slug(args["slug"])
        if team is not None:
            return abort("team", "slug-exists")

        avatar = None
        if args["avatar"] is not None:
            helper = UploadHelper(request.account, args["avatar"], "avatar")
            data = helper.upload_image()

            if type(data) is Response:
                return data

            avatar = data

        team = TeamService.create(args["name"], args["slug"],
                                  args["description"])

        if avatar is not None:
            TeamService.update_avatar(team, avatar)

        for username in args["members"]:
            account = UserService.get_by_username(username)

            if account is None:
                return abort("account", "not-found")

            TeamService.add_member(team, account)
            if account.username in args["admins"]:
                PermissionService.add(account, "global", "publishing")

        result["data"] = team.dict(True)
        return result
Exemplo n.º 4
0
    def post(self):
        result = {"error": None, "data": {}}

        parser = reqparse.RequestParser()
        parser.add_argument("username", type=str, required=True)
        parser.add_argument("admin", type=bool, default=False)
        parser.add_argument("slug", type=str, required=True)
        args = parser.parse_args()

        team = TeamService.get_by_slug(args["slug"])
        if team is None:
            return abort("team", "not-found")

        account = UserService.get_by_username(args["username"])
        if account is None:
            return abort("account", "not-found")

        TeamService.add_member(team, account)
        if args["admin"]:
            PermissionService.add(account, "global", "publishing")

        result["data"] = team.dict(True)
        return result