On Fri, Jun 10, 2016 at 06:19:04PM +0200, Pierre-Yves Chibon wrote:
On Fri, Jun 10, 2016 at 09:56:04AM -0600, Kevin Fenzi wrote:
> On Fri, 10 Jun 2016 11:41:41 +0200
> Pierre-Yves Chibon <pingou(a)pingoured.fr> wrote:
>
> > Good Morning Everyone,
> >
> > I would like to propose for consideration the following patch to FAS2:
> >
https://github.com/fedora-infra/fas/pull/165
> >
> > The idea is to allow searching users via their email address instead
> > of always relying on their nickname.
> >
> > I have already adjusted stg to show the new behavior:
> >
https://admin.stg.fedoraproject.org/accounts/user/list/*redhat*?by_email=...
> > vs
> >
https://admin.stg.fedoraproject.org/accounts/user/list/*redhat*?limit=10000
> >
> > My only issue is: why aren't the user returned ordered by their nicks
> > as it's asked for in the code.
> >
> > This feature is/will be required for FMN :)
>
> Is the idea to apply this on top of the hotfixes we have, or cut a new
> fas release upstream to include this and the previous one?
Here is the diff of the new hotfix on the top of the existing one:
diff --git a/ roles/fas_server/files/user.py b/ roles/fas_server/files/user.py
index 0f246da..39ee443 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(a)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(a)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()
Pierre