[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Change Request: fix a fas2 vs fas1 regression

Ricky Zhou wrote:
On 2008-05-01 06:24:32 PM, Toshio Kuratomi wrote:
I've just committed this change to the fas git repo that fixes a change in the dump format from fas1 to fas2. In fas1, the role_type was accurate when dumped from the account system. In fas2, role_type was always "user" even if the person was a sponsor or administrator.

I'd like to have this applied to the production FAS so that the Package Status Scripts can be run again.
+1 for the role_type fix
(If the last field, the number of people sponsored, isn't vital to those
scripts, then we can fix that last omissions after the freeze.)

Shoot. I didn't know that field was broken as well. Am I correct that that's the number of people that the given person has sponsored?

If so, here's a new version of the patch that fixes that as well (committed to fas's git). It makes two db queries inside of the method body[1]_ per request. I'm pretty sure that it could be made into a single query per request but I don't think that's a necessary change at the moment.

This has been tested on pt3 for plain text and json calls, with a groupname and without a groupname specified. It imports a few methods from sqlalchemy but otherwise it only touches the dump method and its template just like the last patch.

.. _[1]: There are additional queries that we don't have much control over for authentication and such.

--- fas/templates/group/dump.txt.orig	2008-05-01 23:12:13.000000000 -0700
+++ fas/templates/group/dump.txt	2008-05-01 23:13:43.000000000 -0700
@@ -1,3 +1,3 @@
 #for person in people
--- fas/group.py.orig	2008-05-01 23:21:33.000000000 -0700
+++ fas/group.py	2008-05-01 23:43:00.000000000 -0700
@@ -4,8 +4,12 @@
 import cherrypy
 import sqlalchemy
+from sqlalchemy import select, func
+from sqlalchemy.sql import literal_column
 import fas
+from fas.model import (People, PeopleTable, PersonRoles, PersonRolesTable, \
+        Groups, GroupsTable)
 from fas.auth import *
 from fas.user import KnownUser
@@ -477,27 +481,44 @@
-    @expose(template="genshi-text:fas.templates.group.dump", format="text", content_type='text/plain; charset=utf-8')
+    @expose(template="genshi-text:fas.templates.group.dump", format="text",
+            content_type='text/plain; charset=utf-8')
     def dump(self, groupname=None):
-        username = turbogears.identity.current.user_name
-        person = People.by_username(username)
+        sponsorTables = PeopleTable.join(PersonRolesTable,
+                People.id==PersonRoles.sponsor_id)
         if not groupname:
-#            groupname = config.get('cla_done_group')
-            people = People.query.order_by('username').all()
+            people = People.query.order_by('username').add_column(
+                    literal_column("'user'").label('role_type')).all()
+            # retrieve sponsorship info:
+            sponsorCount = select(
+                    [People.username, func.count(People.username)],
+                    from_obj = sponsorTables).group_by(People.username)
+            sponsorship = dict(pair for pair in sponsorCount.execute())
             people = []
-            groups = Groups.by_name(groupname)
-            for role in groups.approved_roles:
-                people.append(role.member)
-            if not canViewGroup(person, groups):
-                turbogears.flash(_("You cannot view '%s'") % group.name)
-                turbogears.redirect('/group/list')
-                return dict()
+            # Retrieve necessary info about the users who are approved in
+            # this group
+            people = People.query.join('roles').filter(
+                    PersonRoles.role_status=='approved').join(
+                        PersonRoles.group).add_column(
+                            PersonRoles.role_type).filter(
+                                Groups.name==groupname).order_by('username')
+            # retrieve sponsorship info:
+            sponsorCount = select(
+                    [People.username, func.count(People.username)],
+                    from_obj=sponsorTables.join(
+                        GroupsTable, PersonRoles.group_id==Groups.id)
+                    ).group_by(People.username).where(Groups.name==groupname)
+            sponsorship = dict(pair for pair in sponsorCount.execute())
         # We filter this so that sending information via json is quick(er)
-        filteredPeople = sorted([(p.username, p.email, p.human_name)
-                for p in people])
+        filteredPeople = sorted((p[0].username, p[0].email, p[0].human_name,
+            p[1], sponsorship.get(p[0].username, 0)) for p in people)
         return dict(people=filteredPeople)

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]