Esempio n. 1
0
    def leave_team(cls, user_data):
        user = Authenticator.authenticate_team(user_data)
        delete_user = TeamDatabaseClient.get_user_in_team_by_ids(
            user.id, user.team_id)

        try:
            TeamDatabaseClient.delete_team_user(delete_user)
            DatabaseClient.commit()
            cls.logger().info(f"User #{user.id} leaved team #{user.team_id}.")
            return SuccessfulTeamMessageResponse(
                "Team leaved!", TeamResponseStatus.REMOVED.value)
        except IntegrityError:
            DatabaseClient.rollback()
            cls.logger().error(
                f"User #{user.id} failing to leave team #{user.team_id}.")
            return UnsuccessfulTeamMessageResponse("Couldn't leave team.")
Esempio n. 2
0
    def delete_user(cls, delete_data):
        user = Authenticator.authenticate_team(delete_data.authentication,
                                               TeamRoles.is_team_moderator)
        delete_user = TeamDatabaseClient.get_user_in_team_by_ids(
            delete_data.delete_id, user.team_id)

        if delete_user is not None:

            if TeamRoles.is_higher_role(user.team_role, delete_user.role):
                try:
                    TeamDatabaseClient.delete_team_user(delete_user)
                    DatabaseClient.commit()
                    cls.logger().info(
                        f"User #{delete_user.user_id} deleted from team #{user.team_id} by user #{user.id}."
                    )
                    return SuccessfulTeamMessageResponse(
                        "User removed!", TeamResponseStatus.REMOVED.value)
                except IntegrityError:
                    DatabaseClient.rollback()
                    cls.logger().error(
                        f"User #{user.id} failed to delete user {delete_user.user_id} from team #{user.team_id}."
                    )
                    return UnsuccessfulTeamMessageResponse(
                        "Couldn't delete user.")
            else:
                cls.logger().info(
                    f"Cannot delete user #{delete_user.user_id} because he's role ({delete_user.role}) "
                    f"is higher than yours.")
                return ForbiddenTeamMessageResponse(
                    "You don't have enough permissions to delete this user.",
                    TeamResponseStatus.NOT_ENOUGH_PERMISSIONS.value)

        else:
            cls.logger().info(
                f"Trying to delete user #{delete_data.delete_id}, who's not part of the team {user.team_id}."
            )
            return NotFoundTeamMessageResponse(
                "Couldn't find user to delete",
                UserResponseStatus.USER_NOT_FOUND.value)