Skip to content

Commit b036347

Browse files
committed
feat(user): add status api
1 parent 0256c67 commit b036347

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ MANIFEST
88
docs/_build
99
.testrepository/
1010
.tox
11+
venv/

docs/gl_objects/users.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,44 @@ Delete an SSH key for a user::
250250
# or
251251
key.delete()
252252

253+
Status
254+
======
255+
256+
References
257+
----------
258+
259+
You can manipulate SSH keys for the current user and for the other users if you
260+
are admin.
261+
262+
* v4 API:
263+
264+
+ :class:`gitlab.v4.objects.CurrentUserStatus`
265+
+ :class:`gitlab.v4.objects.CurrentUserStatusManager`
266+
+ :attr:`gitlab.v4.objects.CurrentUser.status`
267+
+ :class:`gitlab.v4.objects.UserStatus`
268+
+ :class:`gitlab.v4.objects.UserStatusManager`
269+
+ :attr:`gitlab.v4.objects.User.status`
270+
271+
* GitLab API: https://docs.gitlab.com/ce/api/users.html#user-status
272+
273+
Examples
274+
--------
275+
276+
Get current user status::
277+
278+
status = user.status.get()
279+
280+
Update the status for the current user::
281+
282+
status = user.status.get()
283+
status.message = "message"
284+
status.emoji = "thumbsup"
285+
status.save()
286+
287+
Get the status of other users::
288+
289+
gl.users.get(1).status.get()
290+
253291
Emails
254292
======
255293

gitlab/v4/objects.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ class UserActivities(RESTObject):
128128
_id_attr = "username"
129129

130130

131+
class UserStatus(RESTObject):
132+
_id_attr = None
133+
_short_print_attr = "message"
134+
135+
136+
class UserStatusManager(GetWithoutIdMixin, RESTManager):
137+
_path = "/users/%(user_id)s/status"
138+
_obj_cls = UserStatus
139+
_from_parent_attrs = {"user_id": "id"}
140+
141+
131142
class UserActivitiesManager(ListMixin, RESTManager):
132143
_path = "/user/activities"
133144
_obj_cls = UserActivities
@@ -186,6 +197,16 @@ class UserKeyManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
186197
_create_attrs = (("title", "key"), tuple())
187198

188199

200+
class UserStatus(RESTObject):
201+
pass
202+
203+
204+
class UserStatusManager(GetWithoutIdMixin, RESTManager):
205+
_path = "/users/%(user_id)s/status"
206+
_obj_cls = UserStatus
207+
_from_parent_attrs = {"user_id": "id"}
208+
209+
189210
class UserImpersonationToken(ObjectDeleteMixin, RESTObject):
190211
pass
191212

@@ -267,11 +288,13 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject):
267288
_managers = (
268289
("customattributes", "UserCustomAttributeManager"),
269290
("emails", "UserEmailManager"),
291+
("status", "UserStatusManager"),
270292
("events", "UserEventManager"),
271293
("gpgkeys", "UserGPGKeyManager"),
272294
("impersonationtokens", "UserImpersonationTokenManager"),
273295
("keys", "UserKeyManager"),
274296
("projects", "UserProjectManager"),
297+
("status", "UserStatusManager"),
275298
)
276299

277300
@cli.register_custom_action("User")
@@ -330,6 +353,7 @@ class UserManager(CRUDMixin, RESTManager):
330353
"external",
331354
"search",
332355
"custom_attributes",
356+
"status",
333357
)
334358
_create_attrs = (
335359
tuple(),
@@ -410,10 +434,22 @@ class CurrentUserKeyManager(RetrieveMixin, CreateMixin, DeleteMixin, RESTManager
410434
_create_attrs = (("title", "key"), tuple())
411435

412436

437+
class CurrentUserStatus(SaveMixin, RESTObject):
438+
_id_attr = None
439+
_short_print_attr = "message"
440+
441+
442+
class CurrentUserStatusManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
443+
_path = "/user/status"
444+
_obj_cls = CurrentUserStatus
445+
_update_attrs = (tuple(), ("emoji", "message"))
446+
447+
413448
class CurrentUser(RESTObject):
414449
_id_attr = None
415450
_short_print_attr = "username"
416451
_managers = (
452+
("status", "CurrentUserStatusManager"),
417453
("emails", "CurrentUserEmailManager"),
418454
("gpgkeys", "CurrentUserGPGKeyManager"),
419455
("keys", "CurrentUserKeyManager"),

tools/python_test_v4.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,3 +911,14 @@
911911
release_test_project.releases.delete(release_tag_name)
912912
assert len(release_test_project.releases.list()) == 0
913913
release_test_project.delete()
914+
915+
# status
916+
message = "Test"
917+
emoji = "thumbsup"
918+
status = gl.user.status.get()
919+
status.message = message
920+
status.emoji = emoji
921+
status.save()
922+
new_status = gl.user.status.get()
923+
assert new_status.message == message
924+
assert new_status.emoji == emoji

0 commit comments

Comments
 (0)