diff options
author | Max Wittig <max.wittig@siemens.com> | 2021-02-25 21:51:13 +0100 |
---|---|---|
committer | Max Wittig <max.wittig@siemens.com> | 2021-02-27 16:33:05 +0100 |
commit | e456869d98a1b7d07e6f878a0d6a9719c1b10fd4 (patch) | |
tree | a21654e7d05a6c668c0214837ba561e070fbbf5f /gitlab/v4 | |
parent | e06c51bcf29492dbc7ef838c35f6ef86a79af261 (diff) | |
download | gitlab-feat/user-follow-api.tar.gz |
feat(users): add follow/unfollow APIfeat/user-follow-api
Diffstat (limited to 'gitlab/v4')
-rw-r--r-- | gitlab/v4/objects/users.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/gitlab/v4/objects/users.py b/gitlab/v4/objects/users.py index c332435..530383d 100644 --- a/gitlab/v4/objects/users.py +++ b/gitlab/v4/objects/users.py @@ -106,6 +106,8 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject): _managers = ( ("customattributes", "UserCustomAttributeManager"), ("emails", "UserEmailManager"), + ("followers_users", "UserFollowersManager"), + ("following_users", "UserFollowingManager"), ("events", "UserEventManager"), ("gpgkeys", "UserGPGKeyManager"), ("identityproviders", "UserIdentityProviderManager"), @@ -138,6 +140,42 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject): return server_data @cli.register_custom_action("User") + @exc.on_http_error(exc.GitlabFollowError) + def follow(self, **kwargs): + """Follow the user. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabFollowError: If the user could not be followed + + Returns: + dict: The new object data (*not* a RESTObject) + """ + path = "/users/%s/follow" % self.id + return self.manager.gitlab.http_post(path, **kwargs) + + @cli.register_custom_action("User") + @exc.on_http_error(exc.GitlabUnfollowError) + def unfollow(self, **kwargs): + """Unfollow the user. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabUnfollowError: If the user could not be followed + + Returns: + dict: The new object data (*not* a RESTObject) + """ + path = "/users/%s/unfollow" % self.id + return self.manager.gitlab.http_post(path, **kwargs) + + @cli.register_custom_action("User") @exc.on_http_error(exc.GitlabUnblockError) def unblock(self, **kwargs): """Unblock the user. @@ -454,3 +492,15 @@ class UserProjectManager(ListMixin, CreateMixin, RESTManager): else: path = "/users/%s/projects" % kwargs["user_id"] return ListMixin.list(self, path=path, **kwargs) + + +class UserFollowersManager(ListMixin, RESTManager): + _path = "/users/%(user_id)s/followers" + _obj_cls = User + _from_parent_attrs = {"user_id": "id"} + + +class UserFollowingManager(ListMixin, RESTManager): + _path = "/users/%(user_id)s/following" + _obj_cls = User + _from_parent_attrs = {"user_id": "id"} |