Skip to content

Commit 31e05d0

Browse files
authored
Merge pull request #1592 from craftcms/feature/show-read-only-settings-when-allowadminchanges-false
show read-only settings when allowAdminChanges is false
2 parents 1dc9d4a + 303c859 commit 31e05d0

File tree

12 files changed

+754
-417
lines changed

12 files changed

+754
-417
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"prefer-stable": true,
3131
"require": {
3232
"php": "^8.2",
33-
"craftcms/cms": "^5.0.0-beta.2",
33+
"craftcms/cms": "^5.6.0",
3434
"cakephp/utility": "^5.0.0",
3535
"jakeasmith/http_build_url": "^1.0",
3636
"nesbot/carbon": "^2.10|^3.0.0",

composer.lock

Lines changed: 684 additions & 380 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/.vitepress/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function renderInlineCode(tokens, idx, options, env, renderer) {
77
var token = tokens[idx];
88

99
return `<code v-pre ${renderer.renderAttrs(token)}>${escapeHtml(
10-
tokens[idx].content
10+
tokens[idx].content,
1111
)}</code>`;
1212
}
1313

src/Plugin.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public static function config(): array
6666
public bool $hasCpSettings = true;
6767
public bool $hasCpSection = true;
6868

69+
/**
70+
* @inheritdoc
71+
*/
72+
public bool $hasReadOnlyCpSettings = true;
73+
6974
/**
7075
* @var Queue|array|string
7176
* @since 4.5.0
@@ -108,6 +113,14 @@ public function getSettingsResponse(): mixed
108113
return Craft::$app->controller->redirect(UrlHelper::cpUrl('feed-me/settings'));
109114
}
110115

116+
/**
117+
* @inheritdoc
118+
*/
119+
public function getReadOnlySettingsResponse(): mixed
120+
{
121+
return Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('feed-me/settings'));
122+
}
123+
111124
public function getPluginName(): string
112125
{
113126
return Craft::t('feed-me', $this->getSettings()->pluginName);

src/controllers/BaseController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ class BaseController extends Controller
2323
*/
2424
public function actionSettings(): Response
2525
{
26-
$this->requireAdmin();
26+
$this->requireAdmin(false);
2727

2828
$settings = Plugin::$plugin->getSettings();
2929

3030
return $this->renderTemplate('feed-me/settings/general', [
3131
'settings' => $settings,
32+
'readOnly' => !Craft::$app->getConfig()->getGeneral()->allowAdminChanges,
3233
]);
3334
}
3435

src/templates/settings/general.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
{% requireAdmin %}
1+
{% requireAdmin false %}
22

33
{% extends 'feed-me/_layouts/settings' %}
44

55
{% import '_includes/forms' as forms %}
66

7-
{% set fullPageForm = true %}
7+
{% set readOnly = readOnly ?? false %}
8+
{% set fullPageForm = not readOnly %}
9+
10+
{% if readOnly %}
11+
{% set contentNotice = readOnlyNotice() %}
12+
{% endif %}
813

914
{% block content %}
1015
<input type="hidden" name="action" value="plugins/save-plugin-settings">
@@ -20,6 +25,7 @@
2025
first: true,
2126
autofocus: true,
2227
instructions: 'Plugin name for the end user.'|t('feed-me'),
28+
disabled: readOnly,
2329
}) }}
2430

2531
{{ forms.textField({
@@ -28,6 +34,7 @@
2834
label: 'Cache Duration'|t('feed-me'),
2935
value: settings.cache,
3036
instructions: 'Cache duration (in seconds) to cache requests. Note: this only affects calls using the template tag - requests are never cached when triggering directly via the CP.'|t('feed-me'),
37+
disabled: readOnly,
3138
}) }}
3239

3340
<hr>
@@ -45,6 +52,7 @@
4552
},
4653
values: settings.enabledTabs,
4754
instructions: 'Choose which tabs you would like to be shown.'|t('feed-me'),
55+
disabled: readOnly,
4856
}) }}
4957

5058
{% endnamespace %}

src/web/assets/feedme/src/js/feed-me.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $(function () {
2323

2424
// Change the import strategy for Users
2525
var $disableLabel = $(
26-
'input[name="duplicateHandle[]"][value="disable"]'
26+
'input[name="duplicateHandle[]"][value="disable"]',
2727
).next('label');
2828
var originalDisableLabel = $disableLabel.text();
2929
var $disableInstructions = $disableLabel.siblings('.instructions');
@@ -39,7 +39,10 @@ $(function () {
3939
if (value === 'craft-elements-User') {
4040
$disableLabel.text(Craft.t('feed-me', 'Suspend missing users'));
4141
$disableInstructions.text(
42-
Craft.t('feed-me', 'Suspends any users that are missing from the feed.')
42+
Craft.t(
43+
'feed-me',
44+
'Suspends any users that are missing from the feed.',
45+
),
4346
);
4447
} else {
4548
$disableLabel.text(originalDisableLabel);
@@ -118,7 +121,7 @@ $(function () {
118121
// for categories and entries - only show "create if they do not exist" if matching done by "title"
119122
// for users - only show "create if they do not exist" if matching done by "email"
120123
$(
121-
'.categories-field-match select, .entries-field-match select, .users-field-match select'
124+
'.categories-field-match select, .entries-field-match select, .users-field-match select',
122125
).on('change', function (e) {
123126
var match = 'title';
124127
var $selectParent = $(this).parent();
@@ -226,7 +229,7 @@ $(function () {
226229
});
227230

228231
$container.find('select').html(newOptions);
229-
}
232+
},
230233
);
231234

232235
$('.field-extra-settings .element-group-section select').trigger('change');

src/web/assets/feedme/src/lib/selectize.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@
655655
module.exports = factory(
656656
require('jquery'),
657657
require('sifter'),
658-
require('microplugin')
658+
require('microplugin'),
659659
);
660660
} else {
661661
root.Selectize = factory(root.jQuery, root.Sifter, root.MicroPlugin);
@@ -722,7 +722,7 @@
722722
for (var i = 0; i < this._events[event].length; i++) {
723723
this._events[event][i].apply(
724724
this,
725-
Array.prototype.slice.call(arguments, 1)
725+
Array.prototype.slice.call(arguments, 1),
726726
);
727727
}
728728
},
@@ -1288,7 +1288,7 @@
12881288
if (!self.settings.splitOn && self.settings.delimiter) {
12891289
var delimiterEscaped = self.settings.delimiter.replace(
12901290
/[-\/\\^$*+?.()|[\]{}]/g,
1291-
'\\$&'
1291+
'\\$&',
12921292
);
12931293
self.settings.splitOn = new RegExp('\\s*' + delimiterEscaped + '+\\s*');
12941294
}
@@ -1392,7 +1392,7 @@
13921392
if (self.isOpen) {
13931393
self.positionDropdown.apply(self, arguments);
13941394
}
1395-
}
1395+
},
13961396
);
13971397
$window.on('mousemove' + eventNS, function () {
13981398
self.ignoreHover = false;
@@ -1593,7 +1593,7 @@
15931593
if (self.settings.splitOn) {
15941594
setTimeout(function () {
15951595
var splitInput = $.trim(self.$control_input.val() || '').split(
1596-
self.settings.splitOn
1596+
self.settings.splitOn,
15971597
);
15981598
for (var i = 0, n = splitInput.length; i < n; i++) {
15991599
self.createItem(splitInput[i]);
@@ -2089,14 +2089,14 @@
20892089
.stop()
20902090
.animate(
20912091
{scrollTop: scroll_bottom},
2092-
animate ? self.settings.scrollDuration : 0
2092+
animate ? self.settings.scrollDuration : 0,
20932093
);
20942094
} else if (y < scroll) {
20952095
self.$dropdown_content
20962096
.stop()
20972097
.animate(
20982098
{scrollTop: scroll_top},
2099-
animate ? self.settings.scrollDuration : 0
2099+
animate ? self.settings.scrollDuration : 0,
21002100
);
21012101
}
21022102
}
@@ -2110,7 +2110,7 @@
21102110
if (self.settings.mode === 'single') return;
21112111

21122112
self.$activeItems = Array.prototype.slice.apply(
2113-
self.$control.children(':not(input)').addClass('active')
2113+
self.$control.children(':not(input)').addClass('active'),
21142114
);
21152115
if (self.$activeItems.length) {
21162116
self.hideInput();
@@ -2227,7 +2227,7 @@
22272227
calculateScore = self.settings.score.apply(this, [query]);
22282228
if (typeof calculateScore !== 'function') {
22292229
throw new Error(
2230-
'Selectize "score" setting must be a function that returns a function'
2230+
'Selectize "score" setting must be a function that returns a function',
22312231
);
22322232
}
22332233
}
@@ -2237,7 +2237,7 @@
22372237
self.lastQuery = query;
22382238
result = self.sifter.search(
22392239
query,
2240-
$.extend(options, {score: calculateScore})
2240+
$.extend(options, {score: calculateScore}),
22412241
);
22422242
self.currentResults = result;
22432243
} else {
@@ -2345,8 +2345,8 @@
23452345
'optgroup',
23462346
$.extend({}, self.optgroups[optgroup], {
23472347
html: html_children,
2348-
})
2349-
)
2348+
}),
2349+
),
23502350
);
23512351
} else {
23522352
html.push(groups[optgroup].join(''));
@@ -2627,7 +2627,7 @@
26272627
getOption: function (value) {
26282628
return this.getElementWithValue(
26292629
value,
2630-
this.$dropdown_content.find('[data-selectable]')
2630+
this.$dropdown_content.find('[data-selectable]'),
26312631
);
26322632
},
26332633

@@ -2947,7 +2947,7 @@
29472947
escape_html(self.items[i]) +
29482948
'" selected="selected">' +
29492949
escape_html(label) +
2950-
'</option>'
2950+
'</option>',
29512951
);
29522952
}
29532953
if (!options.length && !this.$input.attr('multiple')) {
@@ -3112,7 +3112,7 @@
31123112

31133113
if (self.$activeItems.length) {
31143114
$tail = self.$control.children(
3115-
'.active:' + (direction > 0 ? 'last' : 'first')
3115+
'.active:' + (direction > 0 ? 'last' : 'first'),
31163116
);
31173117
caret = self.$control.children(':not(input)').index($tail);
31183118
if (direction > 0) {
@@ -3393,13 +3393,13 @@
33933393
id = data[self.settings.optgroupValueField] || '';
33943394
html = html.replace(
33953395
regex_tag,
3396-
'<$1 data-group="' + escape_replace(escape_html(id)) + '"'
3396+
'<$1 data-group="' + escape_replace(escape_html(id)) + '"',
33973397
);
33983398
}
33993399
if (templateName === 'option' || templateName === 'item') {
34003400
html = html.replace(
34013401
regex_tag,
3402-
'<$1 data-value="' + escape_replace(escape_html(value || '')) + '"'
3402+
'<$1 data-value="' + escape_replace(escape_html(value || '')) + '"',
34033403
);
34043404
}
34053405

@@ -3687,7 +3687,7 @@
36873687

36883688
instance = new Selectize(
36893689
$input,
3690-
$.extend(true, {}, defaults, settings_element, settings_user)
3690+
$.extend(true, {}, defaults, settings_element, settings_user),
36913691
);
36923692
});
36933693
};
@@ -3781,7 +3781,7 @@
37813781
);
37823782
},
37833783
},
3784-
options
3784+
options,
37853785
);
37863786

37873787
self.setup = (function () {
@@ -3802,7 +3802,7 @@
38023802
equalizeWidth: true,
38033803
equalizeHeight: true,
38043804
},
3805-
options
3805+
options,
38063806
);
38073807

38083808
this.getAdjacentOption = function ($option, direction) {
@@ -3903,7 +3903,7 @@
39033903
className: 'remove',
39043904
append: true,
39053905
},
3906-
options
3906+
options,
39073907
);
39083908

39093909
var self = this;

src/web/assets/feedme/src/scss/_font-awesome.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4752,7 +4752,8 @@ readers do not read off random characters that represent icons */
47524752
font-style: normal;
47534753
font-weight: 400;
47544754
src: url('../fonts/fa-regular-400.eot');
4755-
src: url('../fonts/fa-regular-400.eot?#iefix') format('embedded-opentype'),
4755+
src:
4756+
url('../fonts/fa-regular-400.eot?#iefix') format('embedded-opentype'),
47564757
url('../fonts/fa-regular-400.woff2') format('woff2'),
47574758
url('../fonts/fa-regular-400.woff') format('woff'),
47584759
url('../fonts/fa-regular-400.ttf') format('truetype'),
@@ -4773,7 +4774,8 @@ readers do not read off random characters that represent icons */
47734774
font-style: normal;
47744775
font-weight: 900;
47754776
src: url('../fonts/fa-solid-900.eot');
4776-
src: url('../fonts/fa-solid-900.eot?#iefix') format('embedded-opentype'),
4777+
src:
4778+
url('../fonts/fa-solid-900.eot?#iefix') format('embedded-opentype'),
47774779
url('../fonts/fa-solid-900.woff2') format('woff2'),
47784780
url('../fonts/fa-solid-900.woff') format('woff'),
47794781
url('../fonts/fa-solid-900.ttf') format('truetype'),

src/web/assets/feedme/src/scss/feed-me.css

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)