Пример #1
0
 def delete(self, username):
     try:
         user = User.get_user(username)
         user.delete()
         return None, 204
     except ValidationError as err:
         return Error(str(err)).to_json(), 400
Пример #2
0
 def get(self, username):
     try:
         user = User.get_user(username)
         result = user_schema.dump(user)
         return Success(result).to_json(), 200
     except ValidationError as err:
         return Error(str(err)).to_json(), 400
Пример #3
0
 def patch(self, username):
     try:
         user = User.get_user(username)
         teams = user_patch_schema.load(request.get_json())["teams"]
         current_app.logger.debug(teams)
         for t in teams:
             team_name = t["name"]
             team = Team.get_team(team_name)
             user._teams.append(team)
         user.save()
         return None, 204
     except ValidationError as err:
         return Error(str(err)).to_json(), 400
Пример #4
0
 def delete(self, team_name, user_name):
     try:
         team = Team.get_team(team_name)
         user = User.get_user(user_name)
         team._members.remove(user)
         team.save()
         return None, 204
     except ValueError:
         return (
             Fail(f"User: {user_name} not found on Team: {team_name}").
             to_json(),
             404,
         )
     except ValidationError as err:
         return Error(str(err)).to_json(), 400
Пример #5
0
 def put(self, username):
     try:
         user = User.get_user(username)
         user._teams = []
         teams = user_put_schema.load(request.get_json())["teams"]
         current_app.logger.debug(teams)
         for t in teams:
             team_name = t["name"]
             team = Team.get_team(team_name)
             if team is None:
                 return Fail(
                     f"Team {team_name} does not exist").to_json(), 400
             user._teams.append(team)
         user.save()
         return None, 204
     except ValidationError as err:
         return Error(str(err)).to_json(), 400
Пример #6
0
 def post(self):
     try:
         data = users_post_schema.load(request.get_json())
         username = data["username"]
         User.validate_non_existance(username)
         new_user = User(username=username)
         teams = data.get("teams")
         if teams is not None and len(teams) > 0:
             for t in teams:
                 team_name = t["name"]
                 team = Team.get_team(team_name)
                 new_user._teams.append(team)
         new_user.save()
         return Success(
             f"user {username} created successfully").to_json(), 201
     except ValidationError as err:
         return Error(str(err)).to_json(), 400
Пример #7
0
 def get(self):
     users = User.get_all()
     users_json = users_schema.dump(users)
     return Success(users_json).to_json(), 200