Skip to content

feat(user): add status api #875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ MANIFEST
docs/_build
.testrepository/
.tox
venv/
37 changes: 37 additions & 0 deletions docs/gl_objects/users.rst
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,43 @@ Delete an SSH key for a user::
# or
key.delete()

Status
======

References
----------

You can manipulate the status for the current user and you can read the status of other users.

* v4 API:

+ :class:`gitlab.v4.objects.CurrentUserStatus`
+ :class:`gitlab.v4.objects.CurrentUserStatusManager`
+ :attr:`gitlab.v4.objects.CurrentUser.status`
+ :class:`gitlab.v4.objects.UserStatus`
+ :class:`gitlab.v4.objects.UserStatusManager`
+ :attr:`gitlab.v4.objects.User.status`

* GitLab API: https://docs.gitlab.com/ce/api/users.html#user-status

Examples
--------

Get current user status::

status = user.status.get()

Update the status for the current user::

status = user.status.get()
status.message = "message"
status.emoji = "thumbsup"
status.save()

Get the status of other users::

gl.users.get(1).status.get()

Emails
======

Expand Down
35 changes: 35 additions & 0 deletions gitlab/v4/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ class UserActivities(RESTObject):
_id_attr = "username"


class UserStatus(RESTObject):
_id_attr = None
_short_print_attr = "message"


class UserStatusManager(GetWithoutIdMixin, RESTManager):
_path = "/users/%(user_id)s/status"
_obj_cls = UserStatus
_from_parent_attrs = {"user_id": "id"}


class UserActivitiesManager(ListMixin, RESTManager):
_path = "/user/activities"
_obj_cls = UserActivities
Expand Down Expand Up @@ -186,6 +197,16 @@ class UserKeyManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
_create_attrs = (("title", "key"), tuple())


class UserStatus(RESTObject):
pass


class UserStatusManager(GetWithoutIdMixin, RESTManager):
_path = "/users/%(user_id)s/status"
_obj_cls = UserStatus
_from_parent_attrs = {"user_id": "id"}


class UserImpersonationToken(ObjectDeleteMixin, RESTObject):
pass

Expand Down Expand Up @@ -272,6 +293,7 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject):
("impersonationtokens", "UserImpersonationTokenManager"),
("keys", "UserKeyManager"),
("projects", "UserProjectManager"),
("status", "UserStatusManager"),
)

@cli.register_custom_action("User")
Expand Down Expand Up @@ -330,6 +352,7 @@ class UserManager(CRUDMixin, RESTManager):
"external",
"search",
"custom_attributes",
"status",
)
_create_attrs = (
tuple(),
Expand Down Expand Up @@ -410,10 +433,22 @@ class CurrentUserKeyManager(RetrieveMixin, CreateMixin, DeleteMixin, RESTManager
_create_attrs = (("title", "key"), tuple())


class CurrentUserStatus(SaveMixin, RESTObject):
_id_attr = None
_short_print_attr = "message"


class CurrentUserStatusManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
_path = "/user/status"
_obj_cls = CurrentUserStatus
_update_attrs = (tuple(), ("emoji", "message"))


class CurrentUser(RESTObject):
_id_attr = None
_short_print_attr = "username"
_managers = (
("status", "CurrentUserStatusManager"),
("emails", "CurrentUserEmailManager"),
("gpgkeys", "CurrentUserGPGKeyManager"),
("keys", "CurrentUserKeyManager"),
Expand Down
11 changes: 11 additions & 0 deletions tools/python_test_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,3 +911,14 @@
release_test_project.releases.delete(release_tag_name)
assert len(release_test_project.releases.list()) == 0
release_test_project.delete()

# status
message = "Test"
emoji = "thumbsup"
status = gl.user.status.get()
status.message = message
status.emoji = emoji
status.save()
new_status = gl.user.status.get()
assert new_status.message == message
assert new_status.emoji == emoji