bug fix, tag_type was undefined
[plcapi.git] / PLC / Methods / DeletePersonTag.py
1 #
2 # Thierry Parmentelat - INRIA
3 #
4 from PLC.Faults import *
5 from PLC.Method import Method
6 from PLC.Parameter import Parameter, Mixed
7 from PLC.Auth import Auth
8
9 from PLC.PersonTags import PersonTag, PersonTags
10 from PLC.Persons import Person, Persons
11
12 # need to import so the core classes get decorated with caller_may_write_tag
13 from PLC.AuthorizeHelpers import AuthorizeHelpers
14
15 class DeletePersonTag(Method):
16     """
17     Deletes the specified person setting
18
19     Admins have full access.  Non-admins can change their own tags.
20
21     Returns 1 if successful, faults otherwise.
22     """
23
24     roles = ['admin', 'pi', 'user']
25
26     accepts = [
27         Auth(),
28         PersonTag.fields['person_tag_id']
29         ]
30
31     returns = Parameter(int, '1 if successful')
32
33     def call(self, auth, person_tag_id):
34         person_tags = PersonTags(self.api, [person_tag_id])
35         if not person_tags:
36             raise PLCInvalidArgument, "No such person tag %r"%person_tag_id
37         person_tag = person_tags[0]
38
39         tag_type_id = person_tag['tag_type_id']
40         tag_type = TagTypes (self.api,[tag_type_id])[0]
41
42         persons = Persons (self.api, person_tag['person_id'])
43         if not persons:
44             raise PLCInvalidArgument, "No such person %d"%person_tag['person_id']
45         person=persons[0]
46
47         # check authorizations
48         person.caller_may_write_tag(self.api,self.caller,tag_type)
49
50         person_tag.delete()
51         self.object_ids = [person_tag['person_tag_id']]
52
53         return 1