Skip to content

Commit

Permalink
TV panel grids updates
Browse files Browse the repository at this point in the history
Apply new permissions methods
  • Loading branch information
smg6511 committed Dec 7, 2024
1 parent dda9081 commit cbcc7e1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public function prepareRow(modResourceGroup $resourceGroup)

$resourceGroupArray = $resourceGroup->toArray();
$resourceGroupArray['access'] = $rgtv ? true : false;
$resourceGroupArray['menu'] = [];

return $resourceGroupArray;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
*/
class GetList extends Processor
{
public $canEdit = false;
public $canEditTemplate = false;

public function checkPermissions()
{
return $this->modx->hasPermission('view_tv');
Expand All @@ -49,8 +52,10 @@ public function initialize()
'dir' => 'ASC',
'tv' => false,
]);
$this->canEdit = $this->modx->hasPermission('edit_tv') && $this->modx->hasPermission('save_tv');
$this->canEditTemplate = $this->modx->hasPermission('edit_template') && $this->modx->hasPermission('save_template');

Check warning on line 56 in core/src/Revolution/Processors/Element/TemplateVar/Template/GetList.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 124 characters

return true;
return parent::initialize();
}

public function process()
Expand Down Expand Up @@ -133,9 +138,14 @@ public function getData()
*/
public function prepareRow(modTemplate $template)
{
$permissions = [
'update' => $this->canEdit,
'updateTemplate' => $this->canEditTemplate && $template->checkPolicy('save')
];
$templateArray = $template->toArray();
$templateArray['category_name'] = $template->get('category_name');
unset($templateArray['content']);
$templateArray['permissions'] = $permissions;

return $templateArray;
}
Expand Down
14 changes: 10 additions & 4 deletions manager/assets/modext/widgets/element/modx.grid.tv.security.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ MODx.grid.TVSecurity = function(config = {}) {
sortable: true,
renderer: {
fn: function(value, metaData, record) {
return this.renderLink(value, {
href: '?a=security/resourcegroup',
target: '_blank'
});
return this.userCanEditResourceGroups
? this.renderLink(value, {
href: '?a=security/resourcegroup',
target: '_blank'
})
: value
;
},
scope: this
}
Expand All @@ -54,6 +57,9 @@ MODx.grid.TVSecurity = function(config = {}) {
]
});
MODx.grid.TVSecurity.superclass.constructor.call(this, config);

this.setUserCanEdit(['edit_tv', 'save_tv']);
this.setUserHasPermissions('editResourceGroups', ['resourcegroup_view', 'resourcegroup_resource_list']);
};
Ext.extend(MODx.grid.TVSecurity, MODx.grid.Grid);
Ext.reg('modx-grid-tv-security', MODx.grid.TVSecurity);
14 changes: 10 additions & 4 deletions manager/assets/modext/widgets/element/modx.grid.tv.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ MODx.grid.TemplateVarTemplate = function(config = {}) {
sortable: true,
renderer: {
fn: function(value, metadata, record) {
return this.renderLink(value, {
href: `?a=element/template/update&id=${record.data.id}`,
target: '_blank'
});
return this.userCanEditTemplate && this.userCanEditRecord(record, 'updateTemplate')
? this.renderLink(value, {
href: `?a=element/template/update&id=${record.data.id}`,
target: '_blank'
})
: value
;
},
scope: this
}
Expand Down Expand Up @@ -86,6 +89,9 @@ MODx.grid.TemplateVarTemplate = function(config = {}) {
]
});
MODx.grid.TemplateVarTemplate.superclass.constructor.call(this, config);

this.setUserCanEdit(['edit_tv', 'save_tv']);
this.setUserHasPermissions('editTemplate', ['edit_template', 'save_template']);
};
Ext.extend(MODx.grid.TemplateVarTemplate, MODx.grid.Grid);
Ext.reg('modx-grid-tv-template', MODx.grid.TemplateVarTemplate);
34 changes: 22 additions & 12 deletions manager/assets/modext/widgets/element/modx.panel.tv.js
Original file line number Diff line number Diff line change
Expand Up @@ -1651,19 +1651,26 @@ MODx.grid.ElementSources = function(config = {}) {
src.getStore().load();
Ext.applyIf(config, {
id: 'modx-grid-element-sources',
fields: ['context_key', 'source', 'name'],
fields: [
'context_key',
'source',
'name'
],
showActionsColumn: false,
autoHeight: true,
primaryKey: 'id',
columns: [{
header: _('context'),
dataIndex: 'context_key',
renderer: {
fn: function(v, md, record) {
return this.renderLink(v, {
href: `?a=context/update&key=${v}`,
target: '_blank'
});
fn: function(value, metaData, record) {
return this.userCanEditContexts
? this.renderLink(value, {
href: `?a=context/update&key=${value}`,
target: '_blank'
})
: value
;
},
scope: this
}
Expand All @@ -1676,11 +1683,14 @@ MODx.grid.ElementSources = function(config = {}) {
}]
});
MODx.grid.ElementSources.superclass.constructor.call(this, config);
this.propRecord = Ext.data.Record.create(['context_key', 'source']);

this.propRecord = Ext.data.Record.create([
'context_key',
'source'
]);

this.setUserCanEdit(['edit_tv', 'save_tv']);
this.setUserHasPermissions('editContexts', ['edit_context', 'save_context']);
};
Ext.extend(MODx.grid.ElementSources, MODx.grid.LocalGrid, {
getMenu: function() {
return [];
}
});
Ext.extend(MODx.grid.ElementSources, MODx.grid.LocalGrid);
Ext.reg('modx-grid-element-sources', MODx.grid.ElementSources);

0 comments on commit cbcc7e1

Please sign in to comment.