| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 32f7e17 commit 4fb2e43
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -97,3 +97,21 @@ | |||
| 97 | 97 | gl.auth() | |
| 98 | 98 | current_user = gl.user | |
| 99 | 99 | # end currentuser get | |
| 100 | + | ||
| 101 | + # ca list | ||
| 102 | + attrs = user.customeattributes.list() | ||
| 103 | + # end ca list | ||
| 104 | + | ||
| 105 | + # ca get | ||
| 106 | + attr = user.customeattributes.get(attr_key) | ||
| 107 | + # end ca get | ||
| 108 | + | ||
| 109 | + # ca set | ||
| 110 | + attr = user.customeattributes.set(attr_key, attr_value) | ||
| 111 | + # end ca set | ||
| 112 | + | ||
| 113 | + # ca delete | ||
| 114 | + attr.delete() | ||
| 115 | + # or | ||
| 116 | + user.customeattributes.delete(attr_key) | ||
| 117 | + # end ca delete | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,6 +70,42 @@ Block/Unblock a user: | |||
| 70 | 70 | :start-after: # block | |
| 71 | 71 | :end-before: # end block | |
| 72 | 72 | ||
| 73 | + User custom attributes | ||
| 74 | + ====================== | ||
| 75 | + | ||
| 76 | + References | ||
| 77 | + ---------- | ||
| 78 | + | ||
| 79 | + * v4 API: | ||
| 80 | + | ||
| 81 | + + :class:`gitlab.v4.objects.UserCustomAttribute` | ||
| 82 | + + :class:`gitlab.v4.objects.UserCustomAttributeManager` | ||
| 83 | + + :attr:`gitlab.v4.objects.User.customattributes` | ||
| 84 | + | ||
| 85 | + List custom attributes for a user: | ||
| 86 | + | ||
| 87 | + .. literalinclude:: users.py | ||
| 88 | + :start-after: # ca list | ||
| 89 | + :end-before: # end ca list | ||
| 90 | + | ||
| 91 | + Get a custom attribute for a user: | ||
| 92 | + | ||
| 93 | + .. literalinclude:: users.py | ||
| 94 | + :start-after: # ca get | ||
| 95 | + :end-before: # end ca get | ||
| 96 | + | ||
| 97 | + Set (create or update) a custom attribute for a user: | ||
| 98 | + | ||
| 99 | + .. literalinclude:: users.py | ||
| 100 | + :start-after: # ca set | ||
| 101 | + :end-before: # end ca set | ||
| 102 | + | ||
| 103 | + Delete a custom attribute for a user: | ||
| 104 | + | ||
| 105 | + .. literalinclude:: users.py | ||
| 106 | + :start-after: # ca list | ||
| 107 | + :end-before: # end ca list | ||
| 108 | + | ||
| 73 | 109 | Current User | |
| 74 | 110 | ============ | |
| 75 | 111 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,6 +77,10 @@ class GitlabDeleteError(GitlabOperationError): | |||
| 77 | 77 | pass | |
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | + class GitlabSetError(GitlabOperationError): | ||
| 81 | + pass | ||
| 82 | + | ||
| 83 | + | ||
| 80 | 84 | class GitlabProtectError(GitlabOperationError): | |
| 81 | 85 | pass | |
| 82 | 86 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -112,6 +112,36 @@ def compound_metrics(self, **kwargs): | |||
| 112 | 112 | return self.gitlab.http_get('/sidekiq/compound_metrics', **kwargs) | |
| 113 | 113 | ||
| 114 | 114 | ||
| 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 | + | ||
| 115 | 145 | class UserEmail(ObjectDeleteMixin, RESTObject): | |
| 116 | 146 | _short_print_attr = 'email' | |
| 117 | 147 | ||
@@ -165,6 +195,7 @@ class UserProjectManager(CreateMixin, RESTManager): | |||
| 165 | 195 | class User(SaveMixin, ObjectDeleteMixin, RESTObject): | |
| 166 | 196 | _short_print_attr = 'username' | |
| 167 | 197 | _managers = ( | |
| 198 | + ('customattributes', 'UserCustomAttributeManager'), | ||
| 168 | 199 | ('emails', 'UserEmailManager'), | |
| 169 | 200 | ('gpgkeys', 'UserGPGKeyManager'), | |
| 170 | 201 | ('keys', 'UserKeyManager'), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -131,6 +131,20 @@ | |||
| 131 | 131 | email.delete() | |
| 132 | 132 | assert(len(new_user.emails.list()) == 0) | |
| 133 | 133 | ||
| 134 | + # custom attributes | ||
| 135 | + attrs = new_user.customattributes.list() | ||
| 136 | + assert(len(attrs) == 0) | ||
| 137 | + attr = new_user.customattributes.set('key', 'value1') | ||
| 138 | + assert(attr.key == 'key') | ||
| 139 | + assert(attr.value == 'value1') | ||
| 140 | + assert(len(new_user.customattributes.list()) == 1) | ||
| 141 | + attr = new_user.customattributes.set('key', 'value2') | ||
| 142 | + attr = new_user.customattributes.get('key') | ||
| 143 | + assert(attr.value == 'value2') | ||
| 144 | + assert(len(new_user.customattributes.list()) == 1) | ||
| 145 | + attr.delete() | ||
| 146 | + assert(len(new_user.customattributes.list()) == 0) | ||
| 147 | + | ||
| 134 | 148 | new_user.delete() | |
| 135 | 149 | foobar_user.delete() | |
| 136 | 150 | assert(len(gl.users.list()) == 3) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments