X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FGetPersonTags.py;h=6c0c9b3621e002248e531bad3a0524307d76e56a;hb=c3d614f7f131b986e6193960032b0a50ff1fd624;hp=44fbdea7b2fa1864e73adf4a247a9cab724d4f58;hpb=f7ce7ce813d4c44502629820a3583f32a99a98f7;p=plcapi.git diff --git a/PLC/Methods/GetPersonTags.py b/PLC/Methods/GetPersonTags.py index 44fbdea..6c0c9b3 100644 --- a/PLC/Methods/GetPersonTags.py +++ b/PLC/Methods/GetPersonTags.py @@ -1,17 +1,15 @@ -# $Id: GetPersonTags.py 14587 2009-07-19 13:18:50Z thierry $ -# $URL: http://svn.planet-lab.org/svn/PLCAPI/tags/PLCAPI-4.3-27/PLC/Methods/GetPersonTags.py $ # # Thierry Parmentelat - INRIA # -# $Revision: 14587 $ -# from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Filter import Filter from PLC.Auth import Auth +from PLC.Persons import Person, Persons from PLC.PersonTags import PersonTag, PersonTags +from PLC.Sites import Sites, Site class GetPersonTags(Method): """ @@ -24,7 +22,7 @@ class GetPersonTags(Method): the specified details will be returned. """ - roles = ['admin', 'pi', 'user', 'node'] + roles = ['admin', 'pi', 'user', 'tech'] accepts = [ Auth(), @@ -39,6 +37,39 @@ class GetPersonTags(Method): def call(self, auth, person_tag_filter = None, return_fields = None): + # only persons can call this (as per roles, but..) + if not isinstance(self.caller,Person): + return [] + + # If we are not admin, make sure to only return viewable accounts + valid_person_ids=None + added_fields=[] + if 'admin' not in self.caller['roles']: + # Get accounts that we are able to view + valid_person_ids = [self.caller['person_id']] + if 'pi' in self.caller['roles'] and self.caller['site_ids']: + sites = Sites(self.api, self.caller['site_ids']) + for site in sites: + valid_person_ids += site['person_ids'] + + if not valid_person_ids: + return [] + + # if we have to filter out on person_id, make sure this is returned from db + if return_fields: + added_fields = set(['person_id']).difference(return_fields) + return_fields += added_fields + person_tags = PersonTags(self.api, person_tag_filter, return_fields) + + if valid_person_ids is not None: + person_tags = [ person_tag for person_tag in person_tags + if person_tag['person_id'] in valid_person_ids] + # Remove added fields if not initially specified + if added_fields: + for person_tag in person_tags: + for field in added_fields: + if field in person_tag: + del person_tag[field] return person_tags