Exemplo n.º 1
0
    def send_join_request(self, roomname: str, username: str) -> None:
        """ Send a join request to the sepcified room
        Args:
            roomname (str): Name of the room to join
            username (str): User that is to requesting to join
        """

        get_members_query = Query.get_room_members(roomname)
        room_members: str = self.db.read_execute_query(get_members_query)[0][0]
        room_members_list = room_members.split()

        if username in room_members_list:
            return

        try:
            get_pending_requests_query = Query.get_pending_requests(roomname)
            pending_requests: str = self.db.read_execute_query(
                get_pending_requests_query)[0][0]
            room_request_query = Query.room_request(roomname, username,
                                                    pending_requests)
            self.db.execute_query(room_request_query)

        except IndexError:
            room_request_query = Query.room_request(roomname, username, "")
            self.db.execute_query(room_request_query)
Exemplo n.º 2
0
 def _accept():
     """Accept the request"""
     get_members_query = Query.get_room_members(roomname)
     room_members: str = self.db.read_execute_query(
         get_members_query)[0][0]
     add_member_query = Query.add_member(roomname, username,
                                         room_members)
     self.db.execute_query(add_member_query)
Exemplo n.º 3
0
    def has_access(self, roomname: str, uid: str) -> bool:
        """ Check if user has access to a room
        Args:
            roomname (str): Name of the room to verify
            uid (str): UID of the user to verify
        Returns:
            bool: True if user has access, False if user does not have access
        """

        if roomname == 'global':
            return True

        try:
            room_exists = self.room_exists(roomname)
            get_username_query = Query.get_username(uid)
            username = self.db.read_execute_query(get_username_query)[0][0]

            if room_exists:
                get_members_query = Query.get_room_members(roomname)
                room_members: str = self.db.read_execute_query(
                    get_members_query)[0][0]
                room_members_list = room_members.split()

                if username in room_members_list:
                    self.logger.debug(
                        f"User with UID = '{uid}' has access to room '{roomname}'"
                    )
                    return True
                else:
                    self.logger.error(
                        f"User with UID = '{uid}' does not have access to room '{roomname}'"
                    )
                    return False
            else:
                self.logger.error(f"Room '{roomname}' does not exist")
                return False

        except:
            self.logger.error(f"Failed to verify room access")
            return False
Exemplo n.º 4
0
    def add_member(self, roomname: str, username: str) -> bool:
        """ Add a user to the room
        Args:
            roomname (str): Name of the room to add user to
            username (str): User to add to room
        Returns:
            bool: True if successfully added, False if not added 
        """

        try:
            room_exists = self.room_exists(roomname)

            if room_exists:
                get_members_query = Query.get_room_members(roomname)
                room_members: str = self.db.read_execute_query(
                    get_members_query)[0][0]
                room_members_list = room_members.split()

                if username in room_members_list:
                    self.logger.warning(
                        f"User '{username}' is already a part of room {roomname}"
                    )
                    return False

                else:
                    add_member_query = Query.add_member(
                        roomname, username, room_members)
                    self.db.execute_query(add_member_query)
                    self.logger.info(f"User '{username}' added to {roomname}")
                    return True

            else:
                self.logger.error(f"Room '{roomname}' does not exist")
                return False

        except:
            self.logger.error(f"Failed to add '{username}' to '{roomname}'")
            return False