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
13 class GetPersonTags(Method):
15 Returns an array of structs containing details about
16 persons and related settings.
18 If person_tag_filter is specified and is an array of
19 person setting identifiers, only person settings matching
20 the filter will be returned. If return_fields is specified, only
21 the specified details will be returned.
24 roles = ['admin', 'pi', 'user', 'tech']
28 Mixed([PersonTag.fields['person_tag_id']],
29 Parameter(int,"Person setting id"),
30 Filter(PersonTag.fields)),
31 Parameter([str], "List of fields to return", nullok = True)
34 returns = [PersonTag.fields]
37 def call(self, auth, person_tag_filter = None, return_fields = None):
39 # only persons can call this (as per roles, but..)
40 if not isinstance(self.caller,Person):
43 # If we are not admin, make sure to only return viewable accounts
46 if 'admin' not in self.caller['roles']:
47 # Get accounts that we are able to view
48 valid_person_ids = [self.caller['person_id']]
49 if 'pi' in self.caller['roles'] and self.caller['site_ids']:
50 sites = Sites(self.api, self.caller['site_ids'])
52 valid_person_ids += site['person_ids']
54 if not valid_person_ids:
57 # if we have to filter out on person_id, make sure this is returned from db
59 added_fields = set(['person_id']).difference(return_fields)
60 return_fields += added_fields
62 person_tags = PersonTags(self.api, person_tag_filter, return_fields)
64 if valid_person_ids is not None:
65 person_tags = [ person_tag for person_tag in person_tags
66 if person_tag['person_id'] in valid_person_ids]
68 # Remove added fields if not initially specified
70 for person_tag in person_tags:
71 for field in added_fields:
72 if field in person_tag: