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.PersonTags import PersonTag, PersonTags
10 from PLC.Persons import Person, Persons
12 from PLC.AuthorizeHelpers import AuthorizeHelpers
14 class DeletePersonTag(Method):
16 Deletes the specified person setting
18 Admins have full access. Non-admins can change their own tags.
20 Returns 1 if successful, faults otherwise.
23 roles = ['admin', 'pi', 'user']
27 PersonTag.fields['person_tag_id']
30 returns = Parameter(int, '1 if successful')
32 def call(self, auth, person_tag_id):
33 person_tags = PersonTags(self.api, [person_tag_id])
35 raise PLCInvalidArgument, "No such person tag %r"%person_tag_id
36 person_tag = person_tags[0]
38 person = Persons (self.api, person_tag['person_id'])[0]
40 # check authorizations
41 if 'admin' in self.caller['roles']:
43 # user can change tags on self
44 elif AuthorizeHelpers.person_may_access_person (self.api, self.caller, person):
47 raise PLCPermissionDenied, "%s: you can only change your own tags"%self.name
50 self.object_ids = [person_tag['person_tag_id']]