@@ -112,6 +112,36 @@ def compound_metrics(self, **kwargs):
112112 return self .gitlab .http_get ('/sidekiq/compound_metrics' , ** kwargs )
113113
114114
115+ class UserCustomAttribute (ObjectDeleteMixin , RESTObject ):
116+ _id_attr = 'key'
117+
118+
119+ class UserCustomAttributeManager (RetrieveMixin , DeleteMixin , RESTManager ):
120+ _path = '/users/%(user_id)s/custom_attributes'
121+ _obj_cls = UserCustomAttribute
122+ _from_parent_attrs = {'user_id' : 'id' }
123+
124+ def set (self , key , value , ** kwargs ):
125+ """Create or update a user attribute.
126+
127+ Args:
128+ key (str): The attribute to update
129+ value (str): The value to set
130+ **kwargs: Extra options to send to the server (e.g. sudo)
131+
132+ Raises:
133+ GitlabAuthenticationError: If authentication is not correct
134+ GitlabSetError: If an error occured
135+
136+ Returns:
137+ UserCustomAttribute: The created/updated user attribute
138+ """
139+ path = '%s/%s' % (self .path , key .replace ('/' , '%2F' ))
140+ data = {'value' : value }
141+ server_data = self .gitlab .http_put (path , post_data = data , ** kwargs )
142+ return self ._obj_cls (self , server_data )
143+
144+
115145class UserEmail (ObjectDeleteMixin , RESTObject ):
116146 _short_print_attr = 'email'
117147
@@ -165,6 +195,7 @@ class UserProjectManager(CreateMixin, RESTManager):
165195class User (SaveMixin , ObjectDeleteMixin , RESTObject ):
166196 _short_print_attr = 'username'
167197 _managers = (
198+ ('customattributes' , 'UserCustomAttributeManager' ),
168199 ('emails' , 'UserEmailManager' ),
169200 ('gpgkeys' , 'UserGPGKeyManager' ),
170201 ('keys' , 'UserKeyManager' ),
0 commit comments