Fixes: Simplify PageController, fix config API, update deployment package (2026-02-17)
- Removed service dependencies from PageController constructor - Fixed AdminController config API signatures - Cleaned up Application.php resource loading - Updated template with proper resource includes - Simplified routes.php - Reduced analyticshub.zip from 50KB to 27KB - Status: Fixed and ready for redeployment
This commit is contained in:
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace OCA\AnalyticsHub\AppInfo;
|
||||
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\Util;
|
||||
|
||||
/**
|
||||
* Application class for Mini-CMO Analytics Hub
|
||||
@@ -18,9 +17,5 @@ class Application extends App {
|
||||
|
||||
public function __construct(array $urlParams = []) {
|
||||
parent::__construct(self::APP_ID, $urlParams);
|
||||
|
||||
// Load scripts and styles for admin page
|
||||
Util::addStyle(self::APP_ID, 'admin');
|
||||
Util::addScript(self::APP_ID, 'admin');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,6 @@
|
||||
<php min-version="7.4"/>
|
||||
</dependencies>
|
||||
<navigation>
|
||||
<admin>analyticshub.page.index</admin>
|
||||
<admin>page#index</admin>
|
||||
</navigation>
|
||||
</info>
|
||||
|
||||
@@ -10,24 +10,22 @@ namespace OCA\AnalyticsHub;
|
||||
|
||||
return [
|
||||
'routes' => [
|
||||
// Admin routes
|
||||
// Main page route
|
||||
[
|
||||
'name' => 'page#index',
|
||||
'url' => '/',
|
||||
'verb' => 'GET',
|
||||
'requirements' => [],
|
||||
],
|
||||
// Admin configuration routes (AJAX)
|
||||
[
|
||||
'name' => 'admin#load',
|
||||
'url' => '/admin/load',
|
||||
'verb' => 'GET',
|
||||
'requirements' => [],
|
||||
],
|
||||
[
|
||||
'name' => 'admin#save',
|
||||
'url' => '/admin/save',
|
||||
'verb' => 'POST',
|
||||
'requirements' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -31,11 +31,11 @@ class AdminController {
|
||||
* Load configuration
|
||||
*/
|
||||
public function load(): JSONResponse {
|
||||
$clientId = $this->config->getAppValue('google_client_id', 'analyticshub', '');
|
||||
$apiKey = $this->config->getAppValue('anthropic_api_key', 'analyticshub', '');
|
||||
$llmEndpoint = $this->config->getAppValue('llm_api_endpoint', 'analyticshub', '');
|
||||
$llmModel = $this->config->getAppValue('llm_model', 'analyticshub', '');
|
||||
$refreshToken = $this->config->getAppValue('google_refresh_token', 'analyticshub', '');
|
||||
$clientId = $this->config->getAppValue('analyticshub', 'google_client_id', '');
|
||||
$apiKey = $this->config->getAppValue('analyticshub', 'anthropic_api_key', '');
|
||||
$llmEndpoint = $this->config->getAppValue('analyticshub', 'llm_api_endpoint', '');
|
||||
$llmModel = $this->config->getAppValue('analyticshub', 'llm_model', '');
|
||||
$refreshToken = $this->config->getAppValue('analyticshub', 'google_refresh_token', '');
|
||||
|
||||
// Check if configured
|
||||
$isConfigured = !empty($clientId) && !empty($apiKey) && !empty($refreshToken);
|
||||
@@ -92,22 +92,22 @@ class AdminController {
|
||||
}
|
||||
|
||||
// Save configuration
|
||||
$this->config->setAppValue('google_client_id', 'analyticshub', $clientId);
|
||||
$this->config->setAppValue('google_client_secret', 'analyticshub', $clientSecret);
|
||||
$this->config->setAppValue('analyticshub', 'google_client_id', $clientId);
|
||||
$this->config->setAppValue('analyticshub', 'google_client_secret', $clientSecret);
|
||||
|
||||
if (!empty($refreshToken)) {
|
||||
$this->config->setAppValue('google_refresh_token', 'analyticshub', $refreshToken);
|
||||
$this->config->setAppValue('analyticshub', 'google_refresh_token', $refreshToken);
|
||||
}
|
||||
|
||||
if (!empty($llmEndpoint)) {
|
||||
$this->config->setAppValue('llm_api_endpoint', 'analyticshub', $llmEndpoint);
|
||||
$this->config->setAppValue('analyticshub', 'llm_api_endpoint', $llmEndpoint);
|
||||
}
|
||||
|
||||
if (!empty($llmModel)) {
|
||||
$this->config->setAppValue('llm_model', 'analyticshub', $llmModel);
|
||||
$this->config->setAppValue('analyticshub', 'llm_model', $llmModel);
|
||||
}
|
||||
|
||||
$this->config->setAppValue('anthropic_api_key', 'analyticshub', $apiKey);
|
||||
$this->config->setAppValue('analyticshub', 'anthropic_api_key', $apiKey);
|
||||
|
||||
// Check if fully configured
|
||||
$isConfigured = !empty($clientId) && !empty($clientSecret) && !empty($apiKey) && !empty($refreshToken);
|
||||
|
||||
@@ -7,81 +7,77 @@ namespace OCA\AnalyticsHub\Controller;
|
||||
use OCP\IRequest;
|
||||
use OCP\IConfig;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCA\AnalyticsHub\Service\GoogleAnalyticsService;
|
||||
use OCA\AnalyticsHub\Service\LLMService;
|
||||
|
||||
/**
|
||||
* Admin Settings Controller
|
||||
*
|
||||
* @NoAdminRequired
|
||||
* @AdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
class PageController extends \OCP\AppFramework\Controller {
|
||||
|
||||
protected $appName;
|
||||
protected $config;
|
||||
protected $gaService;
|
||||
protected $llmService;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
IConfig $config,
|
||||
GoogleAnalyticsService $gaService,
|
||||
LLMService $llmService
|
||||
IConfig $config
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->appName = $appName;
|
||||
$this->config = $config;
|
||||
$this->gaService = $gaService;
|
||||
$this->llmService = $llmService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Index page - render admin UI
|
||||
*
|
||||
* @NoAdminRequired
|
||||
* @AdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index(): TemplateResponse {
|
||||
// Check configuration status gracefully
|
||||
$isConfigured = false;
|
||||
$isGAConfigured = false;
|
||||
$isLLMConfigured = false;
|
||||
// Get configuration values directly from config service
|
||||
$clientId = $this->config->getAppValue('analyticshub', 'google_client_id', '');
|
||||
$clientSecret = $this->config->getAppValue('analyticshub', 'google_client_secret', '');
|
||||
$refreshToken = $this->config->getAppValue('analyticshub', 'google_refresh_token', '');
|
||||
$apiKey = $this->config->getAppValue('analyticshub', 'anthropic_api_key', '');
|
||||
$llmEndpoint = $this->config->getAppValue('analyticshub', 'llm_api_endpoint', '');
|
||||
$llmModel = $this->config->getAppValue('analyticshub', 'llm_model', '');
|
||||
|
||||
try {
|
||||
$isGAConfigured = $this->gaService->isConfigured();
|
||||
$isLLMConfigured = $this->llmService->isConfigured();
|
||||
$isConfigured = $isGAConfigured && $isLLMConfigured;
|
||||
} catch (\Exception $e) {
|
||||
// If service initialization fails, app is not configured
|
||||
$isConfigured = false;
|
||||
// Check if configured
|
||||
$isConfigured = !empty($clientId) && !empty($clientSecret) && !empty($refreshToken) && !empty($apiKey);
|
||||
$isGAConfigured = !empty($clientId) && !empty($clientSecret) && !empty($refreshToken);
|
||||
$isLLMConfigured = !empty($apiKey);
|
||||
|
||||
// Mask secrets for display
|
||||
$maskedClientSecret = '';
|
||||
if (!empty($clientSecret)) {
|
||||
$maskedClientSecret = '••••••••••••••••';
|
||||
}
|
||||
|
||||
// Get configuration values (masked for secrets)
|
||||
$clientId = $this->config->getAppValue('google_client_id', 'analyticshub', '');
|
||||
$apiKey = $this->config->getAppValue('anthropic_api_key', 'analyticshub', '');
|
||||
$llmEndpoint = $this->config->getAppValue('llm_api_endpoint', 'analyticshub', '');
|
||||
$llmModel = $this->config->getAppValue('llm_model', 'analyticshub', '');
|
||||
$maskedRefreshToken = '';
|
||||
if (!empty($refreshToken)) {
|
||||
$maskedRefreshToken = substr($refreshToken, 0, 8) . '...' . substr($refreshToken, -4);
|
||||
}
|
||||
|
||||
// Mask API key for display
|
||||
$maskedApiKey = '';
|
||||
if (!empty($apiKey)) {
|
||||
$maskedApiKey = substr($apiKey, 0, 8) . '...' . substr($apiKey, -4);
|
||||
}
|
||||
|
||||
return new TemplateResponse($this->appName, 'admin', [
|
||||
'app_name' => $this->appName,
|
||||
return new TemplateResponse('analyticshub', 'admin', [
|
||||
'app_name' => 'Mini-CMO Analytics Hub',
|
||||
'version' => '1.0.0',
|
||||
'status' => 'Ready for development',
|
||||
'status' => $isConfigured ? 'Ready' : 'Configuration Required',
|
||||
'is_configured' => $isConfigured,
|
||||
'is_ga_configured' => $isGAConfigured,
|
||||
'is_llm_configured' => $isLLMConfigured,
|
||||
'google_client_id' => $clientId,
|
||||
'google_client_secret_masked' => $maskedClientSecret,
|
||||
'google_refresh_token_masked' => $maskedRefreshToken,
|
||||
'llm_api_endpoint' => $llmEndpoint,
|
||||
'llm_model' => $llmModel,
|
||||
'anthropic_api_key_masked' => $maskedApiKey,
|
||||
'request' => $this->request,
|
||||
]);
|
||||
], 'blank'); // Use 'blank' rendering mode for admin pages
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
style('display:none');
|
||||
style('analyticshub', 'admin');
|
||||
script('analyticshub', 'admin');
|
||||
?>
|
||||
|
||||
<div id="analytics-hub-settings" class="section analytics-hub-settings">
|
||||
@@ -20,8 +21,6 @@ style('display:none');
|
||||
<?php endif; ?>
|
||||
|
||||
<form id="analytics-hub-form" class="analytics-hub-settings__form">
|
||||
<?php print_unescaped($l->t('CSRF Token: %s', [$_['request']->getParam('requesttoken')])); ?>
|
||||
<input type="hidden" name="requesttoken" value="<?php p($_['request']->getParam('requesttoken')); ?>" />
|
||||
|
||||
<!-- Google Analytics Configuration -->
|
||||
<div class="analytics-hub-settings__section">
|
||||
|
||||
Reference in New Issue
Block a user