allow tech to Get node and interface tags
[plcapi.git] / PLC / Methods / GetPersons.py
index 461c04b..9439420 100644 (file)
@@ -1,4 +1,3 @@
-# $Id$
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
@@ -28,8 +27,8 @@ class GetPersons(Method):
         Auth(),
         Mixed([Mixed(Person.fields['person_id'],
                      Person.fields['email'])],
-             Parameter(str,"email"),
-              Parameter(int,"person_id"), 
+              Parameter(str,"email"),
+              Parameter(int,"person_id"),
               Filter(Person.fields)),
         Parameter([str], "List of fields to return", nullok = True)
         ]
@@ -38,9 +37,9 @@ class GetPersons(Method):
     return_fields = dict(filter(lambda (field, value): field not in hidden_fields,
                                 Person.fields.items()))
     returns = [return_fields]
-    
+
     def call(self, auth, person_filter = None, return_fields = None):
-       # If we are not admin, make sure to only return viewable accounts
+        # If we are not admin, make sure to only return viewable accounts
         if isinstance(self.caller, Person) and \
            'admin' not in self.caller['roles']:
             # Get accounts that we are able to view
@@ -53,6 +52,11 @@ class GetPersons(Method):
             if not valid_person_ids:
                 return []
 
+            # this may look suspicious; what if person_filter is not None ?
+            # turns out the results are getting filtered again below, so we're safe
+            # although this part of the code does not always trigger, it's probably 
+            # a sensible performance enhancement for all the times 
+            # when GetPersons() gets called without an argument
             if person_filter is None:
                 person_filter = valid_person_ids
 
@@ -60,13 +64,13 @@ class GetPersons(Method):
         if return_fields:
             return_fields = filter(lambda field: field not in hidden_fields,
                                    return_fields)
-       else:
-           return_fields = self.return_fields.keys()
+        else:
+            return_fields = self.return_fields.keys()
 
         # Must query at least person_id, site_ids, and role_ids (see
         # Person.can_view() and below).
         if return_fields is not None:
-            added_fields = set(['person_id', 'site_ids', 'role_ids']).difference(return_fields)
+            added_fields = set(['person_id', 'site_ids', 'role_ids','roles']).difference(return_fields)
             return_fields += added_fields
         else:
             added_fields = []
@@ -82,7 +86,7 @@ class GetPersons(Method):
         if added_fields:
             for person in persons:
                 for field in added_fields:
-                   if field in person:
-                       del person[field]
+                    if field in person:
+                        del person[field]
 
         return persons