X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAddPersonToSlice.py;h=d4a17a4e8d1f6880639c7e93728bf5855fc07698;hb=bd0cbf4f7f2e4cf7ceda500bfa6f98c0a700018b;hp=a74389e1eba3170edab5ac6bde3ef249a22e40bc;hpb=1f8c38dd1357c93e4be8d94456b7274a591d2db4;p=plcapi.git diff --git a/PLC/Methods/AddPersonToSlice.py b/PLC/Methods/AddPersonToSlice.py index a74389e..d4a17a4 100644 --- a/PLC/Methods/AddPersonToSlice.py +++ b/PLC/Methods/AddPersonToSlice.py @@ -8,7 +8,7 @@ from PLC.Auth import Auth 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. + already a member of the slice, no errors are returned. Returns 1 if successful, faults otherwise. """ @@ -24,33 +24,38 @@ class AddPersonToSlice(Method): ] returns = Parameter(int, '1 if successful') - event_type = 'AddTo' - object_type = 'Slice' - object_ids = [] 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] + 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 - if 'admin' not in self.caller['roles']: + 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']: + if slice['slice_id'] not in person['slice_ids']: slice.add_person(person) - self.object_ids = [slice['slice_id']] + + # Logging variables + self.event_objects = {'Person': [person['person_id']], + 'Slice': [slice['slice_id']]} + self.object_ids = [slice['slice_id']] return 1