add NotifyPersons method to e-mail specified users
[plcapi.git] / PLC / Methods / AdmGetPersonSites.py
index 9c82f5b..79324f8 100644 (file)
@@ -3,12 +3,12 @@ from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Persons import Person, Persons
 from PLC.Sites import Site, Sites
-from PLC.Auth import PasswordAuth
+from PLC.Auth import Auth
 
-from PLC.Methods.AdmGetPersons import AdmGetPersons
-
-class AdmGetPersonSites(AdmGetPersons):
+class AdmGetPersonSites(Method):
     """
+    Deprecated. See GetPersons.
+
     Returns the sites that the specified person is associated with as
     an array of site identifiers.
 
@@ -17,24 +17,31 @@ class AdmGetPersonSites(AdmGetPersons):
     themselves and others at their sites.
     """
 
+    status = "deprecated"
+
     roles = ['admin', 'pi', 'user', 'tech']
 
     accepts = [
-        PasswordAuth(),
+        Auth(),
         Mixed(Person.fields['person_id'],
               Person.fields['email'])
         ]
 
-    returns = [Site.fields['site_id']]
+    returns = Person.fields['site_ids']
 
     def call(self, auth, person_id_or_email):
-        persons = AdmGetPersons.call(self, auth, [person_id_or_email])
+        # Get account information
+        persons = Persons(self.api, [person_id_or_email])
+        if not persons:
+            raise PLCInvalidArgument, "No such account"
 
-        # AdmGetPersons() validates person_id_or_email
-        assert persons
         person = persons[0]
 
-        # Filter out deleted sites
-        sites = Sites(self.api, persons['site_ids'])
+        # Authenticated function
+        assert self.caller is not None
+
+        # Check if we can view this account
+        if not self.caller.can_view(person):
+            raise PLCPermissionDenied, "Not allowed to view specified account"
 
-        return [site['site_id'] for site in sites]
+        return person['site_ids']