- use all_slice_ids when checking slice_ids in node['slice_ids']
[plcapi.git] / PLC / Methods / GetPersons.py
index 1ab08c2..e29d109 100644 (file)
@@ -1,14 +1,17 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
 from PLC.Persons import Person, Persons
 from PLC.Persons import Person, Persons
-from PLC.Auth import PasswordAuth
+from PLC.Auth import Auth
 
 class GetPersons(Method):
     """
 
 class GetPersons(Method):
     """
-    Return an array of structs containing details about accounts. If
-    person_id_or_email_list is specified, only the specified accounts
-    will be queried.
+    Returns an array of structs containing details about users. If
+    person_filter is specified and is an array of user identifiers or
+    usernames, or a struct of user attributes, only users matching the
+    filter will be returned. If return_fields is specified, only the
+    specified details will be returned.
 
     Users and techs may only retrieve details about themselves. PIs
     may retrieve details about themselves and others at their
 
     Users and techs may only retrieve details about themselves. PIs
     may retrieve details about themselves and others at their
@@ -18,10 +21,11 @@ class GetPersons(Method):
     roles = ['admin', 'pi', 'user', 'tech']
 
     accepts = [
     roles = ['admin', 'pi', 'user', 'tech']
 
     accepts = [
-        PasswordAuth(),
-        [Mixed(Person.fields['person_id'],
-               Person.fields['email'])],
-        Parameter([str], 'List of fields to return')
+        Auth(),
+        Mixed([Mixed(Person.fields['person_id'],
+                     Person.fields['email'])],
+              Filter(Person.fields)),
+        Parameter([str], "List of fields to return", nullok = True)
         ]
 
     # Filter out password field
         ]
 
     # Filter out password field
@@ -29,23 +33,28 @@ class GetPersons(Method):
     return_fields = dict(filter(can_return, Person.fields.items()))
     returns = [return_fields]
 
     return_fields = dict(filter(can_return, Person.fields.items()))
     returns = [return_fields]
 
-    def call(self, auth, person_id_or_email_list = None):
+    def call(self, auth, person_filter = None, return_fields = None):
        # If we are not admin, make sure to only return viewable accounts
         if 'admin' not in self.caller['roles']:
             # Get accounts that we are able to view
             valid_person_ids = [self.caller['person_id']]
             if 'pi' in self.caller['roles'] and self.caller['site_ids']:
        # If we are not admin, make sure to only return viewable accounts
         if 'admin' not in self.caller['roles']:
             # Get accounts that we are able to view
             valid_person_ids = [self.caller['person_id']]
             if 'pi' in self.caller['roles'] and self.caller['site_ids']:
-                sites = Sites(self.api, self.caller['site_ids']).values()
+                sites = Sites(self.api, self.caller['site_ids'])
                 for site in sites:
                     valid_person_ids += site['person_ids']
 
             if not valid_person_ids:
                 return []
 
                 for site in sites:
                     valid_person_ids += site['person_ids']
 
             if not valid_person_ids:
                 return []
 
-            if not person_id_or_email_list:
-                person_id_or_email_list = valid_person_ids
+            if person_filter is None:
+                person_filter = valid_person_ids
 
 
-        persons = Persons(self.api, person_id_or_email_list).values()
+        # Filter out password field
+        if return_fields:
+            while 'password' in return_fields:
+                return_fields.remove('password')
+
+        persons = Persons(self.api, person_filter, return_fields)
 
         # Filter out accounts that are not viewable
         if 'admin' not in self.caller['roles']:
 
         # Filter out accounts that are not viewable
         if 'admin' not in self.caller['roles']: