diff --git a/pagure/api/group.py b/pagure/api/group.py
index 24aacea..ea718a7 100644
--- a/pagure/api/group.py
+++ b/pagure/api/group.py
@@ -54,15 +54,32 @@ def api_groups():
'''
pattern = flask.request.args.get('pattern', None)
+ extended = flask.request.args.get('extended', None)
+ if str(extended).lower() in ['1', 'true']:
+ extended = True
+ else:
+ extended = False
+
if pattern is not None and not pattern.endswith('*'):
pattern += '*'
groups = pagure.lib.search_groups(SESSION, pattern=pattern)
+ if extended:
+ groups = [
+ {
+ 'name': grp.group_name,
+ 'description': grp.description
+ }
+ for grp in groups
+ ]
+ else:
+ groups = [group.group_name for group in groups]
+
return flask.jsonify(
{
'total_groups': len(groups),
- 'groups': [group.group_name for group in groups]
+ 'groups': groups
}
)
diff --git a/pagure/templates/_browseheader.html b/pagure/templates/_browseheader.html
index cbaaafb..b28bd70 100644
--- a/pagure/templates/_browseheader.html
+++ b/pagure/templates/_browseheader.html
@@ -7,6 +7,7 @@
+
-
@@ -91,9 +91,11 @@ $(document).ready(function() {
});
$('#term').selectize({
- valueField: 'group',
- labelField: 'group',
+ valueField: 'name',
+ labelField: 'name',
searchField: 'group',
+ maxItems: 1,
+ create: false,
onType: function(value){
if (value == ""){
this.close();
@@ -104,18 +106,34 @@ $(document).ready(function() {
$('#headerSearch').submit();
}
},
- maxItems: 1,
- create: false,
load: function(query, callback) {
if (!query.length) return callback();
$.getJSON(
"{{ url_for('api_ns.api_groups') }}", {
- pattern: query
+ pattern: query,
+ extended:1,
},
function( data ) {
- callback( data.groups.map(function(x) { return { group: x }; }) );
+ callback( data.groups );
}
);
+ },
+ render: {
+ option: function(item, escape) {
+ return '
'
+ + '
'
+ + ''
+ + '
'
+ + '
'
+ + ''
+ + '' + escape(item.name) + ''
+ + ''
+ + '
'
+ + '
'
+ + '' + escape(item.description) + ''
+ + '
'
+ + '
';
+ }
}
});
});
diff --git a/pagure/ui/app.py b/pagure/ui/app.py
index 6d5c779..fc48bd2 100644
--- a/pagure/ui/app.py
+++ b/pagure/ui/app.py
@@ -170,6 +170,8 @@ def search():
elif stype == 'projects_forks':
return flask.redirect(flask.url_for(
'view_projects', pattern=term, forks=True))
+ elif stype == 'groups':
+ return flask.redirect(flask.url_for('view_group', group=term))
else:
return flask.redirect(flask.url_for('view_users', username=term))
diff --git a/tests/test_pagure_flask_api_group.py b/tests/test_pagure_flask_api_group.py
index 42665e4..19977b7 100644
--- a/tests/test_pagure_flask_api_group.py
+++ b/tests/test_pagure_flask_api_group.py
@@ -86,6 +86,51 @@ class PagureFlaskApiGroupTests(tests.Modeltests):
self.assertEqual(sorted(data.keys()), ['groups', 'total_groups'])
self.assertEqual(data['total_groups'], 1)
+ def test_api_groups_extended(self):
+ """ Test the api_groups function. """
+
+ # Add a couple of groups so that we can list them
+ item = pagure.lib.model.PagureGroup(
+ group_name='group1',
+ group_type='user',
+ display_name='User group',
+ user_id=1, # pingou
+ )
+ self.session.add(item)
+
+ item = pagure.lib.model.PagureGroup(
+ group_name='rel-eng',
+ group_type='user',
+ display_name='Release engineering group',
+ user_id=1, # pingou
+ )
+ self.session.add(item)
+ self.session.commit()
+
+ output = self.app.get('/api/0/groups?extended=1')
+ self.assertEqual(output.status_code, 200)
+ data = json.loads(output.data)
+ self.assertEqual(
+ data,
+ {
+ "groups": [
+ {
+ "description": None,
+ "name": "some_group"
+ },
+ {
+ "description": None,
+ "name": "group1"
+ },
+ {
+ "description": None,
+ "name": "rel-eng"
+ }
+ ],
+ "total_groups": 3
+ }
+ )
+
def test_api_view_group_authenticated(self):
"""
Test the api_view_group method of the flask api with an