1 # $Id: DeletePersonTag.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/DeletePersonTag.py $
4 # Thierry Parmentelat - INRIA
9 from PLC.Faults import *
10 from PLC.Method import Method
11 from PLC.Parameter import Parameter, Mixed
12 from PLC.Auth import Auth
14 from PLC.PersonTags import PersonTag, PersonTags
15 from PLC.Persons import Person, Persons
17 from PLC.Nodes import Node, Nodes
18 from PLC.Persons import Person, Persons
20 class DeletePersonTag(Method):
22 Deletes the specified person setting
24 Attributes may require the caller to have a particular role in order
25 to be deleted, depending on the related tag type.
26 Admins may delete attributes of any slice or sliver.
28 Returns 1 if successful, faults otherwise.
31 roles = ['admin', 'pi', 'user']
35 PersonTag.fields['person_tag_id']
38 returns = Parameter(int, '1 if successful')
40 object_type = 'Person'
43 def call(self, auth, person_tag_id):
44 person_tags = PersonTags(self.api, [person_tag_id])
46 raise PLCInvalidArgument, "No such person tag %r"%person_tag_id
47 person_tag = person_tags[0]
49 ### reproducing a check from UpdateSliceTag, looks dumb though
50 persons = Persons(self.api, [person_tag['person_id']])
52 raise PLCInvalidArgument, "No such person %r"%person_tag['person_id']
55 assert person_tag['person_tag_id'] in person['person_tag_ids']
57 # check permission : it not admin, is the user affiliated with the right person
58 if 'admin' not in self.caller['roles']:
59 # check caller is affiliated with this person's site
60 if len(set(person['site_ids']) & set(self.caller['site_ids'])) == 0:
61 raise PLCPermissionDenied, "Not a member of the person's sites: %s"%person['site_ids']
63 required_min_role = tag_type ['min_role_id']
64 if required_min_role is not None and \
65 min(self.caller['role_ids']) > required_min_role:
66 raise PLCPermissionDenied, "Not allowed to modify the specified person setting, requires role %d",required_min_role
69 self.object_ids = [person_tag['person_tag_id']]