summaryrefslogtreecommitdiff
path: root/gitlab
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2017-11-04 09:10:40 +0100
committerGauvain Pocentek <gauvain@pocentek.net>2017-11-04 09:10:40 +0100
commit4fb2e439803bd55868b91827a5fbaa448f1dff56 (patch)
treed34db7c329b2d9e1a684fb1d7429014c9500d317 /gitlab
parent32f7e17208987fa345670421c333e22ae6aced6a (diff)
downloadgitlab-4fb2e439803bd55868b91827a5fbaa448f1dff56.tar.gz
Add users custome attributes support
Diffstat (limited to 'gitlab')
-rw-r--r--gitlab/exceptions.py4
-rw-r--r--gitlab/v4/objects.py31
2 files changed, 35 insertions, 0 deletions
diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py
index a100395..d95bb08 100644
--- a/gitlab/exceptions.py
+++ b/gitlab/exceptions.py
@@ -77,6 +77,10 @@ class GitlabDeleteError(GitlabOperationError):
pass
+class GitlabSetError(GitlabOperationError):
+ pass
+
+
class GitlabProtectError(GitlabOperationError):
pass
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 5a3f17c..6d7512b 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -112,6 +112,36 @@ class SidekiqManager(RESTManager):
return self.gitlab.http_get('/sidekiq/compound_metrics', **kwargs)
+class UserCustomAttribute(ObjectDeleteMixin, RESTObject):
+ _id_attr = 'key'
+
+
+class UserCustomAttributeManager(RetrieveMixin, DeleteMixin, RESTManager):
+ _path = '/users/%(user_id)s/custom_attributes'
+ _obj_cls = UserCustomAttribute
+ _from_parent_attrs = {'user_id': 'id'}
+
+ def set(self, key, value, **kwargs):
+ """Create or update a user attribute.
+
+ Args:
+ key (str): The attribute to update
+ value (str): The value to set
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabSetError: If an error occured
+
+ Returns:
+ UserCustomAttribute: The created/updated user attribute
+ """
+ path = '%s/%s' % (self.path, key.replace('/', '%2F'))
+ data = {'value': value}
+ server_data = self.gitlab.http_put(path, post_data=data, **kwargs)
+ return self._obj_cls(self, server_data)
+
+
class UserEmail(ObjectDeleteMixin, RESTObject):
_short_print_attr = 'email'
@@ -165,6 +195,7 @@ class UserProjectManager(CreateMixin, RESTManager):
class User(SaveMixin, ObjectDeleteMixin, RESTObject):
_short_print_attr = 'username'
_managers = (
+ ('customattributes', 'UserCustomAttributeManager'),
('emails', 'UserEmailManager'),
('gpgkeys', 'UserGPGKeyManager'),
('keys', 'UserKeyManager'),