Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/duplicate board query #61

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e9c2d80
Added "create board by workspace id"
albcl Jun 18, 2022
748f418
Update readme
albcl Jun 18, 2022
5480228
Added "duplicate board" query and type hint
albcl Jun 20, 2022
5dc386d
Readme updated
albcl Jun 20, 2022
ed8e29d
Merge pull request #1 from albcl/feature/create_board_by_workspace_id
albcl Jun 29, 2022
873dda3
Added extra parameters for the query
albcl Jun 29, 2022
f9e3a6e
Merge branch 'master' into feature/duplicate_board_query
albcl Jun 29, 2022
d707140
Query and tests updated
albcl Oct 18, 2022
12b6834
Readme update
albcl Oct 18, 2022
f196586
Restructured Readme
albcl Oct 18, 2022
89a5b8c
Added move_item_to_group and archive_item_by_id (#73)
tonymorello Sep 2, 2022
cdeaa30
Add id to payload of get_item_by_id_query (#74)
wbazant Oct 29, 2022
050c32d
Feature/create board by workspace (#60)
albcl Oct 29, 2022
02820ea
bump version
rhymiz Oct 29, 2022
0d41eb5
Create CODE_OF_CONDUCT.md (#78)
rhymiz Dec 1, 2022
0a9b87d
Update README.md
rhymiz Dec 1, 2022
1a30751
docs: add rhymiz as a contributor for code (#79)
allcontributors[bot] Dec 1, 2022
4340a28
docs: add tonymorello as a contributor for code (#80)
allcontributors[bot] Dec 1, 2022
cd885f8
docs: add chdastolfo as a contributor for code (#81)
allcontributors[bot] Dec 1, 2022
1837e1d
docs: add lucioseki as a contributor for code (#84)
allcontributors[bot] Dec 1, 2022
ba4e159
docs: add yogeshnile as a contributor for code (#86)
allcontributors[bot] Dec 1, 2022
af5fa68
docs: add spencersamuel7 as a contributor for code (#88)
allcontributors[bot] Dec 1, 2022
bd9358d
Update .all-contributorsrc
rhymiz Dec 1, 2022
ee25c90
Update README.md
rhymiz Dec 1, 2022
6d5b19b
Update README.md
rhymiz Dec 1, 2022
53faa21
docs: add rhymiz as a contributor for code, bug, and maintenance (#90)
allcontributors[bot] Dec 1, 2022
2153140
docs: add chdastolfo as a contributor for code, bug, and 2 more (#92)
allcontributors[bot] Dec 1, 2022
4e2d9a0
docs: add pevner-p2 as a contributor for code (#93)
allcontributors[bot] Dec 1, 2022
85154c8
1.3.3 (#96)
chdastolfo Dec 8, 2022
a528b00
docs: add t-a-y-l-o-r as a contributor for code (#97)
allcontributors[bot] Dec 8, 2022
fb9adc2
Readme updated
albcl Jun 20, 2022
2b0689e
Update readme
albcl Jun 18, 2022
1d38403
Readme update
albcl Oct 18, 2022
93938a2
Restructured Readme
albcl Oct 18, 2022
9cc8e82
Merge branch 'master' into feature/duplicate_board_query
albcl Dec 9, 2022
17efb51
Tests improved
albcl Dec 14, 2022
2335617
No need to declare variables again
albcl Dec 14, 2022
3b2c1f0
Better type hints and default values
albcl Dec 14, 2022
0b94fb1
Added missing query parameters
albcl Dec 14, 2022
d42b3ec
Added "duplicate board" query and type hint
albcl Jun 20, 2022
8f445d5
Added extra parameters for the query
albcl Jun 29, 2022
11ac7b5
Added "create board by workspace id"
albcl Jun 18, 2022
5120dbc
Query and tests updated
albcl Oct 18, 2022
5027df3
Fix __email__ typo
chdastolfo Dec 15, 2022
0d9cf2f
Bump certifi from 2021.5.30 to 2022.12.7
dependabot[bot] Dec 9, 2022
246bfc7
Convert README.md to .rst for readthedocs
chdastolfo Jan 5, 2023
5226ae0
docs directory and sphinx setup
chdastolfo Jan 6, 2023
d32dd59
Merge branch 'ProdPerfect:master' into feature/duplicate_board_query
albcl Sep 15, 2023
f5cf788
Updated README
albcl Sep 15, 2023
77c9ca3
fix/ missing query after rebasing
albcl Sep 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a
- `limit` - The number of rows returned (*int*. no default).
- `page` - The page number returned, should you implement pagination(*int*. no default).

- `duplicate_board(board_id, duplicate_type, board_name, workspace_id, folder_id, keep_subscribers)` - Duplicate a board by its id. It requires a duplication type to be chosen (*duplicate_board_with_structure / duplicate_board_with_pulses / duplicate_board_with_pulses_and_updates*). Optionaly you can use:
- `board_name` - The duplicated board's name (*string*).
- `workspace_id` - The destination workspace (*int* Defaults to the original board's workspace).
- `folder_id` - The destination folder within the destination workspace. The folder_id is required if you are duplicating to another workspace. (*int* Defaults to originals board's folder).
- `keep_subscribers` - Ability to duplicate the subscribers to the new board (*Boolean* Defaults to false).

- `create_board(board_name, board_kind, workspace_id)` - Create board with the given name and kind by (and optional) workspace id.


Expand Down
44 changes: 42 additions & 2 deletions monday/query_joins.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
import json
from enum import Enum
from typing import List, Union, Optional
from monday.resources.types import BoardKind, BoardState, BoardsOrderBy
from monday.resources.types import BoardKind, BoardState, BoardsOrderBy, DuplicateTypes

from monday.utils import monday_json_stringify, gather_params

Expand Down Expand Up @@ -401,6 +401,46 @@ def get_columns_by_board_query(board_ids):
}''' % board_ids


def duplicate_board_query(
board_id: int,
duplicate_type: DuplicateTypes,
board_name: str = None,
workspace_id: int = None,
folder_id: int = None,
keep_subscribers: bool = None,
) -> str:
board_name = board_name if board_name else ""
workspace_id = workspace_id if workspace_id else None
folder_id = folder_id if folder_id else None
keep_subscribers = keep_subscribers if keep_subscribers else False

params = """board_id: %s, duplicate_type: %s, board_name: \"%s\"""" % (
board_id,
duplicate_type.value,
board_name,
)

if workspace_id:
params += """, workspace_id: %s"""

query = """
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should be indented once more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to move it under the workspace_id condition? That condition is meant to only add to the params variable the workspace_id parameter for the query but it's not a mandatory condition for the query.

However, there is a clear issue there because there isn't a value passed for the %s token, and the test didn't catch it because it was expecting to find a 1 and a 2 within the query, but both are included in the board_id value (Its value is 12) That was a really bad test.

I have updated both the query and its test to fix these issues. I wonder if it had something to do with the merge when the branch was like +20 commits behind...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, now that I look at it again I'm not sure what I was talking about, it looks fine... disregard.

Good catch on test, and ty for fixing.

mutation {
duplicate_board(%s) {
board {
id
groups{
id
}
}
}
}
""" % (
params
)

return query


def create_board_by_workspace_query(board_name: str, board_kind: BoardKind, workspace_id = None) -> str:
workspace_query = f'workspace_id: {workspace_id}' if workspace_id else ''
query = '''
Expand Down
15 changes: 14 additions & 1 deletion monday/resources/boards.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from typing import List, Optional
from monday.resources.base import BaseResource
from monday.query_joins import (
duplicate_board_query,
get_boards_query,
get_boards_by_id_query,
get_board_items_query,
get_columns_by_board_query,
create_board_by_workspace_query,
)
from monday.resources.types import BoardKind, BoardState, BoardsOrderBy
from monday.resources.types import BoardKind, BoardState, BoardsOrderBy, DuplicateTypes


class BoardResource(BaseResource):
Expand All @@ -30,6 +31,18 @@ def fetch_columns_by_board_id(self, board_ids):
query = get_columns_by_board_query(board_ids)
return self.client.execute(query)

def duplicate_board(
self,
board_id: int,
duplicate_type: DuplicateTypes,
board_name: str = None,
workspace_id: int = None,
folder_id: int = None,
keep_subscribers: bool = None,
):
query = duplicate_board_query(board_id, duplicate_type, board_name, workspace_id, folder_id, keep_subscribers)
return self.client.execute(query)

def create_board(self, board_name: str, board_kind: BoardKind, workspace_id: int = None):
query = create_board_by_workspace_query(board_name, board_kind, workspace_id)
return self.client.execute(query)
8 changes: 8 additions & 0 deletions monday/resources/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ class BoardsOrderBy(Enum):

CREATED_AT = "created_at"
USED_AT = "used_at"


class DuplicateTypes(Enum):
"""Board duplication types"""

WITH_STRUCTURE = "duplicate_board_with_structure"
WITH_PULSES = "duplicate_board_with_pulses"
WITH_PULSES_AND_UPDATES = "duplicate_board_with_pulses_and_updates"
16 changes: 14 additions & 2 deletions monday/tests/test_board_resource.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from monday.tests.test_case_resource import BaseTestCase
from monday.query_joins import create_board_by_workspace_query, get_boards_query, get_boards_by_id_query, get_board_items_query, \
get_columns_by_board_query
from monday.query_joins import duplicate_board_query, create_board_by_workspace_query, get_boards_query, get_boards_by_id_query, get_board_items_query, get_columns_by_board_query


class BoardTestCase(BaseTestCase):
Expand Down Expand Up @@ -53,6 +52,19 @@ def test_get_columns_by_board_query(self):
query = get_columns_by_board_query(board_ids=self.board_id)
self.assertIn(str(self.board_id), query)

def test_duplicate_board_query(self):
query_a = duplicate_board_query(board_id=self.board_id, duplicate_type=self.duplicate_type)
self.assertIn(str(self.board_id), query_a)
self.assertNotIn(str(self.duplicate_type), query_a)
self.assertIn(str(self.duplicate_type.value), query_a)
query_b = duplicate_board_query(board_id=self.board_id, duplicate_type=self.duplicate_type, board_name='testing_name', workspace_id=1, folder_id=2)
self.assertIn(str(self.board_id), query_b)
self.assertNotIn(str(self.duplicate_type), query_b)
self.assertIn(str(self.duplicate_type.value), query_b)
self.assertIn(str('testing_name'), query_b)
self.assertIn(str(1), query_b)
self.assertIn(str(2), query_b)

def test_create_board_by_workspace_query(self):
query_a = create_board_by_workspace_query(board_name=self.board_name, board_kind=self.board_kind, workspace_id=self.workspace_id)
self.assertIn(str(self.board_name), query_a)
Expand Down
3 changes: 2 additions & 1 deletion monday/tests/test_case_resource.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from monday.resources.types import BoardKind, BoardState, BoardsOrderBy
from monday.resources.types import BoardKind, BoardState, BoardsOrderBy, DuplicateTypes


class BaseTestCase(unittest.TestCase):
Expand All @@ -11,6 +11,7 @@ def setUp(self):
self.item_id = 24
self.board_name = "my_board"
self.board_id = 12
self.duplicate_type = DuplicateTypes.WITH_PULSES
self.board_kind = BoardKind.PUBLIC
self.board_state = BoardState.ACTIVE
self.boards_order_by = BoardsOrderBy.USED_AT
Expand Down