2 # Thierry Parmentelat - INRIA
4 from PLC.Faults import *
5 from PLC.Method import Method
6 from PLC.Parameter import Parameter, Mixed
7 from PLC.Auth import Auth
9 from PLC.Persons import Person, Persons
10 from PLC.TagTypes import TagType, TagTypes
11 from PLC.PersonTags import PersonTag, PersonTags
13 # need to import so the core classes get decorated with caller_may_write_tag
14 from PLC.AuthorizeHelpers import AuthorizeHelpers
16 class UpdatePersonTag(Method):
18 Updates the value of an existing person setting
20 Admins have full access. Non-admins can change their own tags.
22 Returns 1 if successful, faults otherwise.
25 roles = ['admin', 'pi', 'tech', 'user']
29 PersonTag.fields['person_tag_id'],
30 PersonTag.fields['value']
33 returns = Parameter(int, '1 if successful')
35 def call(self, auth, person_tag_id, value):
36 person_tags = PersonTags(self.api, [person_tag_id])
38 raise PLCInvalidArgument, "No such person setting %r"%person_tag_id
39 person_tag = person_tags[0]
41 tag_type_id = person_tag['tag_type_id']
42 tag_type = TagTypes (self.api,[tag_type_id])[0]
44 persons = Persons (self.api, person_tag['person_id'])
46 raise PLCInvalidArgument, "No such person %d"%person_tag['person_id']
49 # check authorizations
50 person.caller_may_write_tag(self.api,self.caller,tag_type)
52 person_tag['value'] = value
55 self.object_ids = [person_tag['person_tag_id']]