"""Utility module Resource entities.""" from flask import g from permissions.constants import constants # This was written for the PP endpoint get_my_adminable_resources, # which only supports certain resource types. See constants.PP_SUPPORTED_RESOURCE_TYPES. def transform_resource_entity(resource): """Transform resource entity to match with response format.""" resource_type = resource['type'] if resource_type not in constants.PP_SUPPORTED_RESOURCE_TYPES: g.log.debug('Resource type not supported: {}'.format(resource_type)) return None if resource_type in [ constants.SUBACCOUNT_NEO4J_RESOURCE_TYPE, constants.SUBACCOUNT_RESOURCE_TYPE, ]: return { 'type': constants.SUBACCOUNT_RESOURCE_TYPE, 'id': resource['id'], 'uuid': resource['uuid'], } if resource_type == constants.VENDOR_RESOURCE_TYPE: return { 'type': constants.VENDOR_RESOURCE_TYPE, 'id': resource['vendorId'], 'uuid': resource['uuid'], } if resource_type == constants.COMPANY_BRAND_RESOURCE_TYPE: return { 'type': constants.COMPANY_BRAND_RESOURCE_TYPE, 'id': resource['uuid'], 'uuid': resource['uuid'], } if resource_type == constants.LABELPARTICIPANT_RESOURCE_TYPE: return { 'type': constants.LABELPARTICIPANT_RESOURCE_TYPE, 'id': resource['id'], 'uuid': resource['uuid'], } if resource_type == constants.COLLABORATOR_RESOURCE_TYPE: return { 'type': constants.COLLABORATOR_RESOURCE_TYPE, 'id': resource['id'], 'uuid': resource['uuid'], }