Skip to content

Commit c75b95a

Browse files
committed
fix: Allow admin component to define acl_resource for added security
1 parent c5b7ea3 commit c75b95a

10 files changed

Lines changed: 50 additions & 19 deletions

Component/Form/FormViewModel.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Framework\Exception\LocalizedException;
1818
use Magento\Framework\ObjectManagerInterface;
1919
use Magento\Framework\UrlFactory;
20+
use Magento\Tests\NamingConvention\true\string;
2021

2122
/**
2223
* @method FormRepository getRepository()
@@ -48,6 +49,7 @@ public function getJsData(): array
4849
{
4950
return [
5051
...parent::getJsData(),
52+
'aclResource' => $this->getAclResource(),
5153
'item' => $this->getItemData(),
5254
'indexUrl' => $this->getIndexUrl(),
5355
];
@@ -103,6 +105,16 @@ public function getFields(): array
103105
);
104106
}
105107

108+
public function getAclResource(): string
109+
{
110+
$aclResource = (string) $this->getBlock()->getAclResource();
111+
if (!empty($aclResource)) {
112+
return $aclResource;
113+
}
114+
115+
return 'Magento_Backend::admin';
116+
}
117+
106118
private function getIndexUri(): string
107119
{
108120
$indexUrl = $this->getBlock()->getIndexUrl();

Component/Grid/GridViewModel.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public function getNamespace(): string
5555
return $this->getBlock()->getNameInLayout();
5656
}
5757

58+
public function getAclResource(): string
59+
{
60+
$aclResource = (string) $this->getBlock()->getAclResource();
61+
if (!empty($aclResource)) {
62+
return $aclResource;
63+
}
64+
65+
return 'Magento_Backend::admin';
66+
}
67+
5868
public function getCurrentUrl(): string
5969
{
6070
return (string)$this->urlFactory->create()->getUrl('*/*/*');
@@ -170,6 +180,7 @@ public function getJsData(): array
170180
...parent::getJsData(),
171181
...$stateData,
172182
'namespace' => $this->getNamespace(),
183+
'aclResource' => $this->getAclResource(),
173184
'gridFilters' => $this->getGridFilterStateValues(),
174185
'columns' => $columns,
175186
'columnPositions' => $this->getColumnPositions(),

view/adminhtml/templates/script/component-partial/columns-selector-component-partial.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use Magento\Framework\View\Element\Template;
2626
this.activeColumns.push(columnName);
2727
}
2828

29-
this.post({activeColumns: this.activeColumns});
29+
this.submit({activeColumns: this.activeColumns});
3030
}
3131
}
3232
</script>

view/adminhtml/templates/script/component-partial/filters-component-partial.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use Magento\Framework\View\Element\Template;
1818
return this.showFilters ? '_active' : '';
1919
},
2020
applyFilters() {
21-
this.post({filters: this.filters});
21+
this.submit({filters: this.filters});
2222
}
2323
}
2424
</script>

view/adminhtml/templates/script/component-partial/inline-edit-component-partial.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use Magento\Framework\View\Element\Template;
2525
}
2626
};
2727

28-
this.post(postData);
28+
this.submit(postData);
2929
},
3030
}
3131
</script>

view/adminhtml/templates/script/component-partial/limit-component-partial.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use Magento\Framework\View\Element\Template;
1818
return;
1919
}
2020

21-
this.post({limit: event.target.value});
21+
this.submit({limit: event.target.value});
2222
},
2323
setLimitFromElement(event) {
24-
this.post({limit: event.target.getAttribute('data-limit')});
24+
this.submit({limit: event.target.getAttribute('data-limit')});
2525
},
2626
}
2727
</script>

view/adminhtml/templates/script/component-partial/pagination-component-partial.phtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ use Magento\Framework\View\Element\Template;
1414
return;
1515
}
1616

17-
this.post({page: event.target.value});
17+
this.submit({page: event.target.value});
1818
},
1919
nextPage() {
20-
this.post({page: this.page + 1});
20+
this.submit({page: this.page + 1});
2121
},
2222
previousPage(event) {
23-
this.post({page: this.page - 1});
23+
this.submit({page: this.page - 1});
2424
}
2525
}
2626
</script>

view/adminhtml/templates/script/component-type/form-component-type.phtml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,41 @@ use Magento\Framework\View\Element\Template;
1010
<script>
1111
const LokiAdminFormComponentType = {
1212
...LokiComponentType,
13+
aclResource: '',
1314
showOtherActions: false,
15+
submit(data) {
16+
this.post({...data, aclResource: this.aclResource});
17+
},
1418
toggleOtherActions() {
1519
this.showOtherActions = !this.showOtherActions;
1620
},
1721
closeAction() {
1822
window.location.href = this.indexUrl;
1923
},
2024
saveAndContinueAction() {
21-
this.post({
25+
this.submit({
2226
actions: ['save'],
2327
item: this.item,
2428
});
2529
},
2630
saveAndDuplicateAction() {
27-
this.post({
31+
this.submit({
2832
actions: ['save', 'duplicate'],
2933
item: this.item,
3034
});
3135

3236
this.closeAction();
3337
},
3438
saveAndCloseAction() {
35-
this.post({
39+
this.submit({
3640
actions: ['save'],
3741
item: this.item,
3842
});
3943

4044
this.closeAction();
4145
},
4246
deleteAction() {
43-
this.post({
47+
this.submit({
4448
actions: ['delete'],
4549
item: this.item,
4650
});

view/adminhtml/templates/script/component-type/grid-component-type.phtml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ use Magento\Framework\View\Element\Template;
1717
...LokiAdminFiltersComponentPartial,
1818
...LokiAdminMassActionsComponentPartial,
1919
...LokiComponentType,
20+
namespace: '',
21+
aclResource: '',
2022
columns: [],
2123
columnPositions: {},
2224
showOtherActions: false,
2325
gridFilters: {},
26+
submit(data) {
27+
this.post({...data, aclResource: this.aclResource});
28+
},
2429
toggleOtherActions() {
2530
this.showOtherActions = !this.showOtherActions;
2631
},
@@ -34,10 +39,10 @@ use Magento\Framework\View\Element\Template;
3439
}
3540
},
3641
applyFilters() {
37-
this.post({filters: this.gridFilters});
42+
this.submit({filters: this.gridFilters});
3843
},
3944
clearFilters() { // @todo: Rename to clearGridFilters
40-
this.post({
45+
this.submit({
4146
clearFilters: true
4247
});
4348
},
@@ -47,7 +52,7 @@ use Magento\Framework\View\Element\Template;
4752
return;
4853
}
4954

50-
this.post({
55+
this.submit({
5156
removeFilter: targetFilter
5257
});
5358
},
@@ -56,7 +61,7 @@ use Magento\Framework\View\Element\Template;
5661
return;
5762
}
5863

59-
this.post({
64+
this.submit({
6065
sort: {
6166
sortBy: this.$el.getAttribute('data-column'),
6267
sortDirection: this.sortDirection === 'ASC' ? 'DESC' : 'ASC',
@@ -75,8 +80,7 @@ use Magento\Framework\View\Element\Template;
7580
return;
7681
}
7782

78-
this.post({search: this.$el.value});
83+
this.submit({search: this.$el.value});
7984
},
80-
8185
}
8286
</script>

view/adminhtml/templates/script/component/grid-component.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use Magento\Framework\View\Element\Template;
1717
const componentName = itemParts[0];
1818
const propertyName = itemParts[1];
1919
const component = Alpine.store('LokiComponents').get(componentName);
20-
component.post({reposition: {property: propertyName, position: position}});
20+
component.submit({reposition: {property: propertyName, position: position}});
2121
}
2222
}));
2323
});

0 commit comments

Comments
 (0)