From 0755239efd69c2aa2d30082a32a5037a92e69dfe Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mon, 13 Jun 2016 10:28:04 +0200 Subject: [PATCH] Hotfix FAS2 This hotfix brings a few features - Limit the user returned to a specified status (allowing to retrieve only the active accounts) - Search user by their email address - Search user by their IRC nick - Does not perform a LIKE query if there is no '%' in the pattern searched --- roles/fas_server/files/user.py | 35 +++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/roles/fas_server/files/user.py b/roles/fas_server/files/user.py index 0f246da3f0..39ee443d26 100644 --- a/roles/fas_server/files/user.py +++ b/roles/fas_server/files/user.py @@ -603,13 +603,19 @@ If this is not expected, please contact admin@fedoraproject.org and let them kno #@validate(validators=UserList()) @identity.require(identity.not_anonymous()) @expose(template="fas.templates.user.list", allow_json=True) - def list(self, search=u'a*', fields=None, limit=None): + def list(self, search=u'a*', fields=None, limit=None, status=None, + by_email=None, by_ircnick=None): '''List users :kwarg search: Limit the users returned by the search string. * is a wildcard character. :kwarg fields: Fields to return in the json request. Default is to return everything. + :kwargs status: if specified, only returns accounts with this status. + :kwargs by_email: if true or 1, the search is done by email instead of + nickname. + :kwargs by_ircnick: if true or 1, the search is done by ircnick instead + of nickname. This should be fixed up at some point. Json data needs at least the following for fasClient to work:: @@ -668,8 +674,31 @@ If this is not expected, please contact admin@fedoraproject.org and let them kno onclause=PersonRolesTable.c.person_id==PeopleTable.c.id)\ .outerjoin(GroupsTable, onclause=PersonRolesTable.c.group_id==GroupsTable.c.id) - stmt = select([joined_roles]).where(People.username.ilike(re_search))\ - .order_by(People.username).limit(limit) + + if str(by_email).lower() in ['1', 'true']: + if ur'%' in re_search: + stmt = select([joined_roles]).where(People.email.ilike( + re_search)).order_by(People.username).limit(limit) + else: + stmt = select([joined_roles]).where(People.email==re_search)\ + .order_by(People.username).limit(limit) + elif str(by_ircnick).lower() in ['1', 'true']: + if ur'%' in re_search: + stmt = select([joined_roles]).where(People.ircnick.ilike( + re_search)).order_by(People.username).limit(limit) + else: + stmt = select([joined_roles]).where(People.ircnick==re_search)\ + .order_by(People.username).limit(limit) + else: + if ur'%' in re_search: + stmt = select([joined_roles]).where(People.username.ilike( + re_search)).order_by(People.username).limit(limit) + else: + stmt = select([joined_roles]).where(People.username==re_search)\ + .order_by(People.username).limit(limit) + + if status is not None: + stmt = stmt.where(People.status==status) stmt.use_labels = True people = stmt.execute()