summaryrefslogtreecommitdiff
path: root/gitlab/v4
diff options
context:
space:
mode:
authorNejc Habjan <hab.nejc@gmail.com>2021-02-28 08:48:39 +0100
committerGitHub <noreply@github.com>2021-02-28 08:48:39 +0100
commit5bc158d3d4a8ac0d0116fea7cfd33ad897918741 (patch)
treec6a4db79af274a86285f233bf059d5b781644c44 /gitlab/v4
parentb0d75d9e6fd4876446498f0aac97ae3f6ec601d5 (diff)
parente456869d98a1b7d07e6f878a0d6a9719c1b10fd4 (diff)
downloadgitlab-5bc158d3d4a8ac0d0116fea7cfd33ad897918741.tar.gz
Merge pull request #1333 from python-gitlab/feat/user-follow-api
feat(users): add follow/unfollow API
Diffstat (limited to 'gitlab/v4')
-rw-r--r--gitlab/v4/objects/users.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/gitlab/v4/objects/users.py b/gitlab/v4/objects/users.py
index d6643ae..4f14e86 100644
--- a/gitlab/v4/objects/users.py
+++ b/gitlab/v4/objects/users.py
@@ -115,6 +115,8 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject):
_managers = (
("customattributes", "UserCustomAttributeManager"),
("emails", "UserEmailManager"),
+ ("followers_users", "UserFollowersManager"),
+ ("following_users", "UserFollowingManager"),
("events", "UserEventManager"),
("gpgkeys", "UserGPGKeyManager"),
("identityproviders", "UserIdentityProviderManager"),
@@ -147,6 +149,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.
@@ -453,3 +491,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"}