Repository: ucfopen/canvasapi (language: python)

Issue:
Terminate user sessions
The user module needs a method to terminate all user sessions.

[Docs](https://canvas.instructure.com/doc/api/users.html#method.users.terminate_sessions)



Discussion / hints:

Fix patch:
diff --git a/AUTHORS.md b/AUTHORS.md
index 6ddcfa4b..adb06d80 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -63,6 +63,7 @@ Patches and Suggestions
 - Lawrence Oks [@ljoks](https://github.com/ljoks)
 - Lee Fent [@lafent](https://github.com/lafent)
 - Leonard Camacho [@lcamacho](https://github.com/lcamacho)
+- Lucas Salas [@lucas-salas](https://github.com/lucas-salas)
 - Mark Lalor [@MarkLalor](https://github.com/MarkLalor)
 - Markus [@elec3647](https://github.com/elec3647)
 - Matthew Fedder [@matthewf-ucsd](https://github.com/matthewf-ucsd)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 318c535d..9cf073f2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,8 @@
 - Rubrics (Thanks, [@bennettscience](https://github.com/bennettscience))
     - Create, Update, and Delete Rubric Assessments
     - Create a Rubric Association
+- Users
+    - Terminate all user sessions (Thanks, [@lucas-salas](https://github.com/lucas-salas))
 
 ### General
 
diff --git a/canvasapi/user.py b/canvasapi/user.py
index 6256f705..6f9adabf 100644
--- a/canvasapi/user.py
+++ b/canvasapi/user.py
@@ -1008,6 +1008,26 @@ def show_observee(self, observee_id, **kwargs):
         )
         return User(self._requester, response.json())
 
+    def terminate_sessions(self, **kwargs):
+        """
+        Terminate all sessions for a user.
+
+        This includes all browser-based sessions and all access tokens,
+        including manually generated ones.
+
+        :calls: `DELETE /api/v1/users/:id/sessions \
+        <https://canvas.instructure.com/doc/api/users.html#method.users.terminate_sessions>`_
+
+        :rtype: str
+        """
+
+        response = self._requester.request(
+            "DELETE",
+            "users/{}/sessions".format(self.id),
+            _kwargs=combine_kwargs(**kwargs),
+        )
+        return response.json()
+
     def update_color(self, asset_string, hexcode, **kwargs):
         """
         Update a custom color for this user for a given context.


Test patch:
diff --git a/tests/fixtures/user.json b/tests/fixtures/user.json
index fc32c5b8..b3e67233 100644
--- a/tests/fixtures/user.json
+++ b/tests/fixtures/user.json
@@ -1280,5 +1280,11 @@
 			}
 		],
 		"status_code": 200
+	},
+	"terminate_sessions": {
+		"method": "DELETE",
+		"endpoint": "users/1/sessions",
+		"data": "ok",
+		"status_code": 200
 	}
 }
diff --git a/tests/test_user.py b/tests/test_user.py
index c7276029..84a8b04d 100644
--- a/tests/test_user.py
+++ b/tests/test_user.py
@@ -656,6 +656,12 @@ def test_create_pairing_code(self, m):
         self.assertIsInstance(pairing_code, PairingCode)
         self.assertEqual("abc123", pairing_code.code)
 
+    # terminate_sessions()
+    def test_terminate_sessions(self, m):
+        register_uris({"user": ["terminate_sessions"]}, m)
+        resp = self.user.terminate_sessions()
+        self.assertEqual(resp, "ok")
+
 
 @requests_mock.Mocker()
 class TestUserDisplay(unittest.TestCase):