OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)

This commit is contained in:
wangruiguo
2026-09-03 18:49:20 +08:00
commit d647428529
3501 changed files with 1988906 additions and 0 deletions

View File

@@ -0,0 +1,181 @@
<?php
namespace Leantime\Domain\Connector\Controllers;
use Leantime\Core\Controller\Controller;
use Leantime\Core\Controller\Frontcontroller;
use Leantime\Domain\Auth\Models\Roles;
use Leantime\Domain\Auth\Services\Auth;
use Leantime\Domain\Connector\Models\Integration as IntegrationModel;
use Leantime\Domain\Connector\Services\Connector;
use Leantime\Domain\Connector\Services\Integrations as IntegrationService;
use Leantime\Domain\Connector\Services\Providers;
use Symfony\Component\HttpFoundation\Response;
class Integration extends Controller
{
private Providers $providerService;
private IntegrationService $integrationService;
private Connector $connectorService;
/**
* Initializes dependencies.
*/
public function init(
Providers $providerService,
IntegrationService $integrationService,
Connector $connectorService
): void {
Auth::authOrRedirect([Roles::$owner, Roles::$admin], true);
$this->providerService = $providerService;
$this->integrationService = $integrationService;
$this->connectorService = $connectorService;
}
/**
* Displays the integration wizard step.
*
* @param array $params Request parameters
*/
public function get(array $params): Response
{
return $this->handleIntegration($params);
}
/**
* Handles integration wizard form submissions.
*
* @param array $params Request parameters
*/
public function post(array $params): Response
{
return $this->handleIntegration($params);
}
/**
* Routes the request to the correct integration wizard step.
*
* @param array $params Request parameters
*/
private function handleIntegration(array $params): Response
{
if (! session()->exists('currentImportEntity')) {
session(['currentImportEntity' => '']);
}
if (! isset($params['provider'])) {
return new Response;
}
$provider = $this->providerService->getProvider($params['provider']);
$this->tpl->assign('provider', $provider);
$currentIntegration = app()->make(IntegrationModel::class);
if (isset($params['integrationId'])) {
$currentIntegration = $this->integrationService->get($params['integrationId']);
if (is_object($currentIntegration)) {
$this->tpl->assign('integrationId', $currentIntegration->id);
}
}
if (! isset($params['step'])) {
return $this->tpl->display('connector.newIntegration');
}
if ($params['step'] == 'connect') {
$connection = $provider->connect();
if ($connection instanceof Response) {
return $connection;
}
}
if ($params['step'] == 'entity') {
$this->tpl->assign('providerEntities', $provider->getEntities());
$this->tpl->assign('leantimeEntities', $this->integrationService->getAvailableEntities());
return $this->tpl->display('connector.integrationEntity');
}
if ($params['step'] == 'fields') {
return $this->handleFieldsStep($this->incomingRequest->request->all(), $provider, $currentIntegration);
}
if ($params['step'] == 'sync') {
return $this->tpl->display('connector.integrationSync');
}
if ($params['step'] == 'parse') {
return $this->handleParseStep($this->incomingRequest->request->all(), $provider);
}
if ($params['step'] == 'import') {
return $this->handleImportStep();
}
return new Response;
}
/**
* Handles the fields mapping step.
*
* @param array $params POST request parameters
* @param object $provider Provider instance
* @param IntegrationModel $currentIntegration Integration being configured
*/
private function handleFieldsStep(array $params, object $provider, IntegrationModel $currentIntegration): Response
{
$entity = $this->integrationService->resolveImportEntity($params, $currentIntegration);
if ($entity === null) {
$this->tpl->setNotification('Entity not set', 'error');
return Frontcontroller::redirect(BASE_URL.'/connector/integration?provider='.$provider->id.'');
}
$this->tpl->assign('providerFields', $this->integrationService->resolveProviderFields($currentIntegration, $provider));
$this->tpl->assign('flags', $this->connectorService->getEntityFlags($entity));
$this->tpl->assign('leantimeFields', $this->integrationService->getEntityFields($entity));
return $this->tpl->display('connector.integrationFields');
}
/**
* Handles the import review/parse step.
*
* @param array $params POST request parameters
* @param object $provider Provider instance
*/
private function handleParseStep(array $params, object $provider): Response
{
$values = $provider->geValues();
$fields = $this->connectorService->getFieldMappings($params);
$flags = $this->connectorService->parseValues($fields, $values, session('currentImportEntity'));
$this->tpl->assign('values', $values);
$this->tpl->assign('fields', $fields);
$this->tpl->assign('flags', $flags);
return $this->tpl->display('connector.integrationImport');
}
/**
* Handles the final import execution step.
*/
private function handleImportStep(): Response
{
$payload = $this->integrationService->getCachedImportPayload();
$result = $this->connectorService->importValues($payload['fields'], $payload['values'], session('currentImportEntity'));
if ($result !== true) {
$this->tpl->setNotification('There was a problem with the import '.$result, 'error');
}
return $this->tpl->display('connector.integrationConfirm');
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Leantime\Domain\Connector\Controllers;
use Leantime\Core\Controller\Controller;
use Leantime\Domain\Auth\Models\Roles;
use Leantime\Domain\Auth\Services\Auth;
class Providers extends Controller
{
/**
* constructor - initialize private variables
*/
public function init()
{
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager, Roles::$editor]);
}
/**
* get - handle get requests
*/
public function get($params)
{
return $this->tpl->displayPartial('connectors.providers');
}
/**
* post - handle post requests
*/
public function post($params)
{
return $this->tpl->displayPartial('connectors.providers');
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Leantime\Domain\Connector\Controllers;
use Leantime\Core\Controller\Controller;
use Leantime\Domain\Auth\Models\Roles;
use Leantime\Domain\Auth\Services\Auth;
use Leantime\Domain\Connector\Services;
class Show extends Controller
{
private Services\Providers $providerService;
/**
* constructor - initialize private variables
*/
public function init(Services\Providers $projectService)
{
Auth::authOrRedirect([Roles::$owner, Roles::$admin], true);
$this->providerService = $projectService;
}
/**
* get - handle get requests
*/
public function get($params)
{
$providers = $this->providerService->getProviders();
$this->tpl->assign('providers', $providers);
return $this->tpl->display('connector.show');
}
/**
* post - handle post requests
*/
public function post($params)
{
// Redirect.
}
}