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.Filter import Filter
8 from PLC.Auth import Auth
10 from PLC.Persons import Person, Persons
11 from PLC.PersonTags import PersonTag, PersonTags
12 from PLC.Sites import Sites, Site
14 class GetPersonTags(Method):
16 Returns an array of structs containing details about
17 persons and related settings.
19 If person_tag_filter is specified and is an array of
20 person setting identifiers, only person settings matching
21 the filter will be returned. If return_fields is specified, only
22 the specified details will be returned.
25 roles = ['admin', 'pi', 'user', 'tech']
29 Mixed([PersonTag.fields['person_tag_id']],
30 Parameter(int,"Person setting id"),
31 Filter(PersonTag.fields)),
32 Parameter([str], "List of fields to return", nullok = True)
35 returns = [PersonTag.fields]
38 def call(self, auth, person_tag_filter = None, return_fields = None):
40 # only persons can call this (as per roles, but..)
41 if not isinstance(self.caller,Person):
44 # If we are not admin, make sure to only return viewable accounts
47 if 'admin' not in self.caller['roles']:
48 # Get accounts that we are able to view
49 valid_person_ids = [self.caller['person_id']]
50 if 'pi' in self.caller['roles'] and self.caller['site_ids']:
51 sites = Sites(self.api, self.caller['site_ids'])
53 valid_person_ids += site['person_ids']
55 if not valid_person_ids:
58 # if we have to filter out on person_id, make sure this is returned from db
60 added_fields = set(['person_id']).difference(return_fields)
61 return_fields += added_fields
63 person_tags = PersonTags(self.api, person_tag_filter, return_fields)
65 if valid_person_ids is not None:
66 person_tags = [ person_tag for person_tag in person_tags
67 if person_tag['person_id'] in valid_person_ids]
69 # Remove added fields if not initially specified
71 for person_tag in person_tags:
72 for field in added_fields:
73 if field in person_tag: