Initial checkin of new API implementation
authorTony Mack <tmack@cs.princeton.edu>
Fri, 6 Oct 2006 19:47:18 +0000 (19:47 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Fri, 6 Oct 2006 19:47:18 +0000 (19:47 +0000)
PLC/Methods/AddPersonToSlice.py [new file with mode: 0644]

diff --git a/PLC/Methods/AddPersonToSlice.py b/PLC/Methods/AddPersonToSlice.py
new file mode 100644 (file)
index 0000000..2e9cb60
--- /dev/null
@@ -0,0 +1,46 @@
+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
+
+class AddPersonToSlice(Method):
+    """
+    Adds the specified person to the specified slice. If the person is
+    already a member of the slice, no errors are returned. 
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    roles = ['admin']
+
+    accepts = [
+        PasswordAuth(),
+        Mixed(Person.fields['person_id'],
+              Person.fields['email']),
+        Mixed(Slice.fields['slice_id'],
+              Slice.fields['name'])
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+    def call(self, auth, person_id_or_email, slice_id_or_name):
+        # Get account information
+        persons = Persons(self.api, [person_id_or_email])
+        if not persons:
+            raise PLCInvalidArgument, "No such account"
+
+        person = persons.values()[0]
+
+        # Get slice information
+        slices = Slices(self.api, [slice_id_or_name])
+        if not slices:
+            raise PLCInvalidArgument, "No such slice"
+
+        slice = slices.values()[0]
+
+        if slice['slice_id'] not in person['slice_ids']:
+            slice.add_person(person)
+
+        return 1