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):
"""
Returns 1 if successful, faults otherwise.
"""
- roles = ['admin']
+ roles = ['admin', 'pi']
accepts = [
- PasswordAuth(),
+ Auth(),
Mixed(Person.fields['person_id'],
Person.fields['email']),
Mixed(Slice.fields['slice_id'],
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.values()[0]
+ slice = slices[0]
- if slice['slice_id'] not in person['slice_ids']:
+ # If we are not admin, make sure the caller is a PI
+ # of the site associated with the slice
+ if 'admin' not in self.caller['roles']:
+ if slice['site_id'] not in self.caller['site_ids']:
+ raise PLCPermissionDenied, "Not allowed to add users to this slice"
+
+ if slice['slice_id'] not in person['slice_ids']:
slice.add_person(person)
+ self.object_ids = [slice['slice_id']]
return 1