Fix: Proper Controller extension and test route
- Fixed AdminController to extend OCP\AppFramework\Controller - Annotations (@NoAdminRequired, @NoCSRFRequired) now work - Proper parent::__construct() call - Added test route /admin/test for debugging - Returns JSON to confirm controller works - Helps diagnose routing vs permission issues - Simplified routes to essential ones only - admin#index and admin#test This should resolve 'Access forbidden' for system admin users. The key fix was extending the proper Controller base class.
This commit is contained in:
@@ -4,12 +4,22 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace OCA\AnalyticsHub;
|
namespace OCA\AnalyticsHub;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Routes for Mini-CMO Analytics Hub
|
* Routes for Mini-CMO Analytics Hub
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'routes' => [
|
'routes' => [
|
||||||
|
// Test route
|
||||||
|
[
|
||||||
|
'name' => 'admin#test',
|
||||||
|
'url' => '/test',
|
||||||
|
'verb' => 'GET',
|
||||||
|
'requirements' => [],
|
||||||
|
],
|
||||||
// Admin routes
|
// Admin routes
|
||||||
[
|
[
|
||||||
'name' => 'admin#index',
|
'name' => 'admin#index',
|
||||||
@@ -17,23 +27,5 @@ return [
|
|||||||
'verb' => 'GET',
|
'verb' => 'GET',
|
||||||
'requirements' => [],
|
'requirements' => [],
|
||||||
],
|
],
|
||||||
[
|
|
||||||
'name' => 'admin#save',
|
|
||||||
'url' => '/admin/save',
|
|
||||||
'verb' => 'POST',
|
|
||||||
'requirements' => [],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'admin#load',
|
|
||||||
'url' => '/admin/load',
|
|
||||||
'verb' => 'GET',
|
|
||||||
'requirements' => [],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'admin#getStatus',
|
|
||||||
'url' => '/admin/status',
|
|
||||||
'verb' => 'GET',
|
|
||||||
'requirements' => [],
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -4,21 +4,23 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace OCA\AnalyticsHub\Controller;
|
namespace OCA\AnalyticsHub\Controller;
|
||||||
|
|
||||||
use OCP\IRequest;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http;
|
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
|
use OCP\IRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple Admin Controller for testing
|
* Admin Settings Controller
|
||||||
*
|
*
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
class AdminController {
|
class AdminController extends Controller {
|
||||||
|
|
||||||
private $appName;
|
private $appName;
|
||||||
|
|
||||||
public function __construct($appName) {
|
public function __construct($appName, IRequest $request) {
|
||||||
|
parent::__construct($appName, $request);
|
||||||
$this->appName = $appName;
|
$this->appName = $appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +34,21 @@ class AdminController {
|
|||||||
return new TemplateResponse($this->appName, 'admin', [
|
return new TemplateResponse($this->appName, 'admin', [
|
||||||
'app_name' => $this->appName,
|
'app_name' => $this->appName,
|
||||||
'version' => '1.0.0',
|
'version' => '1.0.0',
|
||||||
'status' => 'testing',
|
'status' => 'testing - admin accessible',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test route - simple JSON response
|
||||||
|
*
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @NoCSRFRequired
|
||||||
|
*/
|
||||||
|
public function test(): JSONResponse {
|
||||||
|
return new JSONResponse([
|
||||||
|
'success' => true,
|
||||||
|
'message' => 'Analytics Hub controller is working!',
|
||||||
|
'app_name' => $this->appName,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user