rocketchat-API 3.7.1__tar.gz → 3.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.github/actions/test_rocketchat/action.yml +2 -2
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.github/workflows/lint.yml +1 -1
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.github/workflows/release.yml +2 -2
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.github/workflows/test.yml +2 -2
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.github/workflows/test_manually.yml +1 -1
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/PKG-INFO +3 -2
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/README.md +1 -1
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/pyproject.toml +2 -1
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/integrations.py +2 -2
- rocketchat_api-3.8.0/rocketchat_API/APISections/users.py +370 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API.egg-info/PKG-INFO +3 -2
- rocketchat_api-3.8.0/rocketchat_API.egg-info/scm_version.json +8 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_user.py +209 -1
- rocketchat_api-3.7.1/rocketchat_API/APISections/users.py +0 -171
- rocketchat_api-3.7.1/rocketchat_API.egg-info/scm_version.json +0 -8
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.coveragerc +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.deepsource.toml +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.editorconfig +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.github/dependabot.yml +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.github/workflows/test_latest.yml +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/.gitignore +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/CONTRIBUTING.md +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/LICENSE.txt +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/bandit.yml +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/docker-compose.yml +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/qodana.yaml +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APIExceptions/RocketExceptions.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APIExceptions/__init__.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/__init__.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/assets.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/banners.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/base.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/channels.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/chat.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/custom_emoji.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/custom_sounds.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/custom_user_status.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/dm.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/groups.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/invites.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/licenses.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/livechat.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/miscellaneous.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/moderation.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/permissions.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/roles.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/rooms.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/settings.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/statistics.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/subscriptions.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/teams.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/users_engagement.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/__init__.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/rocketchat.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API.egg-info/SOURCES.txt +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API.egg-info/dependency_links.txt +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API.egg-info/requires.txt +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API.egg-info/scm_file_list.json +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API.egg-info/top_level.txt +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/setup.cfg +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/__init__.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/assets/avatar.png +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/assets/avatar.svg +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/assets/logo.png +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/conftest.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_assets.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_banners.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_channels.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_chat.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_custom_emoji.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_custom_sounds.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_custom_user_status.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_dms.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_exceptions.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_groups.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_integrations.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_invites.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_licenses.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_livechat.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_moderation.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_paginated.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_permissions.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_roles.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_rooms.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_server.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_settings.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_subscriptions.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_teams.py +0 -0
- {rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/tests/test_users_engagement.py +0 -0
|
@@ -4,7 +4,7 @@ description: 'Run tests on the Rocket.Chat server'
|
|
|
4
4
|
inputs:
|
|
5
5
|
python-version:
|
|
6
6
|
description: 'The version of Python to use'
|
|
7
|
-
default: '3.
|
|
7
|
+
default: '3.15'
|
|
8
8
|
required: true
|
|
9
9
|
rocket-chat-version:
|
|
10
10
|
description: 'The version of Rocket.Chat to use'
|
|
@@ -35,7 +35,7 @@ runs:
|
|
|
35
35
|
run: pip install .[test]
|
|
36
36
|
- name: Wait for rocket.chat server to be online
|
|
37
37
|
shell: bash
|
|
38
|
-
run: until curl --silent http://localhost:3000/api/info
|
|
38
|
+
run: until curl --silent http://localhost:3000/api/info; do sleep 15; echo "waiting for Rocket.Chat server to start"; done;
|
|
39
39
|
- name: Run tests
|
|
40
40
|
shell: bash
|
|
41
41
|
run: pytest tests rocketchat_API --cov-report xml --cov=./
|
|
@@ -15,10 +15,10 @@ jobs:
|
|
|
15
15
|
steps:
|
|
16
16
|
- name: Checkout
|
|
17
17
|
uses: actions/checkout@v7.0.1
|
|
18
|
-
- name: Set up Python 3.
|
|
18
|
+
- name: Set up Python 3.15
|
|
19
19
|
uses: actions/setup-python@v7
|
|
20
20
|
with:
|
|
21
|
-
python-version: '3.
|
|
21
|
+
python-version: '3.15'
|
|
22
22
|
- name: Install dependencies
|
|
23
23
|
run: |
|
|
24
24
|
python -m pip install --upgrade pip
|
|
@@ -14,8 +14,8 @@ jobs:
|
|
|
14
14
|
strategy:
|
|
15
15
|
fail-fast: false
|
|
16
16
|
matrix:
|
|
17
|
-
python-version: [ '3.
|
|
18
|
-
rocket-chat-version: [ '8.
|
|
17
|
+
python-version: [ '3.11', '3.12', '3.13', '3.14', '3.15' ]
|
|
18
|
+
rocket-chat-version: [ '8.5.5', '8.6.4', '8.7.1', '8.8.2', '8.9.1']
|
|
19
19
|
steps:
|
|
20
20
|
- name: Checkout
|
|
21
21
|
uses: actions/checkout@v7.0.1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rocketchat_API
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.8.0
|
|
4
4
|
Summary: Python API wrapper for Rocket.Chat
|
|
5
5
|
Author-email: "Jorge Alberto Díaz Orozco (Akiel)" <diazorozcoj@gmail.com>
|
|
6
6
|
Maintainer-email: "Jorge Alberto Díaz Orozco (Akiel)" <diazorozcoj@gmail.com>
|
|
@@ -8,6 +8,7 @@ License-Expression: MIT
|
|
|
8
8
|
Project-URL: Homepage, https://github.com/jadolg/rocketchat_API
|
|
9
9
|
Project-URL: Issues, https://github.com/jadolg/rocketchat_API/issues
|
|
10
10
|
Keywords: rocketchat,api,wrapper,rest
|
|
11
|
+
Requires-Python: >=3.11
|
|
11
12
|
Description-Content-Type: text/markdown
|
|
12
13
|
License-File: LICENSE.txt
|
|
13
14
|
Requires-Dist: requests
|
|
@@ -47,7 +48,7 @@ pip install .
|
|
|
47
48
|
|
|
48
49
|
## Requirements
|
|
49
50
|
|
|
50
|
-
- Python 3.
|
|
51
|
+
- Python 3.11 or higher
|
|
51
52
|
- [requests](https://github.com/kennethreitz/requests)
|
|
52
53
|
|
|
53
54
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[build-system]
|
|
2
2
|
requires = [
|
|
3
|
-
"setuptools",
|
|
3
|
+
"setuptools>=61",
|
|
4
4
|
"setuptools_scm",
|
|
5
5
|
]
|
|
6
6
|
build-backend = "setuptools.build_meta"
|
|
@@ -9,6 +9,7 @@ build-backend = "setuptools.build_meta"
|
|
|
9
9
|
name = "rocketchat_API"
|
|
10
10
|
dynamic = ["version"]
|
|
11
11
|
description = "Python API wrapper for Rocket.Chat"
|
|
12
|
+
requires-python = ">=3.11"
|
|
12
13
|
|
|
13
14
|
dependencies = [
|
|
14
15
|
"requests",
|
|
@@ -16,7 +16,7 @@ class RocketChatIntegrations(RocketChatBase):
|
|
|
16
16
|
script_enabled,
|
|
17
17
|
event=None,
|
|
18
18
|
urls=None,
|
|
19
|
-
**kwargs
|
|
19
|
+
**kwargs,
|
|
20
20
|
):
|
|
21
21
|
"""Creates an integration."""
|
|
22
22
|
if integrations_type == "webhook-outgoing":
|
|
@@ -82,7 +82,7 @@ class RocketChatIntegrations(RocketChatBase):
|
|
|
82
82
|
channel,
|
|
83
83
|
script_enabled,
|
|
84
84
|
integration_id,
|
|
85
|
-
**kwargs
|
|
85
|
+
**kwargs,
|
|
86
86
|
):
|
|
87
87
|
"""Updates an existing integration."""
|
|
88
88
|
return self.call_api_put(
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
import mimetypes
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from rocketchat_API.APIExceptions.RocketExceptions import (
|
|
6
|
+
USER_ID_OR_USERNAME_REQUIRED,
|
|
7
|
+
USER_INFO_LOOKUP_REQUIRED,
|
|
8
|
+
RocketMissingParamException,
|
|
9
|
+
)
|
|
10
|
+
from rocketchat_API.APISections.base import (
|
|
11
|
+
RocketChatBase,
|
|
12
|
+
paginated,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
USERS_GET_STATUS = "users.getStatus"
|
|
16
|
+
|
|
17
|
+
USERS_INFO = "users.info"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class RocketChatUsers(RocketChatBase):
|
|
21
|
+
def me(self, **kwargs):
|
|
22
|
+
"""Displays information about the authenticated user."""
|
|
23
|
+
return self.call_api_get("me", kwargs=kwargs)
|
|
24
|
+
|
|
25
|
+
def users_info(
|
|
26
|
+
self,
|
|
27
|
+
user_id=None,
|
|
28
|
+
username=None,
|
|
29
|
+
import_id=None,
|
|
30
|
+
email=None,
|
|
31
|
+
free_switch_extension=None,
|
|
32
|
+
**kwargs,
|
|
33
|
+
):
|
|
34
|
+
"""Gets a user's information, limited to the caller's permissions.
|
|
35
|
+
|
|
36
|
+
Exactly one lookup parameter must be provided. ``email`` requires
|
|
37
|
+
Rocket.Chat >= 8.4.0 and ``free_switch_extension`` requires >= 8.5.0.
|
|
38
|
+
"""
|
|
39
|
+
if user_id:
|
|
40
|
+
return self.call_api_get(USERS_INFO, userId=user_id, kwargs=kwargs)
|
|
41
|
+
if username:
|
|
42
|
+
return self.call_api_get(USERS_INFO, username=username, kwargs=kwargs)
|
|
43
|
+
if import_id:
|
|
44
|
+
return self.call_api_get(USERS_INFO, importId=import_id, kwargs=kwargs)
|
|
45
|
+
if email:
|
|
46
|
+
return self.call_api_get(USERS_INFO, email=email, kwargs=kwargs)
|
|
47
|
+
if free_switch_extension:
|
|
48
|
+
return self.call_api_get(
|
|
49
|
+
USERS_INFO,
|
|
50
|
+
freeSwitchExtension=free_switch_extension,
|
|
51
|
+
kwargs=kwargs,
|
|
52
|
+
)
|
|
53
|
+
raise RocketMissingParamException(USER_INFO_LOOKUP_REQUIRED)
|
|
54
|
+
|
|
55
|
+
@paginated("users")
|
|
56
|
+
def users_list(self, **kwargs):
|
|
57
|
+
"""All of the users and their information, limited to permissions."""
|
|
58
|
+
return self.call_api_get("users.list", kwargs=kwargs)
|
|
59
|
+
|
|
60
|
+
def users_get_presence(self, user_id=None, username=None, **kwargs):
|
|
61
|
+
"""Gets the online presence of the a user."""
|
|
62
|
+
if user_id:
|
|
63
|
+
return self.call_api_get("users.getPresence", userId=user_id, kwargs=kwargs)
|
|
64
|
+
if username:
|
|
65
|
+
return self.call_api_get(
|
|
66
|
+
"users.getPresence", username=username, kwargs=kwargs
|
|
67
|
+
)
|
|
68
|
+
raise RocketMissingParamException(USER_ID_OR_USERNAME_REQUIRED)
|
|
69
|
+
|
|
70
|
+
def users_create(self, email, name, password, username, **kwargs):
|
|
71
|
+
"""Creates a user"""
|
|
72
|
+
return self.call_api_post(
|
|
73
|
+
"users.create",
|
|
74
|
+
email=email,
|
|
75
|
+
name=name,
|
|
76
|
+
password=password,
|
|
77
|
+
username=username,
|
|
78
|
+
kwargs=kwargs,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
def users_delete(self, user_id, **kwargs):
|
|
82
|
+
"""Deletes a user"""
|
|
83
|
+
return self.call_api_post("users.delete", userId=user_id, **kwargs)
|
|
84
|
+
|
|
85
|
+
def users_register(self, email, name, password, username, **kwargs):
|
|
86
|
+
"""Register a new user."""
|
|
87
|
+
return self.call_api_post(
|
|
88
|
+
"users.register",
|
|
89
|
+
email=email,
|
|
90
|
+
name=name,
|
|
91
|
+
password=password,
|
|
92
|
+
username=username,
|
|
93
|
+
kwargs=kwargs,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
def users_get_avatar(self, user_id=None, username=None, **kwargs):
|
|
97
|
+
"""Gets the URL for a user's avatar."""
|
|
98
|
+
if user_id:
|
|
99
|
+
return self.call_api_get("users.getAvatar", userId=user_id, kwargs=kwargs)
|
|
100
|
+
if username:
|
|
101
|
+
return self.call_api_get(
|
|
102
|
+
"users.getAvatar", username=username, kwargs=kwargs
|
|
103
|
+
)
|
|
104
|
+
raise RocketMissingParamException(USER_ID_OR_USERNAME_REQUIRED)
|
|
105
|
+
|
|
106
|
+
def users_set_avatar(self, avatar_url, **kwargs):
|
|
107
|
+
"""Set a user's avatar"""
|
|
108
|
+
if avatar_url.startswith(("http://", "https://")):
|
|
109
|
+
return self.call_api_post(
|
|
110
|
+
"users.setAvatar", avatarUrl=avatar_url, kwargs=kwargs
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
avatar_file = {
|
|
114
|
+
"image": (
|
|
115
|
+
os.path.basename(avatar_url),
|
|
116
|
+
open(avatar_url, "rb"),
|
|
117
|
+
mimetypes.guess_type(avatar_url)[0],
|
|
118
|
+
),
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return self.call_api_post("users.setAvatar", files=avatar_file, kwargs=kwargs)
|
|
122
|
+
|
|
123
|
+
def users_reset_avatar(self, user_id=None, username=None, **kwargs):
|
|
124
|
+
"""
|
|
125
|
+
Reset a user's avatar to the default icon. By default, icons contain the user's initials. Permissions required, if the setting AllowUserAvatarChange is enabled:
|
|
126
|
+
- edit-other-user-avatar: Permission to change other user's avatar
|
|
127
|
+
- manage-moderation-actions: Permission to manage moderation actions, perform actions on reported users
|
|
128
|
+
"""
|
|
129
|
+
if user_id:
|
|
130
|
+
return self.call_api_post(
|
|
131
|
+
"users.resetAvatar", userId=user_id, kwargs=kwargs
|
|
132
|
+
)
|
|
133
|
+
if username:
|
|
134
|
+
return self.call_api_post(
|
|
135
|
+
"users.resetAvatar", username=username, kwargs=kwargs
|
|
136
|
+
)
|
|
137
|
+
raise RocketMissingParamException(USER_ID_OR_USERNAME_REQUIRED)
|
|
138
|
+
|
|
139
|
+
def users_create_token(self, user_id, secret, **kwargs):
|
|
140
|
+
"""Create a user authentication token."""
|
|
141
|
+
return self.call_api_post(
|
|
142
|
+
"users.createToken", userId=user_id, secret=secret, kwargs=kwargs
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
def users_update(self, user_id, **kwargs):
|
|
146
|
+
"""Update an existing user."""
|
|
147
|
+
return self.call_api_post("users.update", userId=user_id, data=kwargs)
|
|
148
|
+
|
|
149
|
+
def users_set_active_status(self, user_id, active_status, **kwargs):
|
|
150
|
+
"""Update user active status."""
|
|
151
|
+
return self.call_api_post(
|
|
152
|
+
"users.setActiveStatus",
|
|
153
|
+
userId=user_id,
|
|
154
|
+
activeStatus=active_status,
|
|
155
|
+
kwargs=kwargs,
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
def users_forgot_password(self, email, **kwargs):
|
|
159
|
+
"""Send email to reset your password."""
|
|
160
|
+
return self.call_api_post("users.forgotPassword", email=email, kwargs=kwargs)
|
|
161
|
+
|
|
162
|
+
def users_get_preferences(self, **kwargs):
|
|
163
|
+
"""Gets all preferences of user."""
|
|
164
|
+
return self.call_api_get("users.getPreferences", kwargs=kwargs)
|
|
165
|
+
|
|
166
|
+
def users_set_preferences(self, user_id, data, **kwargs):
|
|
167
|
+
"""Set user's preferences."""
|
|
168
|
+
return self.call_api_post(
|
|
169
|
+
"users.setPreferences", userId=user_id, data=data, kwargs=kwargs
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
def users_set_status(self, message, **kwargs):
|
|
173
|
+
"""Sets a user Status when the status message and state is given."""
|
|
174
|
+
return self.call_api_post("users.setStatus", message=message, kwargs=kwargs)
|
|
175
|
+
|
|
176
|
+
@paginated("users")
|
|
177
|
+
def users_list_by_status(self, **kwargs):
|
|
178
|
+
"""Lists users filtered by status, role or search term.
|
|
179
|
+
|
|
180
|
+
Accepts ``status`` (active or deactivated), ``hasLoggedIn``, ``type``,
|
|
181
|
+
``roles``, ``searchTerm`` and ``inactiveReason``. Requires ``view-d-room``,
|
|
182
|
+
and ``view-outside-room`` when Apply_permission_view-outside-room is on.
|
|
183
|
+
"""
|
|
184
|
+
return self.call_api_get("users.listByStatus", kwargs=kwargs)
|
|
185
|
+
|
|
186
|
+
def users_get_username_suggestion(self, **kwargs):
|
|
187
|
+
"""Gets a free username suggestion for the authenticated user."""
|
|
188
|
+
return self.call_api_get("users.getUsernameSuggestion", kwargs=kwargs)
|
|
189
|
+
|
|
190
|
+
def users_get_avatar_suggestion(self, **kwargs):
|
|
191
|
+
"""Gets avatar suggestions from the user's connected OAuth services."""
|
|
192
|
+
return self.call_api_get("users.getAvatarSuggestion", kwargs=kwargs)
|
|
193
|
+
|
|
194
|
+
def users_check_username_availability(self, username, **kwargs):
|
|
195
|
+
"""Checks whether a username is available."""
|
|
196
|
+
return self.call_api_get(
|
|
197
|
+
"users.checkUsernameAvailability", username=username, kwargs=kwargs
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
def users_presence(self, **kwargs):
|
|
201
|
+
"""Gets the presence of users.
|
|
202
|
+
|
|
203
|
+
Accepts ``ids`` and ``from`` (ISO 8601 datetime). Without ``from``, the
|
|
204
|
+
presence of all users is returned.
|
|
205
|
+
"""
|
|
206
|
+
return self.call_api_get("users.presence", kwargs=kwargs)
|
|
207
|
+
|
|
208
|
+
def users_autocomplete(self, selector, **kwargs):
|
|
209
|
+
"""Autocompletes users. ``selector`` is a JSON string, e.g. ``{"term": "ab"}``."""
|
|
210
|
+
return self.call_api_get("users.autocomplete", selector=selector, kwargs=kwargs)
|
|
211
|
+
|
|
212
|
+
def users_get_status(self, user_id=None, username=None, **kwargs):
|
|
213
|
+
"""Gets the status of a user by ``user_id`` or ``username``.
|
|
214
|
+
|
|
215
|
+
Returns the authenticated user's status if neither is given.
|
|
216
|
+
"""
|
|
217
|
+
if user_id:
|
|
218
|
+
return self.call_api_get(USERS_GET_STATUS, userId=user_id, kwargs=kwargs)
|
|
219
|
+
if username:
|
|
220
|
+
return self.call_api_get(USERS_GET_STATUS, username=username, kwargs=kwargs)
|
|
221
|
+
return self.call_api_get(USERS_GET_STATUS, kwargs=kwargs)
|
|
222
|
+
|
|
223
|
+
def users_list_teams(self, user_id, **kwargs):
|
|
224
|
+
"""Lists the teams a user belongs to. Seeing all of them needs view-all-teams."""
|
|
225
|
+
return self.call_api_get("users.listTeams", userId=user_id, kwargs=kwargs)
|
|
226
|
+
|
|
227
|
+
def users_generate_personal_access_token(self, token_name, **kwargs):
|
|
228
|
+
"""Generates a personal access token. Accepts ``bypassTwoFactor``.
|
|
229
|
+
|
|
230
|
+
Requires ``create-personal-access-tokens`` and 2FA.
|
|
231
|
+
"""
|
|
232
|
+
return self.call_api_post(
|
|
233
|
+
"users.generatePersonalAccessToken", tokenName=token_name, kwargs=kwargs
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
def users_regenerate_personal_access_token(self, token_name, **kwargs):
|
|
237
|
+
"""Regenerates an existing personal access token.
|
|
238
|
+
|
|
239
|
+
Requires ``create-personal-access-tokens`` and 2FA.
|
|
240
|
+
"""
|
|
241
|
+
return self.call_api_post(
|
|
242
|
+
"users.regeneratePersonalAccessToken", tokenName=token_name, kwargs=kwargs
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
def users_get_personal_access_tokens(self, **kwargs):
|
|
246
|
+
"""Lists the personal access tokens of the authenticated user.
|
|
247
|
+
|
|
248
|
+
Requires ``create-personal-access-tokens``.
|
|
249
|
+
"""
|
|
250
|
+
return self.call_api_get("users.getPersonalAccessTokens", kwargs=kwargs)
|
|
251
|
+
|
|
252
|
+
def users_remove_personal_access_token(self, token_name, **kwargs):
|
|
253
|
+
"""Removes a personal access token.
|
|
254
|
+
|
|
255
|
+
Requires ``create-personal-access-tokens`` and 2FA.
|
|
256
|
+
"""
|
|
257
|
+
return self.call_api_post(
|
|
258
|
+
"users.removePersonalAccessToken", tokenName=token_name, kwargs=kwargs
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
def users_request_data_download(self, full_export=False, **kwargs):
|
|
262
|
+
"""Requests an export of the authenticated user's data.
|
|
263
|
+
|
|
264
|
+
The User Data Download feature must be configured in the workspace.
|
|
265
|
+
"""
|
|
266
|
+
return self.call_api_get(
|
|
267
|
+
"users.requestDataDownload",
|
|
268
|
+
fullExport=str(full_export).lower(),
|
|
269
|
+
kwargs=kwargs,
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
def users_deactivate_idle(self, days_idle, **kwargs):
|
|
273
|
+
"""Deactivates users idle for ``days_idle`` days. Accepts ``role``.
|
|
274
|
+
|
|
275
|
+
Requires ``edit-other-user-active-status``.
|
|
276
|
+
"""
|
|
277
|
+
return self.call_api_post(
|
|
278
|
+
"users.deactivateIdle", daysIdle=days_idle, kwargs=kwargs
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
def users_send_confirmation_email(self, email, **kwargs):
|
|
282
|
+
"""Sends the email verification again. Rate limited to one per 60 seconds."""
|
|
283
|
+
return self.call_api_post(
|
|
284
|
+
"users.sendConfirmationEmail", email=email, kwargs=kwargs
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
def users_update_own_basic_info(self, data, **kwargs):
|
|
288
|
+
"""Updates the authenticated user's own profile. Accepts ``customFields``."""
|
|
289
|
+
return self.call_api_post("users.updateOwnBasicInfo", data=data, kwargs=kwargs)
|
|
290
|
+
|
|
291
|
+
def users_2fa_send_email_code(self, email_or_username, **kwargs):
|
|
292
|
+
"""Sends an email 2FA code to the user."""
|
|
293
|
+
return self.call_api_post(
|
|
294
|
+
"users.2fa.sendEmailCode", emailOrUsername=email_or_username, kwargs=kwargs
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
def users_2fa_enable_email(self, **kwargs):
|
|
298
|
+
"""Enables email 2FA. The user must have a verified email."""
|
|
299
|
+
return self.call_api_post("users.2fa.enableEmail", kwargs=kwargs)
|
|
300
|
+
|
|
301
|
+
def users_2fa_disable_email(self, **kwargs):
|
|
302
|
+
"""Disables email 2FA. Requires a 2FA code."""
|
|
303
|
+
return self.call_api_post("users.2fa.disableEmail", kwargs=kwargs)
|
|
304
|
+
|
|
305
|
+
def users_enable_totp(self, **kwargs):
|
|
306
|
+
"""Starts TOTP setup, returns the ``secret`` and a ``url`` for the QR code.
|
|
307
|
+
|
|
308
|
+
Finish it with ``users_validate_totp``. Requires 2FA.
|
|
309
|
+
"""
|
|
310
|
+
return self.call_api_post("users.enableTotp", kwargs=kwargs)
|
|
311
|
+
|
|
312
|
+
def users_validate_totp(self, code, **kwargs):
|
|
313
|
+
"""Finishes TOTP setup with a code from the app, returns the backup codes."""
|
|
314
|
+
return self.call_api_post("users.validateTotp", code=code, kwargs=kwargs)
|
|
315
|
+
|
|
316
|
+
def users_disable_totp(self, code, **kwargs):
|
|
317
|
+
"""Disables TOTP."""
|
|
318
|
+
return self.call_api_post("users.disableTotp", code=code, kwargs=kwargs)
|
|
319
|
+
|
|
320
|
+
def users_regenerate_totp_codes(self, code, **kwargs):
|
|
321
|
+
"""Regenerates the TOTP backup codes. The previous ones stop working."""
|
|
322
|
+
return self.call_api_post("users.regenerateTotpCodes", code=code, kwargs=kwargs)
|
|
323
|
+
|
|
324
|
+
def users_totp_codes_remaining(self, **kwargs):
|
|
325
|
+
"""Gets how many TOTP backup codes are left."""
|
|
326
|
+
return self.call_api_get("users.totpCodesRemaining", kwargs=kwargs)
|
|
327
|
+
|
|
328
|
+
def users_reset_totp(self, **kwargs):
|
|
329
|
+
"""Resets TOTP of a user (``userId`` or ``username``), or your own if omitted.
|
|
330
|
+
|
|
331
|
+
Resetting another user's needs ``edit-other-user-totp``.
|
|
332
|
+
"""
|
|
333
|
+
return self.call_api_post("users.resetTOTP", kwargs=kwargs)
|
|
334
|
+
|
|
335
|
+
def users_reset_e2e_key(self, **kwargs):
|
|
336
|
+
"""Resets E2E key of a user (``userId`` or ``username``), or your own if omitted.
|
|
337
|
+
|
|
338
|
+
Resetting another user's needs ``edit-other-user-e2ee``.
|
|
339
|
+
"""
|
|
340
|
+
return self.call_api_post("users.resetE2EKey", kwargs=kwargs)
|
|
341
|
+
|
|
342
|
+
def users_logout(self, **kwargs):
|
|
343
|
+
"""Logs out the given user (``userId``), or yourself if omitted.
|
|
344
|
+
|
|
345
|
+
Logging out another user needs ``logout-other-user``.
|
|
346
|
+
"""
|
|
347
|
+
return self.call_api_post("users.logout", kwargs=kwargs)
|
|
348
|
+
|
|
349
|
+
def users_logout_other_clients(self, **kwargs):
|
|
350
|
+
"""Logs out all other sessions of the authenticated user."""
|
|
351
|
+
return self.call_api_post("users.logoutOtherClients", kwargs=kwargs)
|
|
352
|
+
|
|
353
|
+
def users_remove_other_tokens(self, **kwargs):
|
|
354
|
+
"""Removes all login tokens except the current one."""
|
|
355
|
+
return self.call_api_post("users.removeOtherTokens", kwargs=kwargs)
|
|
356
|
+
|
|
357
|
+
def users_delete_own_account(self, password, **kwargs):
|
|
358
|
+
"""Deletes the authenticated user's account.
|
|
359
|
+
|
|
360
|
+
Requires the Accounts_AllowDeleteOwnAccount setting. Accepts
|
|
361
|
+
``confirmRelinquish`` to delete it even if it is the last owner of a room.
|
|
362
|
+
"""
|
|
363
|
+
return self.call_api_post(
|
|
364
|
+
"users.deleteOwnAccount",
|
|
365
|
+
body={
|
|
366
|
+
# Rocket.Chat expects the password as a SHA-256 hex digest
|
|
367
|
+
"password": hashlib.sha256(password.encode()).hexdigest(),
|
|
368
|
+
**kwargs,
|
|
369
|
+
},
|
|
370
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rocketchat_API
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.8.0
|
|
4
4
|
Summary: Python API wrapper for Rocket.Chat
|
|
5
5
|
Author-email: "Jorge Alberto Díaz Orozco (Akiel)" <diazorozcoj@gmail.com>
|
|
6
6
|
Maintainer-email: "Jorge Alberto Díaz Orozco (Akiel)" <diazorozcoj@gmail.com>
|
|
@@ -8,6 +8,7 @@ License-Expression: MIT
|
|
|
8
8
|
Project-URL: Homepage, https://github.com/jadolg/rocketchat_API
|
|
9
9
|
Project-URL: Issues, https://github.com/jadolg/rocketchat_API/issues
|
|
10
10
|
Keywords: rocketchat,api,wrapper,rest
|
|
11
|
+
Requires-Python: >=3.11
|
|
11
12
|
Description-Content-Type: text/markdown
|
|
12
13
|
License-File: LICENSE.txt
|
|
13
14
|
Requires-Dist: requests
|
|
@@ -47,7 +48,7 @@ pip install .
|
|
|
47
48
|
|
|
48
49
|
## Requirements
|
|
49
50
|
|
|
50
|
-
- Python 3.
|
|
51
|
+
- Python 3.11 or higher
|
|
51
52
|
- [requests](https://github.com/kennethreitz/requests)
|
|
52
53
|
|
|
53
54
|
|
|
@@ -1,15 +1,50 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import hashlib
|
|
3
|
+
import hmac
|
|
4
|
+
import json
|
|
5
|
+
import struct
|
|
6
|
+
import time
|
|
1
7
|
import uuid
|
|
8
|
+
from types import SimpleNamespace
|
|
2
9
|
|
|
3
10
|
import pytest
|
|
11
|
+
import semver
|
|
4
12
|
|
|
5
13
|
from rocketchat_API.APIExceptions.RocketExceptions import (
|
|
14
|
+
RocketApiException,
|
|
6
15
|
RocketAuthenticationException,
|
|
7
16
|
RocketMissingParamException,
|
|
8
|
-
RocketApiException,
|
|
9
17
|
)
|
|
18
|
+
from rocketchat_API.rocketchat import RocketChat
|
|
10
19
|
from tests.conftest import get_tests_passowrd
|
|
11
20
|
|
|
12
21
|
|
|
22
|
+
def totp_code(secret):
|
|
23
|
+
key = base64.b32decode(secret.upper() + "=" * (-len(secret) % 8))
|
|
24
|
+
digest = hmac.new(
|
|
25
|
+
key, struct.pack(">Q", int(time.time()) // 30), hashlib.sha1
|
|
26
|
+
).digest()
|
|
27
|
+
offset = digest[-1] & 0x0F
|
|
28
|
+
value = struct.unpack(">I", digest[offset : offset + 4])[0] & 0x7FFFFFFF
|
|
29
|
+
return f"{value % 10**6:06d}"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@pytest.fixture
|
|
33
|
+
def temp_user(logged_rocket):
|
|
34
|
+
username = f"tmp_{uuid.uuid4().hex[:10]}"
|
|
35
|
+
created = logged_rocket.users_create(
|
|
36
|
+
f"{username}@domain.com", username, get_tests_passowrd(), username
|
|
37
|
+
)
|
|
38
|
+
user_id = created.get("user").get("_id")
|
|
39
|
+
session = RocketChat(username, get_tests_passowrd())
|
|
40
|
+
yield SimpleNamespace(id=user_id, name=username, rocket=session)
|
|
41
|
+
# The user may already have been removed by the test itself
|
|
42
|
+
try:
|
|
43
|
+
logged_rocket.users_delete(user_id)
|
|
44
|
+
except RocketApiException:
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
|
|
13
48
|
def test_login(logged_rocket, user):
|
|
14
49
|
login = logged_rocket.login(user.name, user.password)
|
|
15
50
|
|
|
@@ -220,3 +255,176 @@ def test_users_list(logged_rocket):
|
|
|
220
255
|
|
|
221
256
|
def test_users_set_status(logged_rocket):
|
|
222
257
|
logged_rocket.users_set_status(message="working on it", status="online")
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def test_users_list_by_status(logged_rocket, user):
|
|
261
|
+
listed = list(logged_rocket.users_list_by_status(status="active"))
|
|
262
|
+
assert user.name in [u.get("username") for u in listed]
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def test_users_get_username_suggestion(logged_rocket):
|
|
266
|
+
assert logged_rocket.users_get_username_suggestion().get("result")
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def test_users_get_avatar_suggestion(logged_rocket):
|
|
270
|
+
assert "suggestions" in logged_rocket.users_get_avatar_suggestion()
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def test_users_check_username_availability(logged_rocket, user):
|
|
274
|
+
free = logged_rocket.users_check_username_availability(uuid.uuid4().hex[:12])
|
|
275
|
+
assert free.get("result") is True
|
|
276
|
+
|
|
277
|
+
taken = logged_rocket.users_check_username_availability("rocket.cat")
|
|
278
|
+
assert taken.get("result") is False
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def test_users_presence(logged_rocket):
|
|
282
|
+
presence = logged_rocket.users_presence()
|
|
283
|
+
assert presence.get("full") is True
|
|
284
|
+
assert "rocket.cat" in [u.get("username") for u in presence.get("users")]
|
|
285
|
+
|
|
286
|
+
by_ids = logged_rocket.users_presence(
|
|
287
|
+
ids=["rocket.cat"], **{"from": "2000-01-01T00:00:00.000Z"}
|
|
288
|
+
)
|
|
289
|
+
assert [u.get("_id") for u in by_ids.get("users")] == ["rocket.cat"]
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def test_users_autocomplete(logged_rocket, user):
|
|
293
|
+
found = logged_rocket.users_autocomplete(json.dumps({"term": user.name}))
|
|
294
|
+
assert user.name in [u.get("username") for u in found.get("items")]
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def test_users_get_status(logged_rocket, user):
|
|
298
|
+
user_id = logged_rocket.me().get("_id")
|
|
299
|
+
|
|
300
|
+
by_id = logged_rocket.users_get_status(user_id=user_id)
|
|
301
|
+
assert by_id.get("_id") == user_id
|
|
302
|
+
assert "status" in by_id
|
|
303
|
+
|
|
304
|
+
by_name = logged_rocket.users_get_status(username=user.name)
|
|
305
|
+
assert by_name.get("_id") == user_id
|
|
306
|
+
|
|
307
|
+
own = logged_rocket.users_get_status()
|
|
308
|
+
assert own.get("_id") == user_id
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def test_users_list_teams(logged_rocket):
|
|
312
|
+
teams = logged_rocket.users_list_teams(logged_rocket.me().get("_id"))
|
|
313
|
+
assert isinstance(teams.get("teams"), list)
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def test_users_personal_access_tokens(logged_rocket):
|
|
317
|
+
token_name = f"token_{uuid.uuid4().hex[:8]}"
|
|
318
|
+
generated = logged_rocket.users_generate_personal_access_token(
|
|
319
|
+
token_name, bypassTwoFactor=True
|
|
320
|
+
)
|
|
321
|
+
assert generated.get("token")
|
|
322
|
+
|
|
323
|
+
listed = logged_rocket.users_get_personal_access_tokens()
|
|
324
|
+
assert token_name in [t.get("name") for t in listed.get("tokens")]
|
|
325
|
+
|
|
326
|
+
regenerated = logged_rocket.users_regenerate_personal_access_token(token_name)
|
|
327
|
+
assert regenerated.get("token")
|
|
328
|
+
assert regenerated.get("token") != generated.get("token")
|
|
329
|
+
|
|
330
|
+
logged_rocket.users_remove_personal_access_token(token_name)
|
|
331
|
+
listed = logged_rocket.users_get_personal_access_tokens()
|
|
332
|
+
assert token_name not in [t.get("name") for t in listed.get("tokens")]
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def test_users_request_data_download(temp_user):
|
|
336
|
+
assert temp_user.rocket.users_request_data_download().get("requested") is True
|
|
337
|
+
assert "requested" in temp_user.rocket.users_request_data_download(full_export=True)
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def test_users_deactivate_idle(logged_rocket):
|
|
341
|
+
assert logged_rocket.users_deactivate_idle(days_idle=36500).get("count") == 0
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def test_users_send_confirmation_email(rocket, logged_rocket, user):
|
|
345
|
+
# TODO: remove the 8.5 branch once Rocket.Chat 8.5 reaches EOL
|
|
346
|
+
version = semver.Version.parse(
|
|
347
|
+
rocket.info()["version"], optional_minor_and_patch=True
|
|
348
|
+
)
|
|
349
|
+
client = logged_rocket if version < semver.Version(8, 6, 0) else rocket
|
|
350
|
+
client.users_send_confirmation_email(user.email)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def test_users_update_own_basic_info(temp_user):
|
|
354
|
+
new_name = f"renamed_{uuid.uuid4().hex[:6]}"
|
|
355
|
+
updated = temp_user.rocket.users_update_own_basic_info(data={"name": new_name})
|
|
356
|
+
assert updated.get("user").get("name") == new_name
|
|
357
|
+
assert temp_user.rocket.me().get("name") == new_name
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def test_users_2fa_email(logged_rocket, temp_user):
|
|
361
|
+
# Email 2FA can only be enabled with a verified email
|
|
362
|
+
logged_rocket.users_update(temp_user.id, verified=True)
|
|
363
|
+
|
|
364
|
+
temp_user.rocket.users_2fa_enable_email()
|
|
365
|
+
temp_user.rocket.users_2fa_send_email_code(temp_user.name)
|
|
366
|
+
|
|
367
|
+
# With 2FA on, protected endpoints reject requests without a code
|
|
368
|
+
with pytest.raises(RocketApiException):
|
|
369
|
+
temp_user.rocket.users_2fa_disable_email()
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def test_users_2fa_send_email_code_and_disable(logged_rocket, temp_user):
|
|
373
|
+
temp_user.rocket.users_2fa_disable_email()
|
|
374
|
+
temp_user.rocket.users_2fa_send_email_code(temp_user.name)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def test_users_totp(temp_user, skip_if_version_under):
|
|
378
|
+
skip_if_version_under("8.8.0")
|
|
379
|
+
enabled = temp_user.rocket.users_enable_totp()
|
|
380
|
+
secret = enabled.get("secret")
|
|
381
|
+
assert secret
|
|
382
|
+
|
|
383
|
+
assert temp_user.rocket.users_validate_totp(totp_code(secret)).get("codes")
|
|
384
|
+
assert temp_user.rocket.users_totp_codes_remaining().get("remaining") is not None
|
|
385
|
+
|
|
386
|
+
regenerated = temp_user.rocket.users_regenerate_totp_codes(totp_code(secret))
|
|
387
|
+
assert regenerated.get("codes")
|
|
388
|
+
|
|
389
|
+
temp_user.rocket.users_disable_totp(totp_code(secret))
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def test_users_reset_totp(logged_rocket, temp_user):
|
|
393
|
+
logged_rocket.users_reset_totp(userId=temp_user.id)
|
|
394
|
+
logged_rocket.users_reset_totp(username=temp_user.name)
|
|
395
|
+
temp_user.rocket.users_reset_totp()
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def test_users_reset_e2e_key(logged_rocket, temp_user):
|
|
399
|
+
logged_rocket.users_reset_e2e_key(userId=temp_user.id)
|
|
400
|
+
logged_rocket.users_reset_e2e_key(username=temp_user.name)
|
|
401
|
+
# Resetting another user's key logs them out
|
|
402
|
+
session = RocketChat(temp_user.name, get_tests_passowrd())
|
|
403
|
+
session.users_reset_e2e_key()
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def test_users_logout_other_clients(temp_user):
|
|
407
|
+
temp_user.rocket.users_logout_other_clients()
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def test_users_remove_other_tokens(temp_user):
|
|
411
|
+
temp_user.rocket.users_remove_other_tokens()
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def test_users_logout(logged_rocket, temp_user):
|
|
415
|
+
logged_rocket.users_logout(userId=temp_user.id)
|
|
416
|
+
with pytest.raises(RocketApiException):
|
|
417
|
+
temp_user.rocket.me()
|
|
418
|
+
|
|
419
|
+
session = RocketChat(temp_user.name, get_tests_passowrd())
|
|
420
|
+
session.users_logout()
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
def test_users_delete_own_account(logged_rocket, temp_user):
|
|
424
|
+
logged_rocket.settings_update("Accounts_AllowDeleteOwnAccount", True)
|
|
425
|
+
try:
|
|
426
|
+
temp_user.rocket.users_delete_own_account(get_tests_passowrd())
|
|
427
|
+
finally:
|
|
428
|
+
logged_rocket.settings_update("Accounts_AllowDeleteOwnAccount", False)
|
|
429
|
+
with pytest.raises(RocketApiException):
|
|
430
|
+
logged_rocket.users_info(user_id=temp_user.id)
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import mimetypes
|
|
2
|
-
import os
|
|
3
|
-
|
|
4
|
-
from rocketchat_API.APIExceptions.RocketExceptions import (
|
|
5
|
-
USER_ID_OR_USERNAME_REQUIRED,
|
|
6
|
-
USER_INFO_LOOKUP_REQUIRED,
|
|
7
|
-
RocketMissingParamException,
|
|
8
|
-
)
|
|
9
|
-
from rocketchat_API.APISections.base import (
|
|
10
|
-
RocketChatBase,
|
|
11
|
-
paginated,
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
USERS_INFO = "users.info"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class RocketChatUsers(RocketChatBase):
|
|
18
|
-
def me(self, **kwargs):
|
|
19
|
-
"""Displays information about the authenticated user."""
|
|
20
|
-
return self.call_api_get("me", kwargs=kwargs)
|
|
21
|
-
|
|
22
|
-
def users_info(
|
|
23
|
-
self,
|
|
24
|
-
user_id=None,
|
|
25
|
-
username=None,
|
|
26
|
-
import_id=None,
|
|
27
|
-
email=None,
|
|
28
|
-
free_switch_extension=None,
|
|
29
|
-
**kwargs,
|
|
30
|
-
):
|
|
31
|
-
"""Gets a user's information, limited to the caller's permissions.
|
|
32
|
-
|
|
33
|
-
Exactly one lookup parameter must be provided. ``email`` requires
|
|
34
|
-
Rocket.Chat >= 8.4.0 and ``free_switch_extension`` requires >= 8.5.0.
|
|
35
|
-
"""
|
|
36
|
-
if user_id:
|
|
37
|
-
return self.call_api_get(USERS_INFO, userId=user_id, kwargs=kwargs)
|
|
38
|
-
if username:
|
|
39
|
-
return self.call_api_get(USERS_INFO, username=username, kwargs=kwargs)
|
|
40
|
-
if import_id:
|
|
41
|
-
return self.call_api_get(USERS_INFO, importId=import_id, kwargs=kwargs)
|
|
42
|
-
if email:
|
|
43
|
-
return self.call_api_get(USERS_INFO, email=email, kwargs=kwargs)
|
|
44
|
-
if free_switch_extension:
|
|
45
|
-
return self.call_api_get(
|
|
46
|
-
USERS_INFO,
|
|
47
|
-
freeSwitchExtension=free_switch_extension,
|
|
48
|
-
kwargs=kwargs,
|
|
49
|
-
)
|
|
50
|
-
raise RocketMissingParamException(USER_INFO_LOOKUP_REQUIRED)
|
|
51
|
-
|
|
52
|
-
@paginated("users")
|
|
53
|
-
def users_list(self, **kwargs):
|
|
54
|
-
"""All of the users and their information, limited to permissions."""
|
|
55
|
-
return self.call_api_get("users.list", kwargs=kwargs)
|
|
56
|
-
|
|
57
|
-
def users_get_presence(self, user_id=None, username=None, **kwargs):
|
|
58
|
-
"""Gets the online presence of the a user."""
|
|
59
|
-
if user_id:
|
|
60
|
-
return self.call_api_get("users.getPresence", userId=user_id, kwargs=kwargs)
|
|
61
|
-
if username:
|
|
62
|
-
return self.call_api_get(
|
|
63
|
-
"users.getPresence", username=username, kwargs=kwargs
|
|
64
|
-
)
|
|
65
|
-
raise RocketMissingParamException(USER_ID_OR_USERNAME_REQUIRED)
|
|
66
|
-
|
|
67
|
-
def users_create(self, email, name, password, username, **kwargs):
|
|
68
|
-
"""Creates a user"""
|
|
69
|
-
return self.call_api_post(
|
|
70
|
-
"users.create",
|
|
71
|
-
email=email,
|
|
72
|
-
name=name,
|
|
73
|
-
password=password,
|
|
74
|
-
username=username,
|
|
75
|
-
kwargs=kwargs,
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
def users_delete(self, user_id, **kwargs):
|
|
79
|
-
"""Deletes a user"""
|
|
80
|
-
return self.call_api_post("users.delete", userId=user_id, **kwargs)
|
|
81
|
-
|
|
82
|
-
def users_register(self, email, name, password, username, **kwargs):
|
|
83
|
-
"""Register a new user."""
|
|
84
|
-
return self.call_api_post(
|
|
85
|
-
"users.register",
|
|
86
|
-
email=email,
|
|
87
|
-
name=name,
|
|
88
|
-
password=password,
|
|
89
|
-
username=username,
|
|
90
|
-
kwargs=kwargs,
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
def users_get_avatar(self, user_id=None, username=None, **kwargs):
|
|
94
|
-
"""Gets the URL for a user's avatar."""
|
|
95
|
-
if user_id:
|
|
96
|
-
return self.call_api_get("users.getAvatar", userId=user_id, kwargs=kwargs)
|
|
97
|
-
if username:
|
|
98
|
-
return self.call_api_get(
|
|
99
|
-
"users.getAvatar", username=username, kwargs=kwargs
|
|
100
|
-
)
|
|
101
|
-
raise RocketMissingParamException(USER_ID_OR_USERNAME_REQUIRED)
|
|
102
|
-
|
|
103
|
-
def users_set_avatar(self, avatar_url, **kwargs):
|
|
104
|
-
"""Set a user's avatar"""
|
|
105
|
-
if avatar_url.startswith("http://") or avatar_url.startswith("https://"):
|
|
106
|
-
return self.call_api_post(
|
|
107
|
-
"users.setAvatar", avatarUrl=avatar_url, kwargs=kwargs
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
avatar_file = {
|
|
111
|
-
"image": (
|
|
112
|
-
os.path.basename(avatar_url),
|
|
113
|
-
open(avatar_url, "rb"),
|
|
114
|
-
mimetypes.guess_type(avatar_url)[0],
|
|
115
|
-
),
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return self.call_api_post("users.setAvatar", files=avatar_file, kwargs=kwargs)
|
|
119
|
-
|
|
120
|
-
def users_reset_avatar(self, user_id=None, username=None, **kwargs):
|
|
121
|
-
"""
|
|
122
|
-
Reset a user's avatar to the default icon. By default, icons contain the user's initials. Permissions required, if the setting AllowUserAvatarChange is enabled:
|
|
123
|
-
- edit-other-user-avatar: Permission to change other user's avatar
|
|
124
|
-
- manage-moderation-actions: Permission to manage moderation actions, perform actions on reported users
|
|
125
|
-
"""
|
|
126
|
-
if user_id:
|
|
127
|
-
return self.call_api_post(
|
|
128
|
-
"users.resetAvatar", userId=user_id, kwargs=kwargs
|
|
129
|
-
)
|
|
130
|
-
if username:
|
|
131
|
-
return self.call_api_post(
|
|
132
|
-
"users.resetAvatar", username=username, kwargs=kwargs
|
|
133
|
-
)
|
|
134
|
-
raise RocketMissingParamException(USER_ID_OR_USERNAME_REQUIRED)
|
|
135
|
-
|
|
136
|
-
def users_create_token(self, user_id, secret, **kwargs):
|
|
137
|
-
"""Create a user authentication token."""
|
|
138
|
-
return self.call_api_post(
|
|
139
|
-
"users.createToken", userId=user_id, secret=secret, kwargs=kwargs
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
def users_update(self, user_id, **kwargs):
|
|
143
|
-
"""Update an existing user."""
|
|
144
|
-
return self.call_api_post("users.update", userId=user_id, data=kwargs)
|
|
145
|
-
|
|
146
|
-
def users_set_active_status(self, user_id, active_status, **kwargs):
|
|
147
|
-
"""Update user active status."""
|
|
148
|
-
return self.call_api_post(
|
|
149
|
-
"users.setActiveStatus",
|
|
150
|
-
userId=user_id,
|
|
151
|
-
activeStatus=active_status,
|
|
152
|
-
kwargs=kwargs,
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
def users_forgot_password(self, email, **kwargs):
|
|
156
|
-
"""Send email to reset your password."""
|
|
157
|
-
return self.call_api_post("users.forgotPassword", email=email, kwargs=kwargs)
|
|
158
|
-
|
|
159
|
-
def users_get_preferences(self, **kwargs):
|
|
160
|
-
"""Gets all preferences of user."""
|
|
161
|
-
return self.call_api_get("users.getPreferences", kwargs=kwargs)
|
|
162
|
-
|
|
163
|
-
def users_set_preferences(self, user_id, data, **kwargs):
|
|
164
|
-
"""Set user's preferences."""
|
|
165
|
-
return self.call_api_post(
|
|
166
|
-
"users.setPreferences", userId=user_id, data=data, kwargs=kwargs
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
def users_set_status(self, message, **kwargs):
|
|
170
|
-
"""Sets a user Status when the status message and state is given."""
|
|
171
|
-
return self.call_api_post("users.setStatus", message=message, kwargs=kwargs)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APIExceptions/RocketExceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/custom_user_status.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rocketchat_api-3.7.1 → rocketchat_api-3.8.0}/rocketchat_API/APISections/users_engagement.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|