Fix: Clean up controller namespace structure, remove duplicate Admin subdirectory controllers
This commit is contained in:
BIN
analyticshub-v2.zip
Normal file
BIN
analyticshub-v2.zip
Normal file
Binary file not shown.
@@ -12,19 +12,19 @@ return [
|
|||||||
'routes' => [
|
'routes' => [
|
||||||
// Admin routes
|
// Admin routes
|
||||||
[
|
[
|
||||||
'name' => 'Admin\PageController#index',
|
'name' => 'page#index',
|
||||||
'url' => '/',
|
'url' => '/',
|
||||||
'verb' => 'GET',
|
'verb' => 'GET',
|
||||||
'requirements' => [],
|
'requirements' => [],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'Admin\AdminController#load',
|
'name' => 'admin#load',
|
||||||
'url' => '/admin/load',
|
'url' => '/admin/load',
|
||||||
'verb' => 'GET',
|
'verb' => 'GET',
|
||||||
'requirements' => [],
|
'requirements' => [],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'Admin\AdminController#save',
|
'name' => 'admin#save',
|
||||||
'url' => '/admin/save',
|
'url' => '/admin/save',
|
||||||
'verb' => 'POST',
|
'verb' => 'POST',
|
||||||
'requirements' => [],
|
'requirements' => [],
|
||||||
|
|||||||
@@ -1,144 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace OCA\AnalyticsHub\Controller\Admin;
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
|
||||||
use OCP\AppFramework\Http\JSONResponse;
|
|
||||||
use OCP\IConfig;
|
|
||||||
use OCA\AnalyticsHub\AppInfo\Application;
|
|
||||||
use OCP\AppFramework\Controller;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Admin Settings Controller
|
|
||||||
*
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @NoCSRFRequired
|
|
||||||
*/
|
|
||||||
class PageController extends Controller {
|
|
||||||
|
|
||||||
private $appName;
|
|
||||||
protected $request;
|
|
||||||
private IConfig $config;
|
|
||||||
|
|
||||||
public function __construct(string $appName, IRequest $request, IConfig $config) {
|
|
||||||
parent::__construct($appName, $request);
|
|
||||||
$this->appName = $appName;
|
|
||||||
$this->request = $request;
|
|
||||||
$this->config = $config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Index page - render admin UI
|
|
||||||
*
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @NoCSRFRequired
|
|
||||||
*/
|
|
||||||
public function index(): TemplateResponse {
|
|
||||||
// Load saved configuration
|
|
||||||
$googleClientId = $this->config->getAppValue(Application::APP_NAME, 'google_client_id', '');
|
|
||||||
$googleClientSecret = '•••'; // Masked for display
|
|
||||||
$anthropicApiKey = '••••••••'; // Masked for display
|
|
||||||
$isConfigured = !empty($googleClientId) && !empty($this->config->getAppValue(Application::APP_NAME, 'anthropic_api_key', ''));
|
|
||||||
|
|
||||||
return new TemplateResponse($this->appName, 'admin', [
|
|
||||||
'app_name' => $this->appName,
|
|
||||||
'version' => Application::APP_VERSION,
|
|
||||||
'is_configured' => $isConfigured,
|
|
||||||
'google_client_id' => $googleClientId,
|
|
||||||
'google_client_secret_masked' => $googleClientSecret,
|
|
||||||
'anthropic_api_key_masked' => $anthropicApiKey,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save configuration
|
|
||||||
*
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @NoCSRFRequired
|
|
||||||
*/
|
|
||||||
public function save(): JSONResponse {
|
|
||||||
$params = $this->request->getParams();
|
|
||||||
|
|
||||||
// Validate required fields
|
|
||||||
if (!isset($params['google_client_id']) || empty($params['google_client_id'])) {
|
|
||||||
return new JSONResponse([
|
|
||||||
'success' => false,
|
|
||||||
'error' => 'Google Client ID is required'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($params['google_client_secret']) || empty($params['google_client_secret'])) {
|
|
||||||
return new JSONResponse([
|
|
||||||
'success' => false,
|
|
||||||
'error' => 'Google Client Secret is required'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($params['anthropic_api_key']) || empty($params['anthropic_api_key'])) {
|
|
||||||
return new JSONResponse([
|
|
||||||
'success' => false,
|
|
||||||
'error' => 'Anthropic API Key is required'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Save configuration
|
|
||||||
$this->config->setAppValue(Application::APP_NAME, 'google_client_id', $params['google_client_id']);
|
|
||||||
$this->config->setAppValue(Application::APP_NAME, 'google_client_secret', $params['google_client_secret']);
|
|
||||||
$this->config->setAppValue(Application::APP_NAME, 'anthropic_api_key', $params['anthropic_api_key']);
|
|
||||||
|
|
||||||
// Check if now configured
|
|
||||||
$isConfigured = !empty($params['google_client_id']) && !empty($params['anthropic_api_key']);
|
|
||||||
|
|
||||||
return new JSONResponse([
|
|
||||||
'success' => true,
|
|
||||||
'data' => [
|
|
||||||
'is_configured' => $isConfigured,
|
|
||||||
'message' => 'Configuration saved successfully'
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return new JSONResponse([
|
|
||||||
'success' => false,
|
|
||||||
'error' => $e->getMessage()
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load configuration
|
|
||||||
*
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @NoCSRFRequired
|
|
||||||
*/
|
|
||||||
public function load(): JSONResponse {
|
|
||||||
try {
|
|
||||||
// Load configuration
|
|
||||||
$googleClientId = $this->config->getAppValue(Application::APP_NAME, 'google_client_id', '');
|
|
||||||
$googleClientSecret = ''; // Don't expose secret
|
|
||||||
$anthropicApiKey = ''; // Don't expose secret
|
|
||||||
|
|
||||||
$isConfigured = !empty($googleClientId) && !empty($this->config->getAppValue(Application::APP_NAME, 'anthropic_api_key', ''));
|
|
||||||
|
|
||||||
return new JSONResponse([
|
|
||||||
'success' => true,
|
|
||||||
'data' => [
|
|
||||||
'google_client_id' => $googleClientId,
|
|
||||||
'google_client_secret_masked' => '•••', // Masked
|
|
||||||
'anthropic_api_key_masked' => '••••••••', // Masked
|
|
||||||
'is_configured' => $isConfigured,
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return new JSONResponse([
|
|
||||||
'success' => false,
|
|
||||||
'error' => $e->getMessage()
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace OCA\AnalyticsHub\Controller\Admin;
|
namespace OCA\AnalyticsHub\Controller;
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
@@ -107,3 +107,4 @@ class AdminController {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace OCA\AnalyticsHub\Controller\Page;
|
|
||||||
|
|
||||||
use OCP\IRequest;
|
|
||||||
use OCP\AppFramework\Controller;
|
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Admin Page Controller
|
|
||||||
*
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @NoCSRFRequired
|
|
||||||
*/
|
|
||||||
class PageController extends Controller {
|
|
||||||
|
|
||||||
protected $appName;
|
|
||||||
|
|
||||||
public function __construct(string $appName, IRequest $request) {
|
|
||||||
parent::__construct($appName, $request);
|
|
||||||
$this->appName = $appName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Index page - render admin UI
|
|
||||||
*
|
|
||||||
* @NoAdminRequired
|
|
||||||
* @NoCSRFRequired
|
|
||||||
*/
|
|
||||||
public function index(): TemplateResponse {
|
|
||||||
return new TemplateResponse($this->appName, 'admin', [
|
|
||||||
'app_name' => $this->appName,
|
|
||||||
'version' => '1.0.0',
|
|
||||||
'status' => 'Testing - admin accessible',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace OCA\AnalyticsHub\Controller\Admin;
|
namespace OCA\AnalyticsHub\Controller;
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
|
|
||||||
use OCA\AnalyticsHub\AppInfo\Application;
|
use OCA\AnalyticsHub\AppInfo\Application;
|
||||||
use OCA\AnalyticsHub\Service\GoogleAnalyticsService;
|
use OCA\AnalyticsHub\Service\GoogleAnalyticsService;
|
||||||
use OCA\AnalyticsHub\Service\LLMService;
|
use OCA\AnalyticsHub\Service\LLMService;
|
||||||
@@ -18,7 +17,7 @@ use OCA\AnalyticsHub\Service\LLMService;
|
|||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
class PageController extends Controller {
|
class PageController extends \OCP\AppFramework\Controller {
|
||||||
|
|
||||||
private $appName;
|
private $appName;
|
||||||
private $config;
|
private $config;
|
||||||
|
|||||||
Reference in New Issue
Block a user