]> git.somenet.org - pub/jan/mattermost-api-python.git/commitdiff
Preliminary group support. master
authorSomeone <someone@somenet.org>
Wed, 14 Dec 2022 20:10:05 +0000 (21:10 +0100)
committerSomeone <someone@somenet.org>
Wed, 14 Dec 2022 20:42:26 +0000 (21:42 +0100)
mattermost/__init__.py
mattermost/stdin2channel.py
mattermost/version.py
mattermost/ws.py

index 8f8bf5d02606c694d6e25987b1fa87f140cbd4ef..8e89d9eb97e84c037081418f0918ebc483f17052 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 """
 Someone's Mattermost API v4 bindings.
-  Copyright (c) 2016-2021 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
+  Copyright (c) 2016-2023 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
   published under MIT-License
 """
 
@@ -1495,7 +1495,102 @@ class MMApi:
 #+ **LDAP** #NOT_IMPLEMENTED
 
 ################################################
-#+ **GROUPS** #NOT_IMPLEMENTED
+    def get_groups(self, **kwargs):
+        """
+        Generator: iterates over all groups.
+
+        Returns:
+            generates: One Group at a time.
+
+        Raises:
+            ApiException: Passed on from lower layers.
+        """
+        page = 0
+        while True:
+            data_page = self._get("/v4/groups", params={
+                "page":str(page),
+                "per_page":"200",
+            }, **kwargs)
+
+            if data_page == []:
+                break
+            page += 1
+
+            for data in data_page:
+                yield data
+
+
+
+    def get_users_for_group(self, group_id, **kwargs):
+        """
+        Generator: Get a page of users in a group.
+
+        Args:
+            group_id (string): The group ID to iterate over.
+
+        Returns:
+            generates: Users.
+
+        Raises:
+            ApiException: Passed on from lower layers.
+        """
+        page = 0
+        while True:
+            data_page = self._get("/v4/groups/"+group_id+"/members", params={"page":str(page)}, **kwargs)
+
+            if data_page['members'] == []:
+                break
+            page += 1
+
+            for member in data_page['members']:
+                yield member
+
+
+
+    def add_user_to_group(self, group_id, user_ids, **kwargs):
+        """
+        Generator: Get a page of users in a group. Use the query parameters to modify the behaviour of this endpoint.
+
+        Args:
+            group_id (string): The group ID to add user_id to.
+            user_ids (string/list): The user ID(s) to add group.
+
+        Returns:
+            generates: Post.
+
+        Raises:
+            ApiException: Passed on from lower layers.
+        """
+        if not isinstance(user_ids, list):
+            user_ids = [user_ids]
+
+        return self._post("/v4/groups/"+group_id+"/members", data={"user_ids":user_ids}, **kwargs)
+
+
+
+    def remove_user_from_group(self, group_id, user_ids=None, **kwargs):
+        """
+        Generator: Get a page of users in a group. Use the query parameters to modify the behaviour of this endpoint.
+
+        Args:
+            group_id (string): The group ID to remove the user_id from.
+            user_id (string/list): The user ID(s) to remove from group or None for all.
+
+        Returns:
+            generates: Post.
+
+        Raises:
+            ApiException: Passed on from lower layers.
+        """
+        if user_ids is None:
+            user_ids = [x['id'] for x in self.get_users_for_group(group_id)]
+
+        elif not isinstance(user_ids, list):
+            user_ids = [user_ids]
+
+        return self._delete("/v4/groups/"+group_id+"/members", data={"user_ids":user_ids}, **kwargs)
+
+
 
 ################################################
 #+ **COMPLIANCE** #NOT_IMPLEMENTED
index e43603003fe2d56fa05915737e1ebc634b8e9258..0fec259351e6ccc806248376a9c4d1d2c700fc99 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 """
 Someone's Mattermost API v4 bindings.
-  Copyright (c) 2016-2021 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
+  Copyright (c) 2016-2023 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
   published under MIT-License
 
 post stdin to a channel.
index 68d830fc4eff15da9350b54fae1fb3aa6644a175..97effc8745a78da836fa171b40e5eaa8d1fffbb6 100755 (executable)
@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
 """
 Someone's Mattermost API v4 bindings.
-  Copyright (c) 2016-2021 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
+  Copyright (c) 2016-2023 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
   published under MIT-License
 """
 
 # Set this package's version.
-__version__ = "6.5.0"
+__version__ = "7.5.0"
index 5390c61ea8fb32f117eceda6ba14208102b7bc2a..9079819f8b7e9d6c695ee276175cbb66743770e6 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 """
 Someone's Mattermost API v4 bindings.
-  Copyright (c) 2016-2021 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
+  Copyright (c) 2016-2023 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
   published under MIT-License
 """