svn keywords
[plcapi.git] / PLC / Methods / AddPersonToSlice.py
index 9948af2..b38e111 100644 (file)
@@ -1,9 +1,11 @@
+# $Id$
+# $URL$
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Persons import Person, Persons
 from PLC.Slices import Slice, Slices
-from PLC.Auth import PasswordAuth
+from PLC.Auth import Auth
 
 class AddPersonToSlice(Method):
     """
@@ -16,7 +18,7 @@ class AddPersonToSlice(Method):
     roles = ['admin', 'pi']
 
     accepts = [
-        PasswordAuth(),
+        Auth(),
         Mixed(Person.fields['person_id'],
               Person.fields['email']),
         Mixed(Slice.fields['slice_id'],
@@ -30,15 +32,19 @@ class AddPersonToSlice(Method):
         persons = Persons(self.api, [person_id_or_email])
         if not persons:
             raise PLCInvalidArgument, "No such account"
-
-        person = persons.values()[0]
+        person = persons[0]
 
         # Get slice information
         slices = Slices(self.api, [slice_id_or_name])
         if not slices:
             raise PLCInvalidArgument, "No such slice"
+        slice = slices[0]
 
-        slice = slices.values()[0]
+        # N.B. Allow foreign users to be added to local slices and
+        # local users to be added to foreign slices (and, of course,
+        # local users to be added to local slices).
+        if person['peer_id'] is not None and slice['peer_id'] is not None:
+            raise PLCInvalidArgument, "Cannot add foreign users to foreign slices"
 
         # If we are not admin, make sure the caller is a PI
         # of the site associated with the slice
@@ -49,4 +55,9 @@ class AddPersonToSlice(Method):
        if slice['slice_id'] not in person['slice_ids']:
             slice.add_person(person)
 
+        # Logging variables
+       self.event_objects = {'Person': [person['person_id']],
+                             'Slice': [slice['slice_id']]}     
+       self.object_ids = [slice['slice_id']]
+
         return 1