def fake_to_tenant(principal_service: PrincipalService,
                   tenant_id: TenantId) -> PrincipalService:
    if principal_service.is_super_admin():
        # fake principal as tenant admin
        return PrincipalService(
            User(userId=principal_service.get_user_id(),
                 tenantId=tenant_id,
                 name=principal_service.get_user_name(),
                 role=UserRole.ADMIN))
    else:
        return principal_service
Ejemplo n.º 2
0
def ask_principal_service(principal_service: PrincipalService,
                          tenant_id: Optional[TenantId]) -> PrincipalService:
    if principal_service.is_tenant_admin():
        if is_blank(tenant_id):
            return principal_service
        elif tenant_id != principal_service.get_tenant_id():
            raise_400(
                f'Tenant id[{tenant_id}] does not match current principal.')
        else:
            return principal_service
    elif principal_service.is_super_admin():
        if is_blank(tenant_id):
            raise_400('Tenant id is required.')
        tenant_service = get_tenant_service(principal_service)
        tenant: Optional[Tenant] = tenant_service.find_by_id(tenant_id)
        if tenant is None:
            raise_404(f'Tenant[id={tenant_id}] not found.')
        return PrincipalService(
            User(tenantId=tenant_id,
                 userId=principal_service.get_user_id(),
                 name=principal_service.get_user_name(),
                 role=UserRole.ADMIN))
Ejemplo n.º 3
0
async def fetch_pipeline_logs(
		criteria: PipelineMonitorLogCriteria, principal_service: PrincipalService = Depends(get_any_admin_principal)
) -> PipelineMonitorLogDataPage:
	if principal_service.is_super_admin():
		if is_blank(criteria.tenantId):
			raise_400('Tenant id is required.')
		# fake principal as tenant admin
		principal_service = PrincipalService(User(
			userId=principal_service.get_user_id(), tenantId=criteria.tenantId,
			name=principal_service.get_user_name(), role=UserRole.ADMIN))
	else:
		criteria.tenantId = principal_service.get_tenant_id()

	page = PipelineMonitorLogDataService(principal_service).page(criteria)

	# translate dataId to string
	def translate_data_id_to_str(log: PipelineMonitorLog) -> None:
		log.dataId = str(log.dataId)

	page.data = ArrayHelper(page.data).each(translate_data_id_to_str).to_list()
	# noinspection PyTypeChecker
	return page