Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cms 660 show read-only settings when allowAdminChanges is disabled #16265

Open
wants to merge 27 commits into
base: 5.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
829c9e3
switch revision notice to a generic class
i-just Dec 3, 2024
c2f10a7
show settings > system items in readOnly mode
i-just Dec 3, 2024
429121b
no need for a new method...
i-just Dec 3, 2024
e8b7b0b
show user profile fields but disabled
i-just Dec 3, 2024
e0e4952
show settings > content items in readOnly mode
i-just Dec 3, 2024
f3b4dcb
show settings > media items in readOnly mode
i-just Dec 3, 2024
c51a748
handle settings > plugins in readOnly mode
i-just Dec 3, 2024
5db7e2d
translation & notice on the main settings page
i-just Dec 3, 2024
d01af67
build
i-just Dec 3, 2024
f529d67
missed notices
i-just Dec 3, 2024
839637d
Merge remote-tracking branch 'origin/5.6' into feature/cms-660-show-r…
i-just Dec 3, 2024
e9c504e
email settings > site overrides read only
i-just Dec 3, 2024
55c2803
twig require admin node and token parser updates
i-just Dec 4, 2024
7560a1d
Merge branch '5.6' into feature/cms-660-show-read-only-settings-when-…
i-just Dec 4, 2024
8897d9a
missed from the merge
i-just Dec 4, 2024
9310f99
updated notice wording
i-just Dec 6, 2024
0f6338e
Merge branch '5.6' into feature/cms-660-show-read-only-settings-when-…
i-just Dec 6, 2024
0555a75
add disabled attr to the lightswitch field
i-just Dec 9, 2024
0c6399e
disabled attr for the .menubtn
i-just Dec 9, 2024
68a9b80
adds readOnlySettingsReady method to the transport adapters
i-just Dec 9, 2024
9e40f04
bug fix
i-just Dec 9, 2024
1ffd021
added Field->readOnlySettingsReady()
i-just Dec 9, 2024
099d6bd
disabled field layout designer shouldn't be keyboard focusable
i-just Dec 9, 2024
8327c21
added Fs->readOnlySettingsReady()
i-just Dec 9, 2024
0dedce3
Merge branch '5.6' into feature/cms-660-show-read-only-settings-when-…
i-just Dec 9, 2024
a77ad09
Merge branch '5.6' into feature/cms-660-show-read-only-settings-when-…
brandonkelly Dec 11, 2024
3db71f9
Merge branch '5.6' into feature/cms-660-show-read-only-settings-when-…
brandonkelly Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/base/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ public function afterSaveSettings(): void
}
}

/**
* @inheritdoc
*/
public function canViewReadOnlySettings(): bool
{
return false;
}

/**
* Instantiates and returns the plugin’s installation migration, if it has one.
*
Expand Down
8 changes: 8 additions & 0 deletions src/base/PluginInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,12 @@ public function beforeSaveSettings(): bool;
* @since 3.0.16
*/
public function afterSaveSettings(): void;

/**
* Returns whether plugin is prepared to view its settings when `allowAdminChanges` is disabled.
*
* @return bool
* @since 5.6.0
*/
public function canViewReadOnlySettings(): bool;
}
12 changes: 10 additions & 2 deletions src/controllers/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ class CategoriesController extends Controller
*/
public function actionGroupIndex(): Response
{
$this->requireAdmin();
$this->requireAdmin(false);

$groups = Craft::$app->getCategories()->getAllGroups();

return $this->renderTemplate('settings/categories/index.twig', [
'categoryGroups' => $groups,
'readOnly' => !Craft::$app->getConfig()->getGeneral()->allowAdminChanges,
]);
}

Expand All @@ -73,7 +74,13 @@ public function actionGroupIndex(): Response
*/
public function actionEditCategoryGroup(?int $groupId = null, ?CategoryGroup $categoryGroup = null): Response
{
$this->requireAdmin();
$this->requireAdmin(false);

$readOnly = !Craft::$app->getConfig()->getGeneral()->allowAdminChanges;

if ($groupId === null && $readOnly) {
throw new ForbiddenHttpException('Administrative changes are disallowed in this environment.');
}

$variables = [];

Expand Down Expand Up @@ -112,6 +119,7 @@ public function actionEditCategoryGroup(?int $groupId = null, ?CategoryGroup $ca

$variables['groupId'] = $groupId;
$variables['categoryGroup'] = $categoryGroup;
$variables['readOnly'] = $readOnly;

return $this->renderTemplate('settings/categories/_edit.twig', $variables);
}
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1184,10 +1184,10 @@ private function _revisionNotice($elementType): string
{
return
Html::beginTag('div', [
'class' => 'revision-notice',
'class' => 'content-notice',
]) .
Html::tag('div', '', [
'class' => ['revision-icon'],
'class' => ['content-notice-icon'],
'aria' => ['hidden' => 'true'],
'data' => ['icon' => 'lightbulb'],
]) .
Expand Down
52 changes: 40 additions & 12 deletions src/controllers/EntryTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use craft\models\Section;
use craft\web\Controller;
use yii\web\BadRequestHttpException;
use yii\web\ForbiddenHttpException;
use yii\web\NotFoundHttpException;
use yii\web\Response;

Expand All @@ -33,13 +34,26 @@
*/
class EntryTypesController extends Controller
{
private bool $readOnly;

/**
* @inheritdoc
*/
public function beforeAction($action): bool
{
// All section actions require an admin
$this->requireAdmin();
// All actions require an admin account (but not allowAdminChanges)
$this->requireAdmin(false);

$viewActions = ['edit', 'table-data'];
if (in_array($action->id, $viewActions)) {
// Some actions require admin but not allowAdminChanges
$this->requireAdmin(false);
} else {
// All other actions require an admin & allowAdminChanges
$this->requireAdmin();
}

$this->readOnly = !Craft::$app->getConfig()->getGeneral()->allowAdminChanges;

return parent::beforeAction($action);
}
Expand All @@ -54,6 +68,10 @@ public function beforeAction($action): bool
*/
public function actionEdit(?int $entryTypeId = null, ?EntryType $entryType = null): Response
{
if ($entryTypeId === null && $this->readOnly) {
throw new ForbiddenHttpException('Administrative changes are disallowed in this environment.');
}

if ($entryTypeId !== null) {
if ($entryType === null) {
$entryType = Craft::$app->getEntries()->getEntryTypeById($entryTypeId);
Expand Down Expand Up @@ -91,26 +109,36 @@ public function actionEdit(?int $entryTypeId = null, ?EntryType $entryType = nul
->title($title)
->addCrumb(Craft::t('app', 'Settings'), 'settings')
->addCrumb(Craft::t('app', 'Entry Types'), 'settings/entry-types')
->action('entry-types/save')
->redirectUrl('settings/entry-types')
->addAltAction(Craft::t('app', 'Save and continue editing'), [
'redirect' => 'settings/entry-types/{id}',
'shortcut' => true,
'retainScroll' => true,
])
->contentTemplate('settings/entry-types/_edit.twig', [
'entryTypeId' => $entryTypeId,
'entryType' => $entryType,
'typeName' => Entry::displayName(),
'lowerTypeName' => Entry::lowerDisplayName(),
'readOnly' => $this->readOnly,
]);

if ($entryType->id) {
if (!$this->readOnly) {
$response
->addAltAction(Craft::t('app', 'Delete'), [
->action('entry-types/save')
->redirectUrl('settings/entry-types')
->addAltAction(Craft::t('app', 'Save and continue editing'), [
'redirect' => 'settings/entry-types/{id}',
'shortcut' => true,
'retainScroll' => true,
]);
} else {
$response->noticeHtml(Cp::allowAdminChangesReadOnlyNotice());
}

if ($entryType->id) {
if (!$this->readOnly) {
$response->addAltAction(Craft::t('app', 'Delete'), [
'action' => 'entry-types/delete',
'destructive' => true,
])
]);
}

$response
->metaSidebarHtml(Cp::metadataHtml([
Craft::t('app', 'ID') => $entryType->id,
Craft::t('app', 'Used by') => function() use ($entryType) {
Expand Down
Loading
Loading