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,76 @@
<?php
namespace Leantime\Domain\Clients\Controllers;
use Leantime\Core\Auth\Permissions\RequiresPermission;
use Leantime\Core\Controller\Controller;
use Leantime\Core\Controller\Frontcontroller;
use Leantime\Domain\Clients\Permissions\ClientsPermissions;
use Leantime\Domain\Clients\Services\Clients as ClientService;
use Symfony\Component\HttpFoundation\Response;
/**
* DelClient Controller - Deleting clients.
*/
class DelClient extends Controller
{
private ClientService $clientService;
/**
* Initializes dependencies.
*/
public function init(ClientService $clientService): void
{
$this->clientService = $clientService;
}
/**
* Displays the delete client confirmation page.
*
* @param array $params Request parameters
*/
#[RequiresPermission(ClientsPermissions::DELETE, global: true)]
public function get(array $params): Response
{
if (! isset($params['id'])) {
return $this->tpl->display('errors.error403', responseCode: 403);
}
$id = (int) $params['id'];
if ($this->clientService->hasTickets($id)) {
$this->tpl->setNotification($this->language->__('notification.client_has_todos'), 'error');
}
$this->tpl->assign('client', $this->clientService->get($id));
return $this->tpl->display('clients.delClient');
}
/**
* Handles client deletion.
*
* @param array $params Request parameters
*/
#[RequiresPermission(ClientsPermissions::DELETE, global: true)]
public function post(array $params): Response
{
if (! isset($params['id'])) {
return $this->tpl->display('errors.error403', responseCode: 403);
}
$id = (int) $params['id'];
if ($this->clientService->hasTickets($id)) {
$this->tpl->setNotification($this->language->__('notification.client_has_todos'), 'error');
$this->tpl->assign('client', $this->clientService->get($id));
return $this->tpl->display('clients.delClient');
}
$this->clientService->delete($id);
$this->tpl->setNotification($this->language->__('notification.client_deleted'), 'success');
return Frontcontroller::redirect(BASE_URL.'/clients/showAll');
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace Leantime\Domain\Clients\Controllers;
use Leantime\Core\Auth\Permissions\RequiresPermission;
use Leantime\Core\Controller\Controller;
use Leantime\Domain\Clients\Permissions\ClientsPermissions;
use Leantime\Domain\Clients\Services\Clients as ClientService;
use Symfony\Component\HttpFoundation\Response;
/**
* EditClient Controller - Editing clients.
*/
class EditClient extends Controller
{
private ClientService $clientService;
/**
* Initializes dependencies.
*/
public function init(ClientService $clientService): void
{
$this->clientService = $clientService;
}
/**
* Displays the edit client form.
*
* @param array $params Request parameters
*/
#[RequiresPermission(ClientsPermissions::EDIT, global: true)]
public function get(array $params): Response
{
if (! isset($params['id'])) {
return $this->tpl->display('errors.error403', responseCode: 403);
}
$id = (int) $params['id'];
$row = $this->clientService->get($id);
if ($row === false) {
return $this->tpl->display('errors.error404', responseCode: 404);
}
$this->tpl->assign('values', $row);
return $this->tpl->display('clients.editClient');
}
/**
* Handles client edit form submission.
*
* @param array $params Request parameters
*/
#[RequiresPermission(ClientsPermissions::EDIT, global: true)]
public function post(array $params): Response
{
if (! isset($params['id'])) {
return $this->tpl->display('errors.error403', responseCode: 403);
}
$id = (int) $params['id'];
$values = [
'id' => $id,
'name' => $_POST['name'] ?? '',
'street' => $_POST['street'] ?? '',
'zip' => $_POST['zip'] ?? '',
'city' => $_POST['city'] ?? '',
'state' => $_POST['state'] ?? '',
'country' => $_POST['country'] ?? '',
'phone' => $_POST['phone'] ?? '',
'internet' => $_POST['internet'] ?? '',
'email' => $_POST['email'] ?? '',
];
if ($values['name'] !== '') {
$this->clientService->editClient($values);
$this->tpl->setNotification('EDIT_CLIENT_SUCCESS', 'success', 'client_updated');
} else {
$this->tpl->setNotification('NO_NAME', 'error');
}
$this->tpl->assign('values', $values);
return $this->tpl->display('clients.editClient');
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace Leantime\Domain\Clients\Controllers;
use Leantime\Core\Auth\Permissions\RequiresPermission;
use Leantime\Core\Controller\Controller;
use Leantime\Core\Controller\Frontcontroller;
use Leantime\Core\Exceptions\EntityExistsException;
use Leantime\Core\Exceptions\MissingParameterException;
use Leantime\Domain\Clients\Permissions\ClientsPermissions;
use Leantime\Domain\Clients\Services\Clients as ClientService;
use Symfony\Component\HttpFoundation\Response;
/**
* NewClient Controller - Add a new client.
*/
class NewClient extends Controller
{
private ClientService $clientService;
/**
* Initializes dependencies.
*/
public function init(ClientService $clientService): void
{
$this->clientService = $clientService;
}
/**
* Displays the new client form.
*
* @param array $params Request parameters
*/
#[RequiresPermission(ClientsPermissions::CREATE, global: true)]
public function get(array $params): Response
{
$values = [
'name' => '',
'street' => '',
'zip' => '',
'city' => '',
'state' => '',
'country' => '',
'phone' => '',
'internet' => '',
'email' => '',
];
$this->tpl->assign('values', $values);
return $this->tpl->display('clients.newClient');
}
/**
* Handles new client form submission.
*
* @param array $params Request parameters
*/
#[RequiresPermission(ClientsPermissions::CREATE, global: true)]
public function post(array $params): Response
{
$values = [
'name' => $_POST['name'] ?? '',
'street' => $_POST['street'] ?? '',
'zip' => $_POST['zip'] ?? '',
'city' => $_POST['city'] ?? '',
'state' => $_POST['state'] ?? '',
'country' => $_POST['country'] ?? '',
'phone' => $_POST['phone'] ?? '',
'internet' => $_POST['internet'] ?? '',
'email' => $_POST['email'] ?? '',
];
try {
$id = $this->clientService->createClient($values);
$this->tpl->setNotification($this->language->__('notification.client_added_successfully'), 'success', 'new_client');
return Frontcontroller::redirect(BASE_URL.'/clients/showClient/'.$id);
} catch (EntityExistsException) {
$this->tpl->setNotification($this->language->__('notification.client_exists_already'), 'error');
} catch (MissingParameterException) {
$this->tpl->setNotification($this->language->__('notification.client_name_not_specified'), 'error');
}
$this->tpl->assign('values', $values);
return $this->tpl->display('clients.newClient');
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace Leantime\Domain\Clients\Controllers;
use Leantime\Core\Auth\Permissions\RequiresPermission;
use Leantime\Core\Controller\Controller;
use Leantime\Core\Controller\Frontcontroller;
use Leantime\Domain\Clients\Permissions\ClientsPermissions;
use Leantime\Domain\Clients\Services\Clients as ClientService;
use Symfony\Component\HttpFoundation\Response;
/**
* RemoveUser Controller - Remove user from client.
*/
class RemoveUser extends Controller
{
private ClientService $clientService;
/**
* Initializes dependencies.
*/
public function init(ClientService $clientService): void
{
$this->clientService = $clientService;
}
/**
* Displays the remove user confirmation (no state change on GET).
*
* @param array $params Request parameters
*/
#[RequiresPermission(ClientsPermissions::EDIT, global: true)]
public function get(array $params): Response
{
$clientId = (int) ($params['id'] ?? $_GET['id'] ?? 0);
return Frontcontroller::redirect(BASE_URL.'/clients/showClient/'.$clientId);
}
/**
* Handles user removal from client via POST (CSRF-protected).
*
* @param array $params Request parameters
*/
#[RequiresPermission(ClientsPermissions::EDIT, global: true)]
public function post(array $params): Response
{
$clientId = (int) ($params['id'] ?? $_POST['id'] ?? 0);
$userId = (int) ($params['userId'] ?? $_POST['userId'] ?? 0);
if ($clientId === 0 || $userId === 0) {
return $this->tpl->display('errors.error403', responseCode: 403);
}
if ($this->clientService->removeUser($clientId, $userId)) {
$this->tpl->setNotification(
$this->language->__('notification.user_removed_from_client'),
'success'
);
} else {
$this->tpl->setNotification(
$this->language->__('notification.error_removing_user'),
'error'
);
}
return Frontcontroller::redirect(BASE_URL.'/clients/showClient/'.$clientId);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Leantime\Domain\Clients\Controllers;
use Leantime\Core\Auth\Permissions\RequiresPermission;
use Leantime\Core\Controller\Controller;
use Leantime\Domain\Clients\Permissions\ClientsPermissions;
use Leantime\Domain\Clients\Services\Clients as ClientService;
use Symfony\Component\HttpFoundation\Response;
/**
* ShowAll Controller - Show all clients.
*/
class ShowAll extends Controller
{
private ClientService $clientService;
/**
* Initializes dependencies.
*/
public function init(ClientService $clientService): void
{
$this->clientService = $clientService;
}
/**
* Displays the list of all clients.
*
* @param array $params Request parameters
*/
#[RequiresPermission(ClientsPermissions::VIEW, global: true)]
public function get(array $params): Response
{
if (session('userdata.role') == 'admin') {
$this->tpl->assign('admin', true);
}
$this->tpl->assign('allClients', $this->clientService->getAll());
return $this->tpl->display('clients.showAll');
}
}

View File

@@ -0,0 +1,161 @@
<?php
namespace Leantime\Domain\Clients\Controllers;
use Leantime\Core\Auth\Permissions\RequiresPermission;
use Leantime\Core\Controller\Controller;
use Leantime\Core\Controller\Frontcontroller;
use Leantime\Core\Exceptions\MissingParameterException;
use Leantime\Domain\Clients\Permissions\ClientsPermissions;
use Leantime\Domain\Clients\Services\Clients as ClientService;
use Leantime\Domain\Comments\Services\Comments as CommentService;
use Leantime\Domain\Files\Services\Files as FileService;
use Symfony\Component\HttpFoundation\Response;
/**
* ShowClient Controller - Show one client.
*/
class ShowClient extends Controller
{
private ClientService $clientService;
private CommentService $commentService;
private FileService $fileService;
/**
* Initializes dependencies.
*/
public function init(
ClientService $clientService,
CommentService $commentService,
FileService $fileService
): void {
$this->clientService = $clientService;
$this->commentService = $commentService;
$this->fileService = $fileService;
if (! session()->exists('lastPage')) {
session(['lastPage' => BASE_URL.'/clients/showAll']);
}
}
/**
* Displays the client detail page.
*
* @param array $params Request parameters
*/
#[RequiresPermission(ClientsPermissions::VIEW, global: true)]
public function get(array $params): Response
{
if (! isset($params['id'])) {
return $this->tpl->display('errors.error404', responseCode: 404);
}
$id = (int) $params['id'];
$client = $this->clientService->get($id);
if ($client === false) {
return $this->tpl->display('errors.error404', responseCode: 404);
}
// Handle file deletion via GET param
if (isset($_GET['delFile'])) {
$result = $this->fileService->deleteFile($_GET['delFile']);
if ($result === true) {
$this->tpl->setNotification($this->language->__('notifications.file_deleted'), 'success', 'clientfile_deleted');
return Frontcontroller::redirect(BASE_URL.'/clients/showClient/'.$id.'#files');
} else {
$this->tpl->setNotification($this->language->__('notifications.file_deleted_error'), 'error');
}
}
if (session('userdata.role') == 'admin') {
$this->tpl->assign('admin', true);
}
$this->tpl->assign('client', $client);
$pageData = $this->clientService->getClientPageData($id);
array_map([$this->tpl, 'assign'], array_keys($pageData), array_values($pageData));
return $this->tpl->display('clients.showClient');
}
/**
* Handles client detail form submissions (save, upload, comment).
*
* @param array $params Request parameters
*/
#[RequiresPermission(ClientsPermissions::EDIT, global: true)]
public function post(array $params): Response
{
if (! isset($params['id'])) {
return $this->tpl->display('errors.error404', responseCode: 404);
}
$id = (int) $params['id'];
$client = $this->clientService->get($id);
if ($client === false) {
return $this->tpl->display('errors.error404', responseCode: 404);
}
// Handle file upload
if (isset($_POST['upload'])) {
if (isset($_FILES['file']) && $_FILES['file']['tmp_name'] != '') {
$this->fileService->upload($_FILES, 'client', $id);
$this->tpl->setNotification($this->language->__('notifications.file_upload_success'), 'success', 'clientfile_uploaded');
} else {
$this->tpl->setNotification($this->language->__('notifications.file_upload_error'), 'error');
}
}
// Handle comment
if (isset($_POST['comment'])) {
if ($this->commentService->addComment($_POST, 'client', $id, $client)) {
$this->tpl->setNotification($this->language->__('notifications.comment_create_success'), 'success');
} else {
$this->tpl->setNotification($this->language->__('notifications.comment_create_error'), 'error');
}
}
// Handle client save
if (isset($_POST['save'])) {
$values = [
'id' => $id,
'name' => $_POST['name'] ?? '',
'street' => $_POST['street'] ?? '',
'zip' => $_POST['zip'] ?? '',
'city' => $_POST['city'] ?? '',
'state' => $_POST['state'] ?? '',
'country' => $_POST['country'] ?? '',
'phone' => $_POST['phone'] ?? '',
'internet' => $_POST['internet'] ?? '',
'email' => $_POST['email'] ?? '',
];
try {
$this->clientService->updateClient($values);
$this->tpl->setNotification($this->language->__('notification.client_saved_successfully'), 'success');
} catch (MissingParameterException) {
$this->tpl->setNotification($this->language->__('notification.client_name_not_specified'), 'error');
}
$client = $values;
}
if (session('userdata.role') == 'admin') {
$this->tpl->assign('admin', true);
}
$this->tpl->assign('client', $client);
$pageData = $this->clientService->getClientPageData($id);
array_map([$this->tpl, 'assign'], array_keys($pageData), array_values($pageData));
return $this->tpl->display('clients.showClient');
}
}