git://git.onelab.eu
/
plcapi.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
get rid of svn keywords once and for good
[plcapi.git]
/
PLC
/
Methods
/
AddPersonKey.py
diff --git
a/PLC/Methods/AddPersonKey.py
b/PLC/Methods/AddPersonKey.py
index
74a6503
..
af70185
100644
(file)
--- a/
PLC/Methods/AddPersonKey.py
+++ b/
PLC/Methods/AddPersonKey.py
@@
-5,7
+5,7
@@
from PLC.Keys import Key, Keys
from PLC.Persons import Person, Persons
from PLC.Auth import Auth
from PLC.Persons import Person, Persons
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):
"""
class AddPersonKey(Method):
"""
@@
-29,20
+29,19
@@
class AddPersonKey(Method):
returns = Parameter(int, 'New key_id (> 0) if successful')
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
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 not persons:
raise PLCInvalidArgument, "No such account"
person = persons[0]
- # If we are not admin, make sure caller is adding a key to their account
+ 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']:
raise PLCPermissionDenied, "You may only modify your own keys"
if 'admin' not in self.caller['roles']:
if person['person_id'] != self.caller['person_id']:
raise PLCPermissionDenied, "You may only modify your own keys"
@@
-51,6
+50,10
@@
class AddPersonKey(Method):
key.sync(commit = False)
person.add_key(key, commit = True)
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']
return key['key_id']