diff --git a/README.md b/README.md index 7428371..6e63418 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,18 @@ monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a #### Users Resource (monday.users) - `fetch_users(**kwargs)` - Fetch user information associated with an account. See Monday API docs for a list of accepted keyword arguments. +### Workspaces Resource (monday.workspaces) +- `get_workspaces()` - Get all workspaces. + +- `create_workspace(name, kind, description)` - Create workspace with the given name, kind and description. + +- `add_users_to_workspace(workspace_id, [user_ids], kind)` - Add given users of the given kind to the given workspace. + +- `delete_users_from_workspace(workspace_id, [user_ids])` - Delete given users from the given workspace. + +- `add_teams_to_workspace(workspace_id, [team_ids])` - Add given teams to the given workspace. + +- `delete_teams_from_workspace(workspace_id, [team_ids])` - Delete given teams from the given workspace. ### Groups Resource (monday.groups) - `get_groups_by_board([board_ids])` - Get all groups associated with a certain board or boards. Accepts a single id or a comma separated list of ids. diff --git a/monday/client.py b/monday/client.py index 80d207c..51475eb 100644 --- a/monday/client.py +++ b/monday/client.py @@ -7,7 +7,7 @@ """ from .__version__ import __version__ -from .resources import ItemResource, UpdateResource, TagResource, BoardResource, UserResource, GroupResource, ComplexityResource +from .resources import ItemResource, UpdateResource, TagResource, BoardResource, UserResource, GroupResource, ComplexityResource, WorkspaceResource class MondayClient: @@ -22,6 +22,7 @@ def __init__(self, token): self.users = UserResource(token=token) self.groups = GroupResource(token=token) self.complexity = ComplexityResource(token=token) + self.workspaces = WorkspaceResource(token=token) def __str__(self): return f'MondayClient {__version__}' diff --git a/monday/query_joins.py b/monday/query_joins.py index 86cebc2..1ae8d97 100644 --- a/monday/query_joins.py +++ b/monday/query_joins.py @@ -468,3 +468,69 @@ def get_complexity_query(): }''' return query + +def get_workspaces_query(): + query = ''' + query { + boards { + workspace { + id + name + kind + description + } + } + } + ''' + return query + +def create_workspace_query(name, kind, description=""): + query = ''' + mutation { + create_workspace (name:"%s", kind: %s, description: "%s") { + id + description + } + } + ''' % (name, kind, description) + return query + +def add_users_to_workspace_query(id, user_ids, kind): + query = ''' + mutation { + add_users_to_workspace (workspace_id: %s, user_ids: %s, kind: %s) { + id + } + } + ''' % (id, user_ids, kind) + return query + +def delete_users_from_workspace_query(id, user_ids): + query = ''' + mutation { + add_users_to_workspace (workspace_id: %s, user_ids: %s) { + id + } + } + ''' % (id, user_ids) + return query + +def add_teams_to_workspace_query(id, team_ids): + query = ''' + mutation { + add_teams_to_workspace (workspace_id: %s, team_ids: %s) { + id + } + } + ''' % (id, team_ids) + return query + +def delete_teams_from_workspace_query(id, team_ids): + query = ''' + mutation { + delete_teams_from_workspace (workspace_id: %s, team_ids: %s) { + id + } + } + ''' % (id, team_ids) + return query diff --git a/monday/resources/__init__.py b/monday/resources/__init__.py index d23e134..92bcd5a 100644 --- a/monday/resources/__init__.py +++ b/monday/resources/__init__.py @@ -5,5 +5,6 @@ from .users import UserResource from .groups import GroupResource from .complexity import ComplexityResource +from .workspaces import WorkspaceResource -__all__ = ['ItemResource', 'UpdateResource', 'TagResource', 'BoardResource', 'UserResource', 'GroupResource', 'ComplexityResource'] +__all__ = ['ItemResource', 'UpdateResource', 'TagResource', 'BoardResource', 'UserResource', 'GroupResource', 'ComplexityResource', 'WorkspaceResource'] diff --git a/monday/resources/workspaces.py b/monday/resources/workspaces.py new file mode 100644 index 0000000..b3ce967 --- /dev/null +++ b/monday/resources/workspaces.py @@ -0,0 +1,34 @@ +from monday.resources.base import BaseResource +from monday.query_joins import (get_workspaces_query, create_workspace_query, + add_users_to_workspace_query, delete_users_from_workspace_query, + add_teams_to_workspace_query, delete_teams_from_workspace_query) + + +class WorkspaceResource(BaseResource): + def __init__(self, token): + super().__init__(token) + + def get_workspaces(self): + query = get_workspaces_query() + return self.client.execute(query) + + def create_workspace(self, name, kind, description=""): + query = create_workspace_query(name, kind, description) + return self.client.execute(query) + + def add_users_to_workspace(self, workspace_id, user_ids, kind): + query = add_users_to_workspace_query(workspace_id, user_ids, kind) + return self.client.execute(query) + + def delete_users_from_workspace(self, workspace_id, user_ids): + query = delete_users_from_workspace_query(workspace_id, user_ids) + return self.client.execute(query) + + def add_teams_to_workspace(self, workspace_id, team_ids): + query = add_teams_to_workspace_query(workspace_id, team_ids) + return self.client.execute(query) + + def delete_teams_from_workspace(self, workspace_id, team_ids): + query = delete_teams_from_workspace_query(workspace_id, team_ids) + return self.client.execute(query) + \ No newline at end of file diff --git a/monday/tests/test_case_resource.py b/monday/tests/test_case_resource.py index 0423c26..da86e6b 100644 --- a/monday/tests/test_case_resource.py +++ b/monday/tests/test_case_resource.py @@ -16,3 +16,9 @@ def setUp(self): self.tags = [123, 456, 789] self.subitem_name = "A subitem" self.column_values = {"foo": "bar", "bar": 12} + self.workspace_name = "my_group_workspace" + self.workspace_kind = "open" + self.workspace_id = "123456" + self.workspace_user_kind = "subscriber" + self.team_ids = [105939, 105940, 105941] + diff --git a/monday/tests/test_workspace_resource.py b/monday/tests/test_workspace_resource.py new file mode 100644 index 0000000..1e029ae --- /dev/null +++ b/monday/tests/test_workspace_resource.py @@ -0,0 +1,42 @@ +from monday.tests.test_case_resource import BaseTestCase +from monday.query_joins import (get_workspaces_query, create_workspace_query, + add_users_to_workspace_query, delete_users_from_workspace_query, + add_teams_to_workspace_query, delete_teams_from_workspace_query) + + +class WorkspaceTestCase(BaseTestCase): + def setUp(self): + super(WorkspaceTestCase, self).setUp() + + def test_get_workspaces_query(self): + query = get_workspaces_query() + self.assertIn(query) + + def test_create_workspace_query(self): + query = create_workspace_query(self.workspace_name, self.workspace_kind) + self.assertIn(str(self.workspace_name), query) + self.assertIn(str(self.workspace_kind), query) + + def test_add_users_to_workspace_query(self): + query = add_users_to_workspace_query(self.workspace_id, self.user_ids, self.workspace_user_kind) + self.assertIn(str(self.workspace_id), query) + self.assertIn(str(self.user_ids), query) + self.assertIn(str(self.workspace_user_kind), query) + + def test_delete_users_from_workspace_query(self): + query = delete_users_from_workspace_query(self.workspace_id, self.user_ids) + self.assertIn(str(self.workspace_id), query) + self.assertIn(str(self.user_ids), query) + + def test_add_teams_to_workspace_query(self): + query = add_teams_to_workspace_query(self.workspace_id, self.team_ids) + self.assertIn(str(self.workspace_id), query) + self.assertIn(str(self.team_ids), query) + + def test_delete_teams_from_workspace_query(self): + query = delete_teams_from_workspace_query(self.workspace_id, self.team_ids) + self.assertIn(str(self.workspace_id), query) + self.assertIn(str(self.team_ids), query) + + + \ No newline at end of file