Skip to content

Commit 3045679

Browse files
committed
Batch updates
Tweaks, clean up, and application of new create button method to various grids
1 parent ba9ee1b commit 3045679

14 files changed

+122
-229
lines changed

Diff for: core/lexicon/en/dashboards.inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,6 @@
107107

108108
// Temporarily match old keys to new ones to ensure compatibility
109109
$_lang['dashboard_desc_customizable'] = $_lang['dashboard_customizable_desc'];
110-
$_lang['dashboard_desc_name'] = $_lang['dashboard_name_desc'];
111110
$_lang['dashboard_desc_description'] = $_lang['dashboard_description_desc'];
112111
$_lang['dashboard_desc_hide_trees'] = $_lang['dashboard_hide_trees_desc'];
112+
$_lang['dashboard_desc_name'] = $_lang['dashboard_name_desc'];

Diff for: core/src/Revolution/Processors/Security/Access/Policy/GetList.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ public function prepareRow(xPDOObject $object)
236236
];
237237
$policyData = $object->toArray();
238238
$policyName = $object->get('name');
239+
$policyPermissions = $object->get('data');
239240
$isCorePolicy = $object->isCorePolicy($policyName);
240-
$this->setActivePermissionsCount($policyData, $object->get('data'));
241+
$this->setActivePermissionsCount($policyData, $policyPermissions);
241242

242243
$policyData['reserved'] = ['name' => $this->corePolicies];
243244
$policyData['isProtected'] = $isCorePolicy;
@@ -246,6 +247,7 @@ public function prepareRow(xPDOObject $object)
246247
unset($permissions['delete']);
247248
}
248249
$policyData['permissions'] = $permissions;
250+
$policyData['policyPermissions'] = array_keys($policyPermissions, 1);
249251
$policyData['description_trans'] = $this->modx->lexicon($policyData['description']);
250252
unset($policyData['data']);
251253

@@ -273,7 +275,7 @@ protected function setActivePermissionsCount(array &$policy, array $data)
273275

274276
/**
275277
* @param xPDOObject|modAccessPolicy $object
276-
* @deprecated as of 3.1
278+
* @deprecated as of MODX 3.1.0
277279
* @return string
278280
*/
279281
protected function prepareRowClasses(xPDOObject $object)

Diff for: manager/assets/modext/widgets/security/modx.grid.access.policy.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ MODx.grid.AccessPolicy = function(config = {}) {
7070
columns: [this.sm, {
7171
header: _('policy_name'),
7272
dataIndex: 'name',
73-
id: 'modx-policy--name',
7473
width: 200,
7574
editor: {
7675
xtype: 'textfield',
@@ -94,7 +93,6 @@ MODx.grid.AccessPolicy = function(config = {}) {
9493
}, {
9594
header: _('description'),
9695
dataIndex: 'description',
97-
id: 'modx-policy--description',
9896
width: 375,
9997
editor: {
10098
xtype: 'textarea'
@@ -134,15 +132,21 @@ MODx.grid.AccessPolicy = function(config = {}) {
134132
editable: false
135133
}],
136134
tbar: [
135+
this.getCreateButton('policy', 'createPolicy'),
137136
{
138-
text: _('create'),
139-
cls: 'primary-button',
140-
scope: this,
141-
handler: this.createPolicy
142-
}, {
143137
text: _('import'),
144138
scope: this,
145-
handler: this.importPolicy
139+
handler: this.importPolicy,
140+
listeners: {
141+
render: {
142+
fn: function(btn) {
143+
if (!this.userCanCreate) {
144+
btn.hide();
145+
}
146+
},
147+
scope: this
148+
}
149+
}
146150
},
147151
this.getBulkActionsButton('policy', 'Security/Access/Policy/RemoveMultiple'),
148152
'->',
@@ -161,13 +165,8 @@ MODx.grid.AccessPolicy = function(config = {}) {
161165
this.setShowActionsMenu();
162166

163167
this.on({
164-
render: function(grid) {
165-
this.setEditableColumnAccess(
166-
['modx-policy--name', 'modx-policy--description']
167-
);
168-
},
169168
beforeedit: function(e) {
170-
if (e.record.json.isProtected || !this.userCanEditRecord(e.record)) {
169+
if (!this.userCanEdit || e.record.json.isProtected || !this.userCanEditRecord(e.record)) {
171170
return false;
172171
}
173172
},
@@ -179,14 +178,18 @@ MODx.grid.AccessPolicy = function(config = {}) {
179178
Ext.extend(MODx.grid.AccessPolicy, MODx.grid.Grid, {
180179
getMenu: function() {
181180
const
182-
record = this.getSelectionModel().getSelected(),
181+
model = this.getSelectionModel(),
182+
record = model.getSelected(),
183183
menu = []
184184
;
185-
if (this.getSelectionModel().getCount() > 1) {
186-
menu.push({
187-
text: _('selected_remove'),
188-
handler: this.removeSelected
189-
});
185+
if (model.getCount() > 1) {
186+
const records = model.getSelections();
187+
if (this.userCanDelete && this.userCanDeleteRecords(records)) {
188+
menu.push({
189+
text: _('selected_remove'),
190+
handler: this.removeSelected.bind(this, 'policy', 'Security/Access/Policy/RemoveMultiple')
191+
});
192+
}
190193
} else {
191194
if (this.userCanEdit && this.userCanEditRecord(record)) {
192195
menu.push({
@@ -217,10 +220,7 @@ Ext.extend(MODx.grid.AccessPolicy, MODx.grid.Grid, {
217220
});
218221
}
219222
}
220-
221-
if (menu.length > 0) {
222-
this.addContextMenuItem(menu);
223-
}
223+
return menu;
224224
},
225225

226226
editPolicy: function(itm, e) {

Diff for: manager/assets/modext/widgets/security/modx.grid.access.policy.template.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ MODx.grid.AccessPolicyTemplate = function(config = {}) {
6868
columns: [this.sm, {
6969
header: _('name'),
7070
dataIndex: 'name',
71-
id: 'modx-policy-template--name',
7271
width: 200,
7372
editor: {
7473
xtype: 'textfield',
@@ -92,7 +91,6 @@ MODx.grid.AccessPolicyTemplate = function(config = {}) {
9291
}, {
9392
header: _('description'),
9493
dataIndex: 'description',
95-
id: 'modx-policy-template--description',
9694
width: 375,
9795
editor: {
9896
xtype: 'textarea'
@@ -126,15 +124,21 @@ MODx.grid.AccessPolicyTemplate = function(config = {}) {
126124
this.getCreatorColumnConfig('policy-template')
127125
],
128126
tbar: [
127+
this.getCreateButton('policy_template', 'createPolicyTemplate'),
129128
{
130-
text: _('create'),
131-
cls: 'primary-button',
132-
scope: this,
133-
handler: this.createPolicyTemplate
134-
}, {
135129
text: _('import'),
136130
scope: this,
137-
handler: this.importPolicyTemplate
131+
handler: this.importPolicyTemplate,
132+
listeners: {
133+
render: {
134+
fn: function(btn) {
135+
if (!this.userCanCreate) {
136+
btn.hide();
137+
}
138+
},
139+
scope: this
140+
}
141+
}
138142
}, {
139143
/*
140144
* Note: Using local this.removeSelected method instead of shared base this.getBulkActionsButton() method here,
@@ -188,13 +192,8 @@ MODx.grid.AccessPolicyTemplate = function(config = {}) {
188192
this.setShowActionsMenu();
189193

190194
this.on({
191-
render: function(grid) {
192-
this.setEditableColumnAccess(
193-
['modx-policy-template--name', 'modx-policy-template--description']
194-
);
195-
},
196195
beforeedit: function(e) {
197-
if (e.record.json.isProtected || !this.userCanEditRecord(e.record)) {
196+
if (!this.userCanEdit || e.record.json.isProtected || !this.userCanEditRecord(e.record)) {
198197
return false;
199198
}
200199
},
@@ -206,15 +205,19 @@ MODx.grid.AccessPolicyTemplate = function(config = {}) {
206205
Ext.extend(MODx.grid.AccessPolicyTemplate, MODx.grid.Grid, {
207206
getMenu: function() {
208207
const
209-
record = this.getSelectionModel().getSelected(),
208+
model = this.getSelectionModel(),
209+
record = model.getSelected(),
210210
menu = []
211211
;
212212

213-
if (this.getSelectionModel().getCount() > 1) {
214-
menu.push({
215-
text: _('selected_remove'),
216-
handler: this.removeSelected
217-
});
213+
if (model.getCount() > 1) {
214+
const records = model.getSelections();
215+
if (this.userCanDelete && this.userCanDeleteRecords(records)) {
216+
menu.push({
217+
text: _('selected_remove'),
218+
handler: this.removeSelected
219+
});
220+
}
218221
} else {
219222
if (this.userCanEdit && this.userCanEditRecord(record)) {
220223
menu.push({
@@ -255,10 +258,7 @@ Ext.extend(MODx.grid.AccessPolicyTemplate, MODx.grid.Grid, {
255258
});
256259
}
257260
}
258-
259-
if (menu.length > 0) {
260-
this.addContextMenuItem(menu);
261-
}
261+
return menu;
262262
},
263263

264264
createPolicyTemplate: function(btn, e) {

Diff for: manager/assets/modext/widgets/security/modx.grid.role.js

+4-28
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ MODx.grid.Role = function(config = {}) {
3333
}, {
3434
header: _('name'),
3535
dataIndex: 'name',
36-
id: 'modx-role--name',
3736
width: 150,
3837
sortable: true,
3938
editor: {
@@ -65,7 +64,6 @@ MODx.grid.Role = function(config = {}) {
6564
}, {
6665
header: _('description'),
6766
dataIndex: 'description',
68-
id: 'modx-role--description',
6967
width: 350,
7068
editor: {
7169
xtype: 'textarea'
@@ -83,7 +81,6 @@ MODx.grid.Role = function(config = {}) {
8381
{
8482
header: _('authority'),
8583
dataIndex: 'authority',
86-
id: 'modx-role--authority',
8784
width: 60,
8885
align: 'center',
8986
sortable: true,
@@ -110,7 +107,7 @@ MODx.grid.Role = function(config = {}) {
110107
selectedRecord = grid.getSelectionModel().getSelected(),
111108
roleIsAssigned = selectedRecord.json.isAssigned === 1
112109
;
113-
if (roleIsAssigned) {
110+
if (!selectedRecord.json.isProtected && roleIsAssigned) {
114111
Ext.Msg.show({
115112
title: _('warning'),
116113
msg: _('role_warn_authority_locked'),
@@ -124,22 +121,7 @@ MODx.grid.Role = function(config = {}) {
124121
}
125122
}
126123
}],
127-
tbar: [{
128-
text: _('create'),
129-
cls: 'primary-button',
130-
handler: this.createRole,
131-
scope: this,
132-
listeners: {
133-
render: {
134-
fn: function(btn) {
135-
if (!this.userCanCreate) {
136-
btn.hide();
137-
}
138-
},
139-
scope: this
140-
}
141-
}
142-
}],
124+
tbar: [this.getCreateButton('role', 'createRole')],
143125
viewConfig: this.getViewConfig(false, false)
144126
});
145127
MODx.grid.Role.superclass.constructor.call(this, config);
@@ -152,13 +134,8 @@ MODx.grid.Role = function(config = {}) {
152134
this.setShowActionsMenu();
153135

154136
this.on({
155-
render: function() {
156-
this.setEditableColumnAccess(
157-
['modx-role--name', 'modx-role--description', 'modx-role--authority']
158-
);
159-
},
160137
beforeedit: function(e) {
161-
if (e.record.json.isProtected) {
138+
if (!this.userCanEdit || e.record.json.isProtected || (e.field === 'authority' && e.record.json.isAssigned)) {
162139
return false;
163140
}
164141
}
@@ -169,10 +146,9 @@ Ext.extend(MODx.grid.Role, MODx.grid.Grid, {
169146
getMenu: function() {
170147
const
171148
record = this.getSelectionModel().getSelected(),
172-
{ permissions } = record.json || '',
173149
menu = []
174150
;
175-
if (permissions.delete) {
151+
if (this.userCanDeleteRecord(record)) {
176152
menu.push({
177153
text: _('delete'),
178154
handler: this.remove.createDelegate(this, ['role_remove_confirm', 'Security/Role/Remove'])

0 commit comments

Comments
 (0)