X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAddPersonKey.py;h=f7f18a624d5a9b3c91030af2322b227d68186c4f;hb=2c4cbe5fb2105d0fc1a3661905bfc2fbee20f0e0;hp=3749ecd08d0bfaa6b1c16084113d746355fbfeea;hpb=ed7fa1ebf97ec2f88f18f8fa538e46c6ae9525c4;p=plcapi.git diff --git a/PLC/Methods/AddPersonKey.py b/PLC/Methods/AddPersonKey.py index 3749ecd..f7f18a6 100644 --- a/PLC/Methods/AddPersonKey.py +++ b/PLC/Methods/AddPersonKey.py @@ -1,11 +1,12 @@ +# $Id$ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Keys import Key, Keys from PLC.Persons import Person, Persons -from PLC.Auth import PasswordAuth +from PLC.Auth import Auth -can_update = lambda (field, value): field not in ['key_id'] +can_update = lambda (field, value): field in ['key_type','key'] class AddPersonKey(Method): """ @@ -21,7 +22,7 @@ class AddPersonKey(Method): key_fields = dict(filter(can_update, Key.fields.items())) accepts = [ - PasswordAuth(), + Auth(), Mixed(Person.fields['person_id'], Person.fields['email']), key_fields @@ -29,19 +30,18 @@ class AddPersonKey(Method): returns = Parameter(int, 'New key_id (> 0) if successful') - event_type = 'Add' - object_type = 'Key' - object_ids = [] - def call(self, auth, person_id_or_email, key_fields): key_fields = dict(filter(can_update, key_fields.items())) # Get account details - persons = Persons(self.api, [person_id_or_email]).values() + persons = Persons(self.api, [person_id_or_email]) if not persons: raise PLCInvalidArgument, "No such account" person = persons[0] + if person['peer_id'] is not None: + raise PLCInvalidArgument, "Not a local account" + # If we are not admin, make sure caller is adding a key to their account if 'admin' not in self.caller['roles']: if person['person_id'] != self.caller['person_id']: @@ -51,6 +51,10 @@ class AddPersonKey(Method): key.sync(commit = False) person.add_key(key, commit = True) - self.object_ids = [person['person_id'], key['key_id']] + # Logging variables + self.event_objects = {'Person': [person['person_id']], + 'Key': [key['key_id']]} + self.message = 'Key %d added to person %d' % \ + (key['key_id'], person['person_id']) return key['key_id']