Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rchavik committed Sep 16, 2020
1 parent 26d8d93 commit b48ae21
Show file tree
Hide file tree
Showing 37 changed files with 61 additions and 66 deletions.
1 change: 0 additions & 1 deletion Acl/config/routes.php
Expand Up @@ -6,7 +6,6 @@
Router::plugin('Croogo/Acl', ['path' => '/'], function (RouteBuilder $route) {
$route->prefix('admin', function (RouteBuilder $route) {
$route->setExtensions(['json']);
$route->applyMiddleware('csrf');

$route->scope('/acl', [], function (RouteBuilder $route) {
$route->fallbacks();
Expand Down
3 changes: 2 additions & 1 deletion Acl/src/Controller/Component/AutoLoginComponent.php
Expand Up @@ -61,7 +61,8 @@ public function startup(Event $event)
return;
}

$this->_registry->Cookie->configKey($this->getConfig('cookieName'), $this->getConfig('cookieConfig'));
// FIXME
// $this->_registry->Cookie->configKey($this->getConfig('cookieName'), $this->getConfig('cookieConfig'));

$setting = $this->_registry->Auth->getConfig('authenticate.all');
list(, $this->_userModel) = pluginSplit($setting['userModel']);
Expand Down
22 changes: 13 additions & 9 deletions Acl/src/Controller/Component/FilterComponent.php
Expand Up @@ -74,10 +74,14 @@ protected function _configure()
if (!$this->_registry->has('Croogo/Acl.AutoLogin')) {
$this->_registry->load('Croogo/Acl.AutoLogin');
if (!$this->_registry->has('Cookie')) {
$this->_registry->load('Cookie');
// FIXME
// $this->_registry->load('Cookie');
}
}

$this->_controller->loadComponent('Auth'); // FIXME
$this->_controller->loadComponent('Acl.Acl'); // FIXME

//Configure AuthComponent
$this->_controller->Auth->setConfig('authenticate', [
AuthComponent::ALL => [
Expand All @@ -97,7 +101,7 @@ protected function _configure()
if (!function_exists('mcrypt_encrypt') && !function_exists('openssl_encrypt')) {
$notice = __d('croogo', '"AutoLogin" (Remember Me) disabled since mcrypt_encrypt or openssl_encrypt is not available');
$this->log($notice, LOG_CRIT);
if ($this->_controller->request->getParam('prefix') == 'admin') {
if ($this->_controller->getRequest()->getParam('prefix') == 'admin') {
$this->_controller->Flash->error($notice);
}
if (isset($this->_controller->Settings)) {
Expand Down Expand Up @@ -125,7 +129,7 @@ protected function _configure()
]
]);

if ($this->_controller->request->getParam('prefix') == 'admin' &&
if ($this->_controller->getRequest()->getParam('prefix') == 'admin' &&
!$this->_controller->Auth->user()) {
$this->_controller->Auth->setConfig('authError', false);
}
Expand All @@ -146,7 +150,7 @@ public function configureLoginActions()
'controller' => 'Users',
'action' => 'login',
]);
if ($this->request->getParam('prefix') === 'admin') {
if ($this->_controller->getRequest()->getParam('prefix') === 'admin') {
$this->_controller->Auth->setConfig('loginAction', [
'prefix' => 'admin',
'plugin' => 'Croogo/Users',
Expand All @@ -159,7 +163,7 @@ public function configureLoginActions()
'controller' => 'Users',
'action' => 'login',
]);
if ($this->request->getParam('prefix') == 'admin') {
if ($this->_controller->getRequest()->getParam('prefix') == 'admin') {
$dashboardUrl = Configure::read('Site.dashboard_url');
if (is_string($dashboardUrl)) {
$converter = new StringConverter();
Expand All @@ -172,7 +176,7 @@ public function configureLoginActions()
$this->_controller->Auth->setConfig('loginRedirect', $loginRedirect);
}

if ($this->_controller->request->is('ajax')) {
if ($this->_controller->getRequest()->is('ajax')) {
$this->_controller->Auth->setConfig('unauthorizedRedirect', false);
} else {
$this->_controller->Auth->setConfig('unauthorizedRedirect', [
Expand All @@ -184,7 +188,7 @@ public function configureLoginActions()

$config = Configure::read('Acl');
if (!empty($config['Auth']) && is_array($config['Auth'])) {
$isAdminRequest = !empty($this->_controller->request->getParam('admin'));
$isAdminRequest = !empty($this->_controller->getRequest()->getParam('admin'));
$authActions = [
'loginAction',
'loginRedirect',
Expand Down Expand Up @@ -219,9 +223,9 @@ public function auth()

$authorizer = $this->_controller->Auth->getAuthorize('Croogo/Acl.AclCached');

if ($this->_controller->Acl->check('Role-public', $authorizer->action($this->_controller->request))) {
if ($this->_controller->Acl->check('Role-public', $authorizer->action($this->_controller->getRequest()))) {
$this->_controller->Auth->allow(
$this->_controller->request->getParam('action')
$this->_controller->getRequest()->getParam('action')
);
}
}
Expand Down
1 change: 0 additions & 1 deletion Blocks/config/routes.php
Expand Up @@ -6,7 +6,6 @@
Router::plugin('Croogo/Blocks', ['path' => '/'], function (RouteBuilder $route) {
$route->prefix('admin', function (RouteBuilder $route) {
$route->setExtensions(['json']);
$route->applyMiddleware('csrf');

$route->scope('/blocks', [], function (RouteBuilder $route) {
$route->fallbacks();
Expand Down
2 changes: 1 addition & 1 deletion Blocks/src/View/Helper/RegionsHelper.php
Expand Up @@ -154,7 +154,7 @@ public function blocks($regionAlias, $options = [])
/**
* @return array
*/
public function implementedEvents()
public function implementedEvents(): array
{
$events = parent::implementedEvents();
$events['Helper.Layout.beforeFilter'] = [
Expand Down
1 change: 0 additions & 1 deletion Comments/config/routes.php
Expand Up @@ -6,7 +6,6 @@
Router::plugin('Croogo/Comments', ['path' => '/'], function (RouteBuilder $route) {
$route->prefix('admin', function (RouteBuilder $route) {
$route->setExtensions(['json']);
$route->applyMiddleware('csrf');

$route->scope('/comments', [], function (RouteBuilder $route) {
$route->fallbacks();
Expand Down
1 change: 0 additions & 1 deletion Contacts/config/routes.php
Expand Up @@ -6,7 +6,6 @@
Router::plugin('Croogo/Contacts', ['path' => '/'], function (RouteBuilder $route) {
$route->prefix('admin', function (RouteBuilder $route) {
$route->setExtensions(['json']);
$route->applyMiddleware('csrf');

$route->scope('/contacts', [], function (RouteBuilder $route) {
$route->fallbacks();
Expand Down
4 changes: 0 additions & 4 deletions Core/config/routes.php
@@ -1,15 +1,11 @@
<?php

use Cake\Core\Configure;
use Cake\Http\Middleware\CsrfProtectionMiddleware;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
use Croogo\Core\Utility\StringConverter;

Router::prefix('admin', function (RouteBuilder $routeBuilder) {
$routeBuilder->registerMiddleware('csrf', new CsrfProtectionMiddleware());
$routeBuilder->applyMiddleware('csrf');

$dashboardUrl = Configure::read('Site.dashboard_url');
if (!$dashboardUrl) {
return;
Expand Down
6 changes: 4 additions & 2 deletions Core/src/Controller/AppController.php
Expand Up @@ -183,7 +183,8 @@ public function beforeFilter(EventInterface $event)
}

if (!$this->getRequest()->is('api')) {
$this->Security->blackHoleCallback = '_securityError';
// FIXME
// $this->Security->blackHoleCallback = '_securityError';
if ($this->getRequest()->getParam('action') == 'delete' && $this->getRequest()->getParam('prefix') == 'admin') {
$this->getRequest()->allowMethod('post');
}
Expand Down Expand Up @@ -241,6 +242,7 @@ public function _securityError($type = null, $exception = null)
*/
protected function _setupAclComponent()
{
$this->loadComponent('Croogo/Acl.Filter'); /// FIXME
$config = Configure::read('Access Control');
if (isset($config['rowLevel']) && $config['rowLevel'] == true) {
if (strpos($config['models'], str_replace('/', '\/', $this->modelClass)) === false) {
Expand All @@ -258,7 +260,7 @@ protected function _setupAclComponent()
*/
protected function _setupPrg()
{
$this->loadComponent('Search.Prg', [
$this->loadComponent('Search.Search', [
'queryStringWhitelist' => ['sort', 'direction', 'limit', 'chooser'],
'actions' => ['index']
]);
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Controller/Component/BulkProcessComponent.php
Expand Up @@ -40,7 +40,7 @@ class BulkProcessComponent extends Component
public function beforeFilter(Event $event)
{
$this->_controller = $event->getSubject();
if ($this->_controller->request->getParam('action') == 'process') {
if ($this->_controller->getRequest()->getParam('action') == 'process') {
$this->_controller->Security->setConfig('validatePost', false);
}
}
Expand Down
8 changes: 4 additions & 4 deletions Core/src/Controller/Component/RecaptchaComponent.php
Expand Up @@ -4,7 +4,7 @@
use Cake\Controller\Component;
use Cake\Controller\ComponentRegistry;
use Cake\Core\Configure;
use Cake\Network\Http\Client;
use Cake\Http\Client;

/**
* Recaptcha Component
Expand Down Expand Up @@ -33,22 +33,22 @@ class RecaptchaComponent extends Component
*/
public function __construct(ComponentRegistry $registry, array $config = [])
{
$this->_defaultConfig['modelClass'] = $registry->getController()->modelClass;
$this->_defaultConfig['modelClass'] = $registry->getController()->getModelType();
parent::__construct($registry, $config);
}

/**
* initialize
*/
public function initialize(array $config)
public function initialize(array $config): void
{
$controller = $this->_registry->getController();
$this->_controller = $controller;
if ($controller->getName() === 'CakeError') {
return;
}

if (in_array($this->request->getParam('action'), $this->getConfig('actions'))) {
if (in_array($controller->getRequest()->getParam('action'), $this->getConfig('actions'))) {
$controller->Security->validatePost = false;
}

Expand Down
3 changes: 2 additions & 1 deletion Core/src/Croogo.php
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Croogo\Core;

Expand Down Expand Up @@ -287,7 +288,7 @@ public static function options($configKey, $object, $option = null)
$options = Hash::merge(Configure::read($configKey . '.*'), $options);
}

if ($option) {
if (!empty($options[$option])) {
return $options[$option];
}

Expand Down
2 changes: 1 addition & 1 deletion Core/src/Model/Behavior/CachedBehavior.php
Expand Up @@ -3,8 +3,8 @@
namespace Croogo\Core\Model\Behavior;

use Cake\Cache\Cache;
use Cake\Cache\InvalidArgumentException;
use Cake\ORM\Behavior;
use InvalidArgumentException;

/**
* Cached Behavior
Expand Down
1 change: 0 additions & 1 deletion Dashboards/config/routes.php
Expand Up @@ -6,7 +6,6 @@
Router::plugin('Croogo/Dashboards', ['path' => '/'], function (RouteBuilder $route) {
$route->prefix('admin', function (RouteBuilder $route) {
$route->setExtensions(['json']);
$route->applyMiddleware('csrf');

$route->scope('/dashboards', [], function (RouteBuilder $route) {
$route->fallbacks();
Expand Down
1 change: 0 additions & 1 deletion Example/config/routes.php
Expand Up @@ -6,7 +6,6 @@
Router::plugin('Croogo/Example', ['path' => '/'], function (RouteBuilder $routeBuilder) {
$routeBuilder->prefix('admin', function (RouteBuilder $routeBuilder) {
$routeBuilder->setExtensions(['json']);
$routeBuilder->applyMiddleware('csrf');

$routeBuilder->connect('/route/here', [
'plugin' => 'Croogo/Example',
Expand Down
1 change: 0 additions & 1 deletion Extensions/config/routes.php
Expand Up @@ -6,7 +6,6 @@
Router::plugin('Croogo/Extensions', ['path' => '/'], function (RouteBuilder $route) {
$route->prefix('admin', function (RouteBuilder $route) {
$route->setExtensions(['json']);
$route->applyMiddleware('csrf');

$route->scope('/extensions', [], function (RouteBuilder $route) {
$route->fallbacks();
Expand Down
1 change: 0 additions & 1 deletion FileManager/config/routes.php
Expand Up @@ -6,7 +6,6 @@
Router::plugin('Croogo/FileManager', ['path' => '/'], function (RouteBuilder $route) {
$route->prefix('admin', function (RouteBuilder $route) {
$route->setExtensions(['json']);
$route->applyMiddleware('csrf');

$route->scope('/file-manager', [], function (RouteBuilder $route) {
$route->fallbacks();
Expand Down
2 changes: 1 addition & 1 deletion FileManager/src/Controller/Admin/AttachmentsController.php
Expand Up @@ -45,7 +45,7 @@ class AttachmentsController extends AppController
public function initialize(): void
{
parent::initialize();
$this->loadComponent('Search.Prg', [
$this->loadComponent('Search.Search', [
'actions' => [
'index', 'browse', 'listings',
],
Expand Down
2 changes: 1 addition & 1 deletion FileManager/src/Model/Behavior/LinkedAssetsBehavior.php
Expand Up @@ -26,7 +26,7 @@ class LinkedAssetsBehavior extends Behavior
* @param array $config
* @return void
*/
public function initialize(array $config = [])
public function initialize(array $config): void
{
$this->_table->addAssociations([
'hasMany' => [
Expand Down
4 changes: 2 additions & 2 deletions FileManager/src/Model/Table/AssetUsagesTable.php
Expand Up @@ -19,7 +19,7 @@ class AssetUsagesTable extends CroogoTable
* @param array $config
* @return void
*/
public function initialize(array $config)
public function initialize(array $config): void
{
$this->setTable('asset_usages');

Expand All @@ -42,7 +42,7 @@ public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $o
{
if (!empty($entity->featured_image)) {
$entity->type = 'FeaturedImage';
$entity->unsetProperty('featured_image');
$entity->unset('featured_image');
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions FileManager/src/Model/Table/AssetsTable.php
Expand Up @@ -16,7 +16,7 @@ class AssetsTable extends CroogoTable
'file' => 'checkFileUpload'
];

public function initialize(array $config)
public function initialize(array $config): void
{
$this->setTable('assets');

Expand Down Expand Up @@ -45,7 +45,7 @@ public function initialize(array $config)
$this->addBehavior('Croogo/Core.Trackable');
}

public function validationDefault(Validator $validator)
public function validationDefault(Validator $validator): Validator
{
$validator
->requirePresence('adapter', 'create');
Expand Down
16 changes: 8 additions & 8 deletions FileManager/src/Model/Table/AttachmentsTable.php
Expand Up @@ -40,7 +40,7 @@ class AttachmentsTable extends CroogoTable
* @param array $config
* @return void
*/
public function initialize(array $config)
public function initialize(array $config): void
{
$this->setTable('attachments');

Expand All @@ -62,32 +62,32 @@ public function initialize(array $config)

$this->searchManager()
->add('title', 'Search.Like', [
'field' => $this->Assets->aliasField('filename'),
'fields' => $this->Assets->aliasField('filename'),
'before' => true,
'after' => true,
])
->add('search', 'Search.Callback', [
'callback' => [$this, 'filterAttachments'],
])
->add('filename', 'Search.Like', [
'field' => $this->Assets->aliasField('filename'),
'fields' => $this->Assets->aliasField('filename'),
'before' => true,
'after' => true,
])
->value('model', [
'field' => $this->Assets->AssetUsages->aliasField('model'),
'fields' => $this->Assets->AssetUsages->aliasField('model'),
])
->value('foreign_key', [
'field' => $this->Assets->AssetUsages->aliasField('foreign_key'),
'fields' => $this->Assets->AssetUsages->aliasField('foreign_key'),
])
->value('asset_id', [
'field' => $this->Assets->aliasField('id'),
'fields' => $this->Assets->aliasField('id'),
])
->value('id', [
'field' => $this->aliasField('id'),
'fields' => $this->aliasField('id'),
])
->value('type', [
'field' => $this->Assets->AssetUsages->aliasField('type'),
'fields' => $this->Assets->AssetUsages->aliasField('type'),
]);
}

Expand Down

0 comments on commit b48ae21

Please sign in to comment.