コード例 #1
0
    def delete(self, team_id):
        team = Teams.query.filter_by(id=team_id).first_or_404()

        data = request.get_json()
        user_id = data['id']
        user = Users.query.filter_by(id=user_id).first_or_404()

        if user.team_id == team.id:
            team.members.remove(user)
            db.session.commit()
        else:
            return {
                'success': False,
                'errors': {
                    'id': ['User is not part of this team']
                }
            }, 400

        view = 'admin' if is_admin() else 'user'
        schema = TeamSchema(view=view)
        response = schema.dump(team)

        if response.errors:
            return {'success': False, 'errors': response.errors}, 400

        members = response.data.get('members')

        return {'success': True, 'data': members}
コード例 #2
0
ファイル: teams.py プロジェクト: cydave/CTFd
    def post(self, team_id):
        team = Teams.query.filter_by(id=team_id).first_or_404()

        data = request.get_json()
        user_id = data["user_id"]
        user = Users.query.filter_by(id=user_id).first_or_404()
        if user.team_id is None:
            team.members.append(user)
            db.session.commit()
        else:
            return (
                {
                    "success": False,
                    "errors": {
                        "id": ["User has already joined a team"]
                    },
                },
                400,
            )

        view = "admin" if is_admin() else "user"
        schema = TeamSchema(view=view)
        response = schema.dump(team)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        members = response.data.get("members")

        return {"success": True, "data": members}
コード例 #3
0
ファイル: teams.py プロジェクト: joseMendoza9696/UCB-CTFd
    def delete(self, team_id):
        team = Teams.query.filter_by(id=team_id).first_or_404()

        data = request.get_json()
        user_id = data["user_id"]
        user = Users.query.filter_by(id=user_id).first_or_404()

        if user.team_id == team.id:
            team.members.remove(user)

            # Remove information that links the user to the team
            Submissions.query.filter_by(user_id=user.id).delete()
            Awards.query.filter_by(user_id=user.id).delete()
            Unlocks.query.filter_by(user_id=user.id).delete()

            db.session.commit()
        else:
            return (
                {"success": False, "errors": {"id": ["User is not part of this team"]}},
                400,
            )

        view = "admin" if is_admin() else "user"
        schema = TeamSchema(view=view)
        response = schema.dump(team)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        members = response.data.get("members")

        return {"success": True, "data": members}
コード例 #4
0
    def post(self, team_id):
        team = Teams.query.filter_by(id=team_id).first_or_404()

        data = request.get_json()
        user_id = data['id']
        user = Users.query.filter_by(id=user_id).first_or_404()
        if user.team_id is None:
            team.members.append(user)
            db.session.commit()
        else:
            return {
                'success': False,
                'errors': {
                    'id': ['User has already joined a team']
                }
            }, 400

        view = 'admin' if is_admin() else 'user'
        schema = TeamSchema(view=view)
        response = schema.dump(team)

        if response.errors:
            return {'success': False, 'errors': response.errors}, 400

        members = response.data.get('members')

        return {'success': True, 'data': members}
コード例 #5
0
    def post(self, team_id):
        team = Teams.query.filter_by(id=team_id).first_or_404()

        # Generate an invite code if no user or body is specified
        if len(request.data) == 0:
            invite_code = team.get_invite_code()
            response = {"code": invite_code}
            return {"success": True, "data": response}

        data = request.get_json()
        user_id = data.get("user_id")
        user = Users.query.filter_by(id=user_id).first_or_404()
        if user.team_id is None:
            team.members.append(user)
            db.session.commit()
        else:
            return (
                {
                    "success": False,
                    "errors": {"id": ["User has already joined a team"]},
                },
                400,
            )

        view = "admin" if is_admin() else "user"
        schema = TeamSchema(view=view)
        response = schema.dump(team)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        members = response.data.get("members")

        return {"success": True, "data": members}
コード例 #6
0
ファイル: teams.py プロジェクト: cydave/CTFd
    def get(self, team_id):
        team = Teams.query.filter_by(id=team_id).first_or_404()

        view = "admin" if is_admin() else "user"
        schema = TeamSchema(view=view)
        response = schema.dump(team)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        members = response.data.get("members")

        return {"success": True, "data": members}
コード例 #7
0
    def get(self, team_id):
        team = Teams.query.filter_by(id=team_id).first_or_404()

        view = 'admin' if is_admin() else 'user'
        schema = TeamSchema(view=view)
        response = schema.dump(team)

        if response.errors:
            return {'success': False, 'errors': response.errors}, 400

        members = response.data.get('members')

        return {'success': True, 'data': members}
コード例 #8
0
    def get(self, team_id):
        team = Teams.query.filter_by(id=team_id).first_or_404()

        if (team.banned or team.hidden) and is_admin() is False:
            abort(404)

        view = TeamSchema.views.get(session.get('type', 'user'))
        schema = TeamSchema(view=view)
        response = schema.dump(team)

        if response.errors:
            return {'success': False, 'errors': response.errors}, 400

        return {'success': True, 'data': response.data}
コード例 #9
0
    def get(self, team_id):
        team = Teams.query.filter_by(id=team_id).first_or_404()

        if (team.banned or team.hidden) and is_admin() is False:
            abort(404)

        view = TeamSchema.views.get(session.get("type", "user"))
        schema = TeamSchema(view=view)
        response = schema.dump(team)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        return {"success": True, "data": response.data}
コード例 #10
0
ファイル: teams.py プロジェクト: joseMendoza9696/UCB-CTFd
    def get(self, team_id):
        team = Teams.query.filter_by(id=team_id).first_or_404()

        if (team.banned or team.hidden) and is_admin() is False:
            abort(404)

        user_type = get_current_user_type(fallback="user")
        view = TeamSchema.views.get(user_type)
        schema = TeamSchema(view=view)
        response = schema.dump(team)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        response.data["place"] = team.place
        response.data["score"] = team.score
        return {"success": True, "data": response.data}
コード例 #11
0
ファイル: teams.py プロジェクト: cydave/CTFd
    def patch(self, team_id):
        team = Teams.query.filter_by(id=team_id).first_or_404()
        data = request.get_json()
        data["id"] = team_id

        schema = TeamSchema(view="admin", instance=team, partial=True)

        response = schema.load(data)
        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        response = schema.dump(response.data)
        db.session.commit()
        db.session.close()

        clear_standings()

        return {"success": True, "data": response.data}
コード例 #12
0
ファイル: teams.py プロジェクト: cydave/CTFd
    def post(self):
        req = request.get_json()
        view = TeamSchema.views.get(session.get("type", "self"))
        schema = TeamSchema(view=view)
        response = schema.load(req)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        db.session.add(response.data)
        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        clear_standings()

        return {"success": True, "data": response.data}
コード例 #13
0
    def post(self):
        req = request.get_json()
        view = TeamSchema.views.get(session.get('type', 'self'))
        schema = TeamSchema(view=view)
        response = schema.load(req)

        if response.errors:
            return {'success': False, 'errors': response.errors}, 400

        db.session.add(response.data)
        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        clear_standings()

        return {'success': True, 'data': response.data}