Skip to content

Commit

Permalink
Batch updates
Browse files Browse the repository at this point in the history
Tweaks, clean up, and application of new create button method to various grids
  • Loading branch information
smg6511 committed Dec 7, 2024
1 parent 81956c3 commit 7739175
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 229 deletions.
2 changes: 1 addition & 1 deletion core/lexicon/en/dashboards.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@

// Temporarily match old keys to new ones to ensure compatibility
$_lang['dashboard_desc_customizable'] = $_lang['dashboard_customizable_desc'];
$_lang['dashboard_desc_name'] = $_lang['dashboard_name_desc'];
$_lang['dashboard_desc_description'] = $_lang['dashboard_description_desc'];
$_lang['dashboard_desc_hide_trees'] = $_lang['dashboard_hide_trees_desc'];
$_lang['dashboard_desc_name'] = $_lang['dashboard_name_desc'];
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ public function prepareRow(xPDOObject $object)
];
$policyData = $object->toArray();
$policyName = $object->get('name');
$policyPermissions = $object->get('data');
$isCorePolicy = $object->isCorePolicy($policyName);
$this->setActivePermissionsCount($policyData, $object->get('data'));
$this->setActivePermissionsCount($policyData, $policyPermissions);

Check warning on line 241 in core/src/Revolution/Processors/Security/Access/Policy/GetList.php

View check run for this annotation

Codecov / codecov/patch

core/src/Revolution/Processors/Security/Access/Policy/GetList.php#L230-L241

Added lines #L230 - L241 were not covered by tests

$policyData['reserved'] = ['name' => $this->corePolicies];
$policyData['isProtected'] = $isCorePolicy;
Expand All @@ -246,6 +247,7 @@ public function prepareRow(xPDOObject $object)
unset($permissions['delete']);

Check warning on line 247 in core/src/Revolution/Processors/Security/Access/Policy/GetList.php

View check run for this annotation

Codecov / codecov/patch

core/src/Revolution/Processors/Security/Access/Policy/GetList.php#L243-L247

Added lines #L243 - L247 were not covered by tests
}
$policyData['permissions'] = $permissions;
$policyData['policyPermissions'] = array_keys($policyPermissions, 1);
$policyData['description_trans'] = $this->modx->lexicon($policyData['description']);
unset($policyData['data']);

Check warning on line 252 in core/src/Revolution/Processors/Security/Access/Policy/GetList.php

View check run for this annotation

Codecov / codecov/patch

core/src/Revolution/Processors/Security/Access/Policy/GetList.php#L249-L252

Added lines #L249 - L252 were not covered by tests

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

/**
* @param xPDOObject|modAccessPolicy $object
* @deprecated as of 3.1
* @deprecated as of MODX 3.1.0
* @return string
*/
protected function prepareRowClasses(xPDOObject $object)
Expand Down
48 changes: 24 additions & 24 deletions manager/assets/modext/widgets/security/modx.grid.access.policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ MODx.grid.AccessPolicy = function(config = {}) {
columns: [this.sm, {
header: _('policy_name'),
dataIndex: 'name',
id: 'modx-policy--name',
width: 200,
editor: {
xtype: 'textfield',
Expand All @@ -94,7 +93,6 @@ MODx.grid.AccessPolicy = function(config = {}) {
}, {
header: _('description'),
dataIndex: 'description',
id: 'modx-policy--description',
width: 375,
editor: {
xtype: 'textarea'
Expand Down Expand Up @@ -134,15 +132,21 @@ MODx.grid.AccessPolicy = function(config = {}) {
editable: false
}],
tbar: [
this.getCreateButton('policy', 'createPolicy'),
{
text: _('create'),
cls: 'primary-button',
scope: this,
handler: this.createPolicy
}, {
text: _('import'),
scope: this,
handler: this.importPolicy
handler: this.importPolicy,
listeners: {
render: {
fn: function(btn) {
if (!this.userCanCreate) {
btn.hide();
}
},
scope: this
}
}
},
this.getBulkActionsButton('policy', 'Security/Access/Policy/RemoveMultiple'),
'->',
Expand All @@ -161,13 +165,8 @@ MODx.grid.AccessPolicy = function(config = {}) {
this.setShowActionsMenu();

this.on({
render: function(grid) {
this.setEditableColumnAccess(
['modx-policy--name', 'modx-policy--description']
);
},
beforeedit: function(e) {
if (e.record.json.isProtected || !this.userCanEditRecord(e.record)) {
if (!this.userCanEdit || e.record.json.isProtected || !this.userCanEditRecord(e.record)) {
return false;
}
},
Expand All @@ -179,14 +178,18 @@ MODx.grid.AccessPolicy = function(config = {}) {
Ext.extend(MODx.grid.AccessPolicy, MODx.grid.Grid, {
getMenu: function() {
const
record = this.getSelectionModel().getSelected(),
model = this.getSelectionModel(),
record = model.getSelected(),
menu = []
;
if (this.getSelectionModel().getCount() > 1) {
menu.push({
text: _('selected_remove'),
handler: this.removeSelected
});
if (model.getCount() > 1) {
const records = model.getSelections();
if (this.userCanDelete && this.userCanDeleteRecords(records)) {
menu.push({
text: _('selected_remove'),
handler: this.removeSelected.bind(this, 'policy', 'Security/Access/Policy/RemoveMultiple')
});
}
} else {
if (this.userCanEdit && this.userCanEditRecord(record)) {
menu.push({
Expand Down Expand Up @@ -217,10 +220,7 @@ Ext.extend(MODx.grid.AccessPolicy, MODx.grid.Grid, {
});
}
}

if (menu.length > 0) {
this.addContextMenuItem(menu);
}
return menu;
},

editPolicy: function(itm, e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ MODx.grid.AccessPolicyTemplate = function(config = {}) {
columns: [this.sm, {
header: _('name'),
dataIndex: 'name',
id: 'modx-policy-template--name',
width: 200,
editor: {
xtype: 'textfield',
Expand All @@ -92,7 +91,6 @@ MODx.grid.AccessPolicyTemplate = function(config = {}) {
}, {
header: _('description'),
dataIndex: 'description',
id: 'modx-policy-template--description',
width: 375,
editor: {
xtype: 'textarea'
Expand Down Expand Up @@ -126,15 +124,21 @@ MODx.grid.AccessPolicyTemplate = function(config = {}) {
this.getCreatorColumnConfig('policy-template')
],
tbar: [
this.getCreateButton('policy_template', 'createPolicyTemplate'),
{
text: _('create'),
cls: 'primary-button',
scope: this,
handler: this.createPolicyTemplate
}, {
text: _('import'),
scope: this,
handler: this.importPolicyTemplate
handler: this.importPolicyTemplate,
listeners: {
render: {
fn: function(btn) {
if (!this.userCanCreate) {
btn.hide();
}
},
scope: this
}
}
}, {
/*
* Note: Using local this.removeSelected method instead of shared base this.getBulkActionsButton() method here,
Expand Down Expand Up @@ -188,13 +192,8 @@ MODx.grid.AccessPolicyTemplate = function(config = {}) {
this.setShowActionsMenu();

this.on({
render: function(grid) {
this.setEditableColumnAccess(
['modx-policy-template--name', 'modx-policy-template--description']
);
},
beforeedit: function(e) {
if (e.record.json.isProtected || !this.userCanEditRecord(e.record)) {
if (!this.userCanEdit || e.record.json.isProtected || !this.userCanEditRecord(e.record)) {
return false;
}
},
Expand All @@ -206,15 +205,19 @@ MODx.grid.AccessPolicyTemplate = function(config = {}) {
Ext.extend(MODx.grid.AccessPolicyTemplate, MODx.grid.Grid, {
getMenu: function() {
const
record = this.getSelectionModel().getSelected(),
model = this.getSelectionModel(),
record = model.getSelected(),
menu = []
;

if (this.getSelectionModel().getCount() > 1) {
menu.push({
text: _('selected_remove'),
handler: this.removeSelected
});
if (model.getCount() > 1) {
const records = model.getSelections();
if (this.userCanDelete && this.userCanDeleteRecords(records)) {
menu.push({
text: _('selected_remove'),
handler: this.removeSelected
});
}
} else {
if (this.userCanEdit && this.userCanEditRecord(record)) {
menu.push({
Expand Down Expand Up @@ -255,10 +258,7 @@ Ext.extend(MODx.grid.AccessPolicyTemplate, MODx.grid.Grid, {
});
}
}

if (menu.length > 0) {
this.addContextMenuItem(menu);
}
return menu;
},

createPolicyTemplate: function(btn, e) {
Expand Down
32 changes: 4 additions & 28 deletions manager/assets/modext/widgets/security/modx.grid.role.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ MODx.grid.Role = function(config = {}) {
}, {
header: _('name'),
dataIndex: 'name',
id: 'modx-role--name',
width: 150,
sortable: true,
editor: {
Expand Down Expand Up @@ -65,7 +64,6 @@ MODx.grid.Role = function(config = {}) {
}, {
header: _('description'),
dataIndex: 'description',
id: 'modx-role--description',
width: 350,
editor: {
xtype: 'textarea'
Expand All @@ -83,7 +81,6 @@ MODx.grid.Role = function(config = {}) {
{
header: _('authority'),
dataIndex: 'authority',
id: 'modx-role--authority',
width: 60,
align: 'center',
sortable: true,
Expand All @@ -110,7 +107,7 @@ MODx.grid.Role = function(config = {}) {
selectedRecord = grid.getSelectionModel().getSelected(),
roleIsAssigned = selectedRecord.json.isAssigned === 1
;
if (roleIsAssigned) {
if (!selectedRecord.json.isProtected && roleIsAssigned) {
Ext.Msg.show({
title: _('warning'),
msg: _('role_warn_authority_locked'),
Expand All @@ -124,22 +121,7 @@ MODx.grid.Role = function(config = {}) {
}
}
}],
tbar: [{
text: _('create'),
cls: 'primary-button',
handler: this.createRole,
scope: this,
listeners: {
render: {
fn: function(btn) {
if (!this.userCanCreate) {
btn.hide();
}
},
scope: this
}
}
}],
tbar: [this.getCreateButton('role', 'createRole')],
viewConfig: this.getViewConfig(false, false)
});
MODx.grid.Role.superclass.constructor.call(this, config);
Expand All @@ -152,13 +134,8 @@ MODx.grid.Role = function(config = {}) {
this.setShowActionsMenu();

this.on({
render: function() {
this.setEditableColumnAccess(
['modx-role--name', 'modx-role--description', 'modx-role--authority']
);
},
beforeedit: function(e) {
if (e.record.json.isProtected) {
if (!this.userCanEdit || e.record.json.isProtected || (e.field === 'authority' && e.record.json.isAssigned)) {
return false;
}
}
Expand All @@ -169,10 +146,9 @@ Ext.extend(MODx.grid.Role, MODx.grid.Grid, {
getMenu: function() {
const
record = this.getSelectionModel().getSelected(),
{ permissions } = record.json || '',
menu = []
;
if (permissions.delete) {
if (this.userCanDeleteRecord(record)) {
menu.push({
text: _('delete'),
handler: this.remove.createDelegate(this, ['role_remove_confirm', 'Security/Role/Remove'])
Expand Down
Loading

0 comments on commit 7739175

Please sign in to comment.