get rid of svn keywords once and for good
[plcapi.git] / PLC / Methods / SetPersonPrimarySite.py
index ada63c5..644826b 100644 (file)
@@ -3,20 +3,20 @@ 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.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
 
 class SetPersonPrimarySite(Method):
     """
     Makes the specified site the person's primary site. The person
     must already be a member of the site.
 
 
 class SetPersonPrimarySite(Method):
     """
     Makes the specified site the person's primary site. The person
     must already be a member of the site.
 
-    ins may update anyone. All others may only update themselves.
+    Admins may update anyone. All others may only update themselves.
     """
 
     roles = ['admin', 'pi', 'user', 'tech']
 
     accepts = [
     """
 
     roles = ['admin', 'pi', 'user', 'tech']
 
     accepts = [
-        PasswordAuth(),
+        Auth(),
         Mixed(Person.fields['person_id'],
               Person.fields['email']),
         Mixed(Site.fields['site_id'],
         Mixed(Person.fields['person_id'],
               Person.fields['email']),
         Mixed(Site.fields['site_id'],
@@ -25,13 +25,17 @@ class SetPersonPrimarySite(Method):
 
     returns = Parameter(int, '1 if successful')
 
 
     returns = Parameter(int, '1 if successful')
 
+    object_type = 'Person'
+
     def call(self, auth, person_id_or_email, site_id_or_login_base):
         # Get account information
         persons = Persons(self.api, [person_id_or_email])
         if not persons:
             raise PLCInvalidArgument, "No such account"
     def call(self, auth, person_id_or_email, site_id_or_login_base):
         # Get account information
         persons = Persons(self.api, [person_id_or_email])
         if not persons:
             raise PLCInvalidArgument, "No such account"
+        person = persons[0]
 
 
-        person = persons.values()[0]
+        if person['peer_id'] is not None:
+            raise PLCInvalidArgument, "Not a local account"
 
         # Authenticated function
         assert self.caller is not None
 
         # Authenticated function
         assert self.caller is not None
@@ -45,8 +49,10 @@ class SetPersonPrimarySite(Method):
         sites = Sites(self.api, [site_id_or_login_base])
         if not sites:
             raise PLCInvalidArgument, "No such site"
         sites = Sites(self.api, [site_id_or_login_base])
         if not sites:
             raise PLCInvalidArgument, "No such site"
+        site = sites[0]
 
 
-        site = sites.values()[0]
+        if site['peer_id'] is not None:
+            raise PLCInvalidArgument, "Not a local site"
 
         if site['site_id'] not in person['site_ids']:
             raise PLCInvalidArgument, "Not a member of the specified site"
 
         if site['site_id'] not in person['site_ids']:
             raise PLCInvalidArgument, "Not a member of the specified site"