Commits

Leho Kraav committed 83ff8f0

Comments (0)

Files changed (1)

DSourceUserDirectory-dsource.org/DSourceUserDirectory.py

+# Original questions/notes from: http://www.dsource.org/projects/test/wiki/UserDirectory
+#
+#    * Currently, all Trac code still uses env.get_known_users() method - should they use the plugin directly (and env.userdir to get the providers), just like that method in env does? If so, the method in env goes away.
+#    * In working on the limit parameter, I'm wondering if we also need a page parameter, to page thru the users if there are a lot of them?
+#    * restrict_owner doesn't work in the global trac.ini - should it? It would be nice for my multi-project setup.
+#    * Is trac/userdir.py a good place for the interface and Trac plugin, or would somewhere else be a better fit?
+#    * I didn't do very much with different attributes of users, so we'll need more work there, esp. when the LDAP plugins are developed. 
+
+class DSourceUserDirectory(Component):
+    implements (IRequestHandler, IUserDirectory)
+    
+    # IRequestHandler methods
+
+    def match_request(self, req):
+        self.req = req
+        return False
+
+    def process_request(self, req):
+        pass
+
+
+    # IUserDirectory methods
+    def get_known_user_info(self, cnx=None, limit=None):
+        proj = get_project_code(self.req)
+        cnx = get_db()
+        cursor = cnx.cursor()
+        cursor.execute("SELECT username, user_email "
+                       "FROM phpbb_users u " 
+                       " INNER JOIN members_projects mp on u.user_id=mp.member_id "
+                       " INNER JOIN projects p on mp.project_id=p.project_id "
+                       "WHERE project_code=%s "
+                       "ORDER BY username", (proj,))
+        
+        for username,email in cursor:
+            yield username,username,email
+
+    def get_known_users(self, cnx=None, limit=None):
+        proj = get_project_code(self.req)
+        cnx = get_db()
+        cursor = cnx.cursor()
+        cursor.execute("SELECT username "
+                       "FROM phpbb_users u " 
+                       " INNER JOIN members_projects mp on u.user_id=mp.member_id "
+                       " INNER JOIN projects p on mp.project_id=p.project_id "
+                       "WHERE project_code=%s "
+                       "ORDER BY username", (proj,))
+        
+        for username in cursor:
+            yield username[0]
+
+    def get_user_attribute(self, user, attr):
+        pass
+    
+    def get_supported_attributes(self):
+        pass