<commit_before>from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Filter import Filter
from PLC.Persons import Person, Persons
from PLC.Auth import Auth

class GetPersons(Method):
    """
    Returns an array of structs containing details about users. If
    person_filter is specified and is an array of user identifiers or
    usernames, or a struct of user attributes, only users matching the
    filter will be returned. If return_fields is specified, only the
    specified details will be returned.

    Users and techs may only retrieve details about themselves. PIs
    may retrieve details about themselves and others at their
    sites. Admins may retrieve details about all accounts.
    """

    roles = ['admin', 'pi', 'user', 'tech']

    accepts = [
        Auth(),
        Mixed([Mixed(Person.fields['person_id'],
                     Person.fields['email'])],
              Filter(Person.fields)),
        Parameter([str], "List of fields to return", nullok = True)
        ]

    # Filter out password field
    can_return = lambda (field, value): field not in \
	['password', 'verification_key', 'verification_expires']
    return_fields = dict(filter(can_return, Person.fields.items()))
    returns = [return_fields]
    

    def call(self, auth, person_filter = None, return_fields = None):

	# If we are not admin, make sure to only return viewable accounts
        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 person_filter is None:
                person_filter = valid_person_ids

        # Filter out password field
        if return_fields:
            return_fields = filter(self.can_return, return_fields)
	else:
	    return_fields = self.return_fields.keys()
		
        persons = Persons(self.api, person_filter, return_fields)

        # Filter out accounts that are not viewable
        if 'admin' not in self.caller['roles']:<commit_msg>- fix hidden fields removal<commit_after>from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Filter import Filter
from PLC.Persons import Person, Persons
from PLC.Auth import Auth

hidden_fields = ['password', 'verification_key', 'verification_expires']

class GetPersons(Method):
    """
    Returns an array of structs containing details about users. If
    person_filter is specified and is an array of user identifiers or
    usernames, or a struct of user attributes, only users matching the
    filter will be returned. If return_fields is specified, only the
    specified details will be returned.

    Users and techs may only retrieve details about themselves. PIs
    may retrieve details about themselves and others at their
    sites. Admins may retrieve details about all accounts.
    """

    roles = ['admin', 'pi', 'user', 'tech']

    accepts = [
        Auth(),
        Mixed([Mixed(Person.fields['person_id'],
                     Person.fields['email'])],
              Filter(Person.fields)),
        Parameter([str], "List of fields to return", nullok = True)
        ]

    # Filter out password field
    return_fields = dict(filter(lambda (field, value): field not in hidden_fields,
                                Person.fields.items()))
    returns = [return_fields]
    
    def call(self, auth, person_filter = None, return_fields = None):
	# If we are not admin, make sure to only return viewable accounts
        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 person_filter is None:
                person_filter = valid_person_ids

        # Filter out password field
        if return_fields:
            return_fields = filter(lambda field: field not in hidden_fields,
                                   return_fields)
	else:
	    return_fields = self.return_fields.keys()

        persons = Persons(self.api, person_filter, return_fields)

        # Filter out accounts that are not viewable
        if 'admin' not in self.caller['roles']:
{'fraction_non_alphanumeric': 0.08392484342379958, 'fraction_numerical': 0.0, 'mean_word_length': 2.5253863134657837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4479086', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1245, 'n_words': 458}