@@ -115,6 +115,8 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject):
115115 _managers = (
116116 ("customattributes" , "UserCustomAttributeManager" ),
117117 ("emails" , "UserEmailManager" ),
118+ ("followers_users" , "UserFollowersManager" ),
119+ ("following_users" , "UserFollowingManager" ),
118120 ("events" , "UserEventManager" ),
119121 ("gpgkeys" , "UserGPGKeyManager" ),
120122 ("identityproviders" , "UserIdentityProviderManager" ),
@@ -146,6 +148,42 @@ def block(self, **kwargs):
146148 self ._attrs ["state" ] = "blocked"
147149 return server_data
148150
151+ @cli .register_custom_action ("User" )
152+ @exc .on_http_error (exc .GitlabFollowError )
153+ def follow (self , ** kwargs ):
154+ """Follow the user.
155+
156+ Args:
157+ **kwargs: Extra options to send to the server (e.g. sudo)
158+
159+ Raises:
160+ GitlabAuthenticationError: If authentication is not correct
161+ GitlabFollowError: If the user could not be followed
162+
163+ Returns:
164+ dict: The new object data (*not* a RESTObject)
165+ """
166+ path = "/users/%s/follow" % self .id
167+ return self .manager .gitlab .http_post (path , ** kwargs )
168+
169+ @cli .register_custom_action ("User" )
170+ @exc .on_http_error (exc .GitlabUnfollowError )
171+ def unfollow (self , ** kwargs ):
172+ """Unfollow the user.
173+
174+ Args:
175+ **kwargs: Extra options to send to the server (e.g. sudo)
176+
177+ Raises:
178+ GitlabAuthenticationError: If authentication is not correct
179+ GitlabUnfollowError: If the user could not be followed
180+
181+ Returns:
182+ dict: The new object data (*not* a RESTObject)
183+ """
184+ path = "/users/%s/unfollow" % self .id
185+ return self .manager .gitlab .http_post (path , ** kwargs )
186+
149187 @cli .register_custom_action ("User" )
150188 @exc .on_http_error (exc .GitlabUnblockError )
151189 def unblock (self , ** kwargs ):
@@ -453,3 +491,15 @@ def list(self, **kwargs):
453491 else :
454492 path = "/users/%s/projects" % kwargs ["user_id" ]
455493 return ListMixin .list (self , path = path , ** kwargs )
494+
495+
496+ class UserFollowersManager (ListMixin , RESTManager ):
497+ _path = "/users/%(user_id)s/followers"
498+ _obj_cls = User
499+ _from_parent_attrs = {"user_id" : "id" }
500+
501+
502+ class UserFollowingManager (ListMixin , RESTManager ):
503+ _path = "/users/%(user_id)s/following"
504+ _obj_cls = User
505+ _from_parent_attrs = {"user_id" : "id" }
0 commit comments