1 # $Id: UpdatePersonTag.py 14587 2009-07-19 13:18:50Z thierry $
2 # $URL: http://svn.planet-lab.org/svn/PLCAPI/tags/PLCAPI-4.3-27/PLC/Methods/UpdatePersonTag.py $
7 from PLC.Faults import *
8 from PLC.Method import Method
9 from PLC.Parameter import Parameter, Mixed
10 from PLC.Auth import Auth
12 from PLC.PersonTags import PersonTag, PersonTags
13 from PLC.Persons import Person, Persons
15 from PLC.Nodes import Nodes
16 from PLC.Persons import Persons
18 class UpdatePersonTag(Method):
20 Updates the value of an existing person setting
22 Access rights depend on the tag type.
24 Returns 1 if successful, faults otherwise.
27 roles = ['admin', 'pi', 'tech', 'user']
31 PersonTag.fields['person_tag_id'],
32 PersonTag.fields['value']
35 returns = Parameter(int, '1 if successful')
37 object_type = 'Person'
39 def call(self, auth, person_tag_id, value):
40 person_tags = PersonTags(self.api, [person_tag_id])
42 raise PLCInvalidArgument, "No such person setting %r"%person_tag_id
43 person_tag = person_tags[0]
45 ### reproducing a check from UpdateSliceTag, looks dumb though
46 persons = Persons(self.api, [person_tag['person_id']])
48 raise PLCInvalidArgument, "No such person %r"%person_tag['person_id']
51 assert person_tag['person_tag_id'] in person['person_tag_ids']
53 # check permission : it not admin, is the user affiliated with the right person
54 if 'admin' not in self.caller['roles']:
55 # check caller is affiliated with this person's person
56 if len(set(person['person_ids']) & set(self.caller['person_ids'])) == 0:
57 raise PLCPermissionDenied, "Not a member of the person's persons: %s"%person['person_ids']
59 required_min_role = tag_type ['min_role_id']
60 if required_min_role is not None and \
61 min(self.caller['role_ids']) > required_min_role:
62 raise PLCPermissionDenied, "Not allowed to modify the specified person setting, requires role %d",required_min_role
64 person_tag['value'] = value
67 self.object_ids = [person_tag['person_tag_id']]