def get_permission_ingest(metadata, userid): """ get user info from policy call then determine if proposal/instrument is in their list of stuff. """ from myemsl.policy import get_policy_userinfo import re my_data = get_policy_userinfo(int(userid)) my_proposals = my_data['proposals'].keys() my_instruments = my_data['instruments'].keys() requested_proposals = {} requested_instruments = {} inst_re = re.compile(r'Instrument\.([0-9][0-9])') if 'eusInfo' in metadata: if 'proposalID' in metadata['eusInfo']: requested_proposals[metadata['eusInfo']['proposalID']] = 1 if 'file' in metadata: for file in metadata['file']: if 'groups' in file and file['groups']: for group in file['groups']: inst_match = inst_re.match(group['type']) if inst_match: requested_instruments[inst_match.group(1)] = 1 if group['type'] == 'proposal': requested_proposals[group['name']] = 1 # we should at least have one proposal if len(requested_proposals.keys()) == 0: return False for prop in requested_proposals.keys(): if not prop in my_proposals: return False for inst in requested_instruments.keys(): if not inst in my_instruments: return False return True
def userinfo(userid, dtype, writer): """ This does the bulk of the SQL to gather the appropriate data to send back to the user. Currently it consists of the: * EUS user information * EUS custodian table for instruments * EUS proposals for the user * EUS instruments for those proposals """ ## # get user information from EUS ## data = get_policy_userinfo(userid) formatdata(dtype, data, writer) return 0