Skip to content

Commit 0f37c4d

Browse files
committed
support for /my/account endpoint
1 parent db5004d commit 0f37c4d

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Changelog
66

77
**Improvements**:
88

9+
- Support for ``get()`` and ``update()`` operations for ``/my/account`` endpoint which doesn't require admin
10+
privileges by using ``me`` as an id, i.e. ``redmine.user.get('me')`` or ``redmine.user.update('me',firstname='John')``
11+
(requires Redmine >= 4.1.0)
912
- News ``create()``, ``update()``, ``delete()`` operations support (requires Redmine >= 4.1.0)
1013
- ResourceSet's ``export()`` method now supports ``columns`` keyword argument which can be either an iterable
1114
of column names, an "all" string which tells Python-Redmine to export all available columns, "all_gui" string

docs/resources/user.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,16 @@ update
293293
... )
294294
True
295295
296+
.. hint::
297+
298+
By default Python-Redmine uses ``/users/ID`` API endpoint which requires admin privileges, it is also
299+
possible to use ``/my/account`` endpoint which doesn't by using ``me`` as an ID (requires Redmine >= 4.1.0):
300+
301+
.. code-block:: python
302+
303+
>>> redmine.user.update('me', firstname='John')
304+
True
305+
296306
save
297307
++++
298308

redminelib/managers/standard.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,24 @@ def _process_create_response(self, request, response):
2323

2424

2525
class UserManager(ResourceManager):
26+
@staticmethod
27+
def _check_custom_url(path):
28+
if path.endswith('/me.json'):
29+
path = '/my/account.json'
30+
31+
return path
32+
33+
def _construct_get_url(self, path):
34+
return super(UserManager, self)._construct_get_url(self._check_custom_url(path))
35+
2636
def _prepare_create_request(self, request):
2737
request = super(UserManager, self)._prepare_create_request(request)
2838
request['send_information'] = request[self.container].pop('send_information', False)
2939
return request
3040

41+
def _construct_update_url(self, path):
42+
return super(UserManager, self)._construct_update_url(self._check_custom_url(path))
43+
3144
def _prepare_update_request(self, request):
3245
request = super(UserManager, self)._prepare_update_request(request)
3346
request['send_information'] = request[self.resource_class.container_update].pop('send_information', False)

tests/test_resources_standard.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,12 @@ def test_user_get(self):
10181018
self.assertEqual(user.id, 1)
10191019
self.assertEqual(user.firstname, 'John')
10201020

1021+
def test_user_get_account(self):
1022+
self.response.json.return_value = responses['user']['get']
1023+
user = self.redmine.user.get('me')
1024+
self.assertEqual(user.firstname, 'John')
1025+
self.assertTrue(self.patch_requests.call_args[0][1].endswith('/my/account.json'))
1026+
10211027
def test_user_all(self):
10221028
self.response.json.return_value = responses['user']['all']
10231029
users = self.redmine.user.all()
@@ -1062,6 +1068,10 @@ def test_user_update(self):
10621068
user.firstname = 'Bar'
10631069
self.assertIsInstance(user.save(), resources.User)
10641070

1071+
def test_user_update_account(self):
1072+
self.redmine.user.update('me', lastname='Foo', firstname='Bar')
1073+
self.assertTrue(self.patch_requests.call_args[0][1].endswith('/my/account.json'))
1074+
10651075
def test_user_update_with_send_information(self):
10661076
import json
10671077
self.response.json.return_value = responses['user']['get']

0 commit comments

Comments
 (0)