all tag types use permission helpers in AuthorizeHelpers
[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 class DeletePersonTag(Method):
13     """
14     Deletes the specified person setting
15
16     Admins have full access.  Non-admins can change their own tags.
17
18     Returns 1 if successful, faults otherwise.
19     """
20
21     roles = ['admin', 'pi', 'user']
22
23     accepts = [
24         Auth(),
25         PersonTag.fields['person_tag_id']
26         ]
27
28     returns = Parameter(int, '1 if successful')
29
30     def call(self, auth, person_tag_id):
31         person_tags = PersonTags(self.api, [person_tag_id])
32         if not person_tags:
33             raise PLCInvalidArgument, "No such person tag %r"%person_tag_id
34         person_tag = person_tags[0]
35
36         persons = Persons (self.api, person_tag['person_id'])
37         if not persons:
38             raise PLCInvalidArgument, "No such person %d"%person_tag['person_id']
39         person=persons[0]
40
41         # check authorizations
42         person.caller_may_write_tag(self.api,self.caller,tag_type)
43
44         person_tag.delete()
45         self.object_ids = [person_tag['person_tag_id']]
46
47         return 1