Skip to content

Commit

Permalink
Call beforeAction() up front
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jun 27, 2023
1 parent 72877eb commit c0a37e1
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 22 deletions.
6 changes: 5 additions & 1 deletion src/controllers/AssetIndexesController.php
Expand Up @@ -36,11 +36,15 @@ class AssetIndexesController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// No permission no bueno
$this->requirePermission('utility:asset-indexes');
$this->requireAcceptsJson();

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/AssetSettingsController.php
Expand Up @@ -25,10 +25,14 @@ class AssetSettingsController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// All user settings actions require an admin
$this->requireAdmin();

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/BaseElementsController.php
Expand Up @@ -27,10 +27,14 @@ abstract class BaseElementsController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// All actions require control panel requests
$this->requireCpRequest();

return parent::beforeAction($action);
return true;
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/controllers/ConditionsController.php
Expand Up @@ -34,6 +34,12 @@ class ConditionsController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

$this->requireCpRequest();

$baseConfig = Json::decodeIfJson($this->request->getBodyParam('config'));
$config = $this->request->getBodyParam($baseConfig['name']);
$newRuleType = ArrayHelper::remove($config, 'new-rule-type');
Expand All @@ -48,7 +54,7 @@ public function beforeAction($action): bool
$this->_condition->addConditionRule($rule);
}

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/FieldsController.php
Expand Up @@ -38,10 +38,14 @@ class FieldsController extends Controller
*/
public function beforeAction($action): bool
{

This comment has been minimized.

Copy link
@GHOST80872

GHOST80872 Sep 13, 2023

no?

if (!parent::beforeAction($action)) {
return false;
}

// All field actions require an admin
$this->requireAdmin();

return parent::beforeAction($action);
return true;
}

// Groups
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/FsController.php
Expand Up @@ -33,10 +33,14 @@ class FsController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// All asset volume actions require an admin
$this->requireAdmin();

return parent::beforeAction($action);
return true;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/controllers/GraphqlController.php
Expand Up @@ -59,13 +59,17 @@ public function beforeAction($action): bool
throw new NotFoundHttpException(Craft::t('yii', 'Page not found.'));
}

Craft::$app->requireEdition(Craft::Pro);

if ($action->id === 'api') {
$this->enableCsrfValidation = false;
}

return parent::beforeAction($action);
if (!parent::beforeAction($action)) {
return false;
}

Craft::$app->requireEdition(Craft::Pro);

return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/ImageTransformsController.php
Expand Up @@ -31,10 +31,14 @@ class ImageTransformsController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// All image transform actions require an admin
$this->requireAdmin();

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/LivePreviewController.php
Expand Up @@ -36,12 +36,16 @@ class LivePreviewController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// Mark this as a Live Preview request
if ($action->id === 'preview') {
$this->request->setIsLivePreview(true);
}

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/PluginStoreController.php
Expand Up @@ -35,10 +35,14 @@ class PluginStoreController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// All plugin store actions require an admin
$this->requireAdmin(false);

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/PluginsController.php
Expand Up @@ -28,10 +28,14 @@ class PluginsController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// All plugin actions require an admin
$this->requireAdmin();

return parent::beforeAction($action);
return true;
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/controllers/RebrandController.php
Expand Up @@ -35,8 +35,13 @@ class RebrandController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

Craft::$app->requireEdition(Craft::Pro);
return parent::beforeAction($action);

return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/RoutesController.php
Expand Up @@ -26,10 +26,14 @@ class RoutesController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// All route actions require an admin
$this->requireAdmin();

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/SectionsController.php
Expand Up @@ -36,10 +36,14 @@ class SectionsController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// All section actions require an admin
$this->requireAdmin();

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/SitesController.php
Expand Up @@ -36,10 +36,14 @@ class SitesController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// All actions require an admin account
$this->requireAdmin();

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/StructuresController.php
Expand Up @@ -41,6 +41,10 @@ class StructuresController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

$this->requirePostRequest();
$this->requireAcceptsJson();

Expand Down Expand Up @@ -80,7 +84,7 @@ public function beforeAction($action): bool
throw new NotFoundHttpException('Element not found');
}

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/SystemMessagesController.php
Expand Up @@ -27,12 +27,16 @@ class SystemMessagesController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

Craft::$app->requireEdition(Craft::Pro);

// Make sure they have access to the System Messages utility
$this->requirePermission('utility:system-messages');

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/SystemSettingsController.php
Expand Up @@ -40,10 +40,14 @@ class SystemSettingsController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// All system setting actions require an admin
$this->requireAdmin();

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/UserSettingsController.php
Expand Up @@ -28,14 +28,18 @@ class UserSettingsController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// All user settings actions require an admin
$this->requireAdmin();

if ($action->id !== 'save-user-settings') {
Craft::$app->requireEdition(Craft::Pro);
}

return parent::beforeAction($action);
return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/VolumesController.php
Expand Up @@ -35,10 +35,14 @@ class VolumesController extends Controller
*/
public function beforeAction($action): bool
{
if (!parent::beforeAction($action)) {
return false;
}

// All asset volume actions require an admin
$this->requireAdmin();

return parent::beforeAction($action);
return true;
}

/**
Expand Down

0 comments on commit c0a37e1

Please sign in to comment.