trix-solutions/moncli

`get_board_by_id` and `get_board_by_name` only search among active boards

Closed this issue · 3 comments

By default the Monday v2 API only acts on active boards:

# This query returns an empty list
query	{
  boards(ids:[<archived board id>]){
    id
    name
    state
  }
}
# This query returns the board
query	{
  boards(state:all, ids:[<archived board id>]){
    id
    name
    state
  }
}

Moncli's get_boards method allows the user to pass in a state enum to get all boards (both active and archived). However, the get_board_by_id and get_board_by_name methods do not and because they don't set the state to all internally, the methods raise BoardNotFound if the board is archived.

I propose that we change get_board_by_id and get_board_by_name so that they add state=all to the graphql query.
Something like:

def get_board_by_id(self, id: str):

        boards_data = client.get_boards(
            self.__creds.api_key_v2, 
            *GET_BOARD_FIELD_LIST,
            ids=[int(id)],
            limit=1,
            state=State.all)  # <-- New line

        if len(boards_data) == 0:
            raise ex.BoardNotFound('id', id)

        return Board(creds=self.__creds, **boards_data[0])

I'm happy to write a PR for this if you like :)

Hi @alexalligator,

Great suggestion! I believe it best to remain consistent with the get_boards method by passing in the desired state as an input parameter to the class method. The input state method parameter can be set to active by default, but gives the user the option to search for all or archived boards. This would also ensure smooth performance. Fetching every single board may cause complexity issues depending on the size of the system.

def get_board_by_id(self, id: str, state: State = State.active):  # <-- New parameter

        boards_data = client.get_boards(
            self.__creds.api_key_v2, 
            *GET_BOARD_FIELD_LIST,
            ids=[int(id)],
            limit=1,
            state=state)  # <-- New line

        if len(boards_data) == 0:
            raise ex.BoardNotFound('id', id)

        return Board(creds=self.__creds, **boards_data[0])

Please let me know if you have any questions, and thank you very much for your continued involvement!

On further investigation, I see that this is a little more complicated than it first appeared.

There are quite a few other places in the code that call api_v2's get_boards handler.
For example, Board uses it in get_columns, get_groups and get_items. The Group and Item entities also make use of it internally.

If we only update get_board_by_id we will end up with an archived Board that is unable to retrieve its columns, groups and items.

To add this feature I suppose we will have to add the new state: State = State.active param to all these methods?
For example:

class Group():
    def get_items(self, state: State = State.active):
        # ...

Any other ideas?

Hello @alexalligator,

I hope all is well. I must apologize for falling off the wagon. I just took a look at this today and added a check inside of the moncli.api_v2.handlers module to set the query value for state to State.all in the case where no state is provided.

With that being said, if you need to add more customization to your queries that the entities themselves cannot provide, you can use the module I mentioned above to do so. Do bear in mind that you are working entirely with dictionaries at this level.

Thank you for your patience!