Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 65c64eb

Browse filesBrowse files
author
Gauvain Pocentek
committed
Add support for user/group/project filter by custom attribute
Closes python-gitlab#367
1 parent fa52024 commit 65c64eb
Copy full SHA for 65c64eb

File tree

Expand file treeCollapse file tree

3 files changed

+23
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-5
lines changed
Open diff view settings
Collapse file

‎gitlab/__init__.py‎

Copy file name to clipboardExpand all lines: gitlab/__init__.py
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,22 @@ def sanitized_url(url):
642642
return parsed._replace(path=new_path).geturl()
643643

644644
url = self._build_url(path)
645-
params = query_data.copy()
646-
params.update(kwargs)
645+
646+
def copy_dict(dest, src):
647+
for k, v in src.items():
648+
if isinstance(v, dict):
649+
# Transform dict values in new attributes. For example:
650+
# custom_attributes: {'foo', 'bar'} =>
651+
# custom_attributes['foo']: 'bar'
652+
for dict_k, dict_v in v.items():
653+
dest['%s[%s]' % (k, dict_k)] = dict_v
654+
else:
655+
dest[k] = v
656+
657+
params = {}
658+
copy_dict(params, query_data)
659+
copy_dict(params, kwargs)
660+
647661
opts = self._get_session_opts(content_type='application/json')
648662

649663
# don't set the content-type header when uploading files
Collapse file

‎gitlab/v4/objects.py‎

Copy file name to clipboardExpand all lines: gitlab/v4/objects.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class UserManager(CRUDMixin, RESTManager):
253253
_obj_cls = User
254254

255255
_list_filters = ('active', 'blocked', 'username', 'extern_uid', 'provider',
256-
'external', 'search')
256+
'external', 'search', 'custom_attributes')
257257
_create_attrs = (
258258
tuple(),
259259
('email', 'username', 'name', 'password', 'reset_password', 'skype',
@@ -656,7 +656,7 @@ class GroupManager(CRUDMixin, RESTManager):
656656
_path = '/groups'
657657
_obj_cls = Group
658658
_list_filters = ('skip_groups', 'all_available', 'search', 'order_by',
659-
'sort', 'statistics', 'owned')
659+
'sort', 'statistics', 'owned', 'custom_attributes')
660660
_create_attrs = (
661661
('name', 'path'),
662662
('description', 'visibility', 'parent_id', 'lfs_enabled',
@@ -2639,7 +2639,8 @@ class ProjectManager(CRUDMixin, RESTManager):
26392639
)
26402640
_list_filters = ('search', 'owned', 'starred', 'archived', 'visibility',
26412641
'order_by', 'sort', 'simple', 'membership', 'statistics',
2642-
'with_issues_enabled', 'with_merge_requests_enabled')
2642+
'with_issues_enabled', 'with_merge_requests_enabled',
2643+
'custom_attributes')
26432644

26442645

26452646
class Runner(SaveMixin, ObjectDeleteMixin, RESTObject):
Collapse file

‎tools/python_test_v4.py‎

Copy file name to clipboardExpand all lines: tools/python_test_v4.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
attrs = new_user.customattributes.list()
130130
assert(len(attrs) == 0)
131131
attr = new_user.customattributes.set('key', 'value1')
132+
assert(len(gl.users.list(custom_attributes={'key': 'value1'})) == 1)
132133
assert(attr.key == 'key')
133134
assert(attr.value == 'value1')
134135
assert(len(new_user.customattributes.list()) == 1)
@@ -234,6 +235,7 @@
234235
attrs = group2.customattributes.list()
235236
assert(len(attrs) == 0)
236237
attr = group2.customattributes.set('key', 'value1')
238+
assert(len(gl.groups.list(custom_attributes={'key': 'value1'})) == 1)
237239
assert(attr.key == 'key')
238240
assert(attr.value == 'value1')
239241
assert(len(group2.customattributes.list()) == 1)
@@ -303,6 +305,7 @@
303305
attrs = admin_project.customattributes.list()
304306
assert(len(attrs) == 0)
305307
attr = admin_project.customattributes.set('key', 'value1')
308+
assert(len(gl.projects.list(custom_attributes={'key': 'value1'})) == 1)
306309
assert(attr.key == 'key')
307310
assert(attr.value == 'value1')
308311
assert(len(admin_project.customattributes.list()) == 1)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.