Skip to content

Translated descriptions for policies, policy templates and policy template groups #14009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 49 additions & 131 deletions _build/data/transport.core.accesspolicies.php

Large diffs are not rendered by default.

58 changes: 13 additions & 45 deletions _build/data/transport.core.accesspolicytemplategroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,24 @@
* For complete copyright and license information, see the COPYRIGHT and LICENSE
* files found in the top-level directory of this distribution.
*/

use MODX\Revolution\modAccessPolicyTemplateGroup;

$templateGroups = [];

/* administrator group templates */
$templateGroups['1']= $xpdo->newObject(modAccessPolicyTemplateGroup::class);
$templateGroups['1']->fromArray([
'id' => 1,
'name' => 'Admin',
'description' => 'All admin policy templates.',
]);

/* Object group templates */
$templateGroups['2']= $xpdo->newObject(modAccessPolicyTemplateGroup::class);
$templateGroups['2']->fromArray([
'id' => 2,
'name' => 'Object',
'description' => 'All Object-based policy templates.',
]);

/* Resource group templates */
$templateGroups['3']= $xpdo->newObject(modAccessPolicyTemplateGroup::class);
$templateGroups['3']->fromArray([
'id' => 3,
'name' => 'Resource',
'description' => 'All Resource-based policy templates.',
]);

/* Element group templates */
$templateGroups['4']= $xpdo->newObject(modAccessPolicyTemplateGroup::class);
$templateGroups['4']->fromArray([
'id' => 4,
'name' => 'Element',
'description' => 'All Element-based policy templates.',
]);
$groups = modAccessPolicyTemplateGroup::getCoreGroups();

/* Media Source group templates */
$templateGroups['5']= $xpdo->newObject(modAccessPolicyTemplateGroup::class);
$templateGroups['5']->fromArray([
'id' => 5,
'name' => 'MediaSource',
'description' => 'All Media Source-based policy templates.',
]);
foreach (modAccessPolicyTemplateGroup::getCoreGroups() as $index => $groupName) {
$group = $xpdo->newObject(modAccessPolicyTemplateGroup::class);
$group->fromArray(
[
'id' => $index + 1,
'name' => $groupName,
'description' => sprintf('policy_template_group_%s_desc', strtolower($groupName)),
]
Comment on lines +19 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the id a primary key here that would require the parameter setPrimaryKeys set to true?
I'm just wondering what makes this different from the modAccessPolicy objects we create.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My solution based on the previous script (https://github.com/modxcms/revolution/blob/3.x/_build/data/transport.core.accesspolicytemplategroups.php), and this index guaranties that order will be always the same. Maybe I can simplify it more, I don't remember exactly already why I chose this solution.

);

/* Namespace group templates */
$templateGroups['6']= $xpdo->newObject(modAccessPolicyTemplateGroup::class);
$templateGroups['6']->fromArray([
'id' => 6,
'name' => 'Namespace',
'description' => 'All Namespace based policy templates.',
]);
$templateGroups[] = $group;
}

return $templateGroups;
105 changes: 20 additions & 85 deletions _build/data/transport.core.accesspolicytemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,99 +7,34 @@
* For complete copyright and license information, see the COPYRIGHT and LICENSE
* files found in the top-level directory of this distribution.
*/

use MODX\Revolution\modAccessPolicyTemplate;

$templates = [];

/* administrator template/policy */
$templates['1']= $xpdo->newObject(modAccessPolicyTemplate::class);
$templates['1']->fromArray([
'id' => 1,
'name' => 'AdministratorTemplate',
'description' => 'Context administration policy template with all permissions.',
'lexicon' => 'permissions',
]);
$permissions = include dirname(__FILE__).'/permissions/transport.policy.tpl.administrator.php';
if (is_array($permissions)) {
$templates['1']->addMany($permissions);
} else { $xpdo->log(xPDO::LOG_LEVEL_ERROR,'Could not load Administrator Policy Template.'); }

/* resource template/policy */
$templates['2']= $xpdo->newObject(modAccessPolicyTemplate::class);
$templates['2']->fromArray([
'id' => 2,
'name' => 'ResourceTemplate',
'description' => 'Resource Policy Template with all attributes.',
'lexicon' => 'permissions',
]);
$permissions = include dirname(__FILE__).'/permissions/transport.policy.tpl.resource.php';
if (is_array($permissions)) {
$templates['2']->addMany($permissions);
} else { $xpdo->log(xPDO::LOG_LEVEL_ERROR,'Could not load Resource Template Permissions.'); }
foreach (modAccessPolicyTemplate::getCoreTemplates() as $index => $templateName) {

/* object template and policies */
$templates['3']= $xpdo->newObject(modAccessPolicyTemplate::class);
$templates['3']->fromArray([
'id' => 3,
'name' => 'ObjectTemplate',
'description' => 'Object Policy Template with all attributes.',
'lexicon' => 'permissions',
]);
$permissions = include dirname(__FILE__).'/permissions/transport.policy.tpl.object.php';
if (is_array($permissions)) {
$templates['3']->addMany($permissions);
} else { $xpdo->log(xPDO::LOG_LEVEL_ERROR,'Could not load Object Template Permissions.'); }
$templateNameLowered = str_replace('template', '', strtolower($templateName));

/* element template/policy */
$templates['4']= $xpdo->newObject(modAccessPolicyTemplate::class);
$templates['4']->fromArray([
'id' => 4,
'name' => 'ElementTemplate',
'description' => 'Element Policy Template with all attributes.',
'lexicon' => 'permissions',
]);
$permissions = include dirname(__FILE__).'/permissions/transport.policy.tpl.element.php';
if (is_array($permissions)) {
$templates['4']->addMany($permissions);
} else { $xpdo->log(xPDO::LOG_LEVEL_ERROR,'Could not load Element Template Permissions.'); }
$template = $xpdo->newObject(modAccessPolicyTemplate::class);
$template->fromArray(
[
'id' => $index + 1,
'name' => $templateName,
'description' => sprintf('policy_template_%s_desc', $templateNameLowered),
'lexicon' => 'permissions',
]
);

/* media source template/policy */
$templates['5']= $xpdo->newObject(modAccessPolicyTemplate::class);
$templates['5']->fromArray([
'id' => 5,
'name' => 'MediaSourceTemplate',
'description' => 'Media Source Policy Template with all attributes.',
'lexicon' => 'permissions',
]);
$permissions = include dirname(__FILE__).'/permissions/transport.policy.tpl.media_source.php';
if (is_array($permissions)) {
$templates['5']->addMany($permissions);
} else { $xpdo->log(xPDO::LOG_LEVEL_ERROR,'Could not load Media Source Template Permissions.'); }
$permissions = include __DIR__ . sprintf('/permissions/transport.policy.tpl.%s.php', $templateNameLowered);

/* context template policies */
$templates['6']= $xpdo->newObject(modAccessPolicyTemplate::class);
$templates['6']->fromArray([
'id' => 6,
'name' => 'ContextTemplate',
'description' => 'Context Policy Template with all attributes.',
'lexicon' => 'permissions',
]);
$permissions = include dirname(__FILE__).'/permissions/transport.policy.tpl.context.php';
if (is_array($permissions)) {
$templates['6']->addMany($permissions);
} else { $xpdo->log(xPDO::LOG_LEVEL_ERROR,'Could not load Context Template Permissions.'); }
if (is_array($permissions)) {
$template->addMany($permissions);
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, sprintf('Could not load %s Policy Template.', $templateName));
}

/* namespace template/policy */
$templates['7']= $xpdo->newObject(modAccessPolicyTemplate::class);
$templates['7']->fromArray([
'id' => 7,
'name' => 'NamespaceTemplate',
'description' => 'Namespace Policy Template with all attributes.',
'lexicon' => 'permissions',
]);
$permissions = include dirname(__FILE__).'/permissions/transport.policy.tpl.namespace.php';
if (is_array($permissions)) {
$templates['7']->addMany($permissions);
} else { $xpdo->log(xPDO::LOG_LEVEL_ERROR,'Could not load Namespace Template Permissions.'); }
$templates[] = $template;
}

return $templates;
22 changes: 11 additions & 11 deletions _build/resolvers/resolve.policies.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

/* map of Policy -> Template */
$map = [
'Resource' => 'ResourceTemplate',
'Administrator' => 'AdministratorTemplate',
'Content Editor' => 'AdministratorTemplate',
'Load Only' => 'ObjectTemplate',
'Load, List and View' => 'ObjectTemplate',
'Object' => 'ObjectTemplate',
'Context' => 'ContextTemplate',
'Element' => 'ElementTemplate',
'Media Source Admin' => 'MediaSourceTemplate',
'Media Source User' => 'MediaSourceTemplate',
'Hidden Namespace' => 'NamespaceTemplate',
modAccessPolicy::POLICY_RESOURCE => modAccessPolicyTemplate::TEMPLATE_RESOURCE,
modAccessPolicy::POLICY_ADMINISTRATOR => modAccessPolicyTemplate::TEMPLATE_ADMINISTRATOR,
modAccessPolicy::POLICY_CONTENT_EDITOR => modAccessPolicyTemplate::TEMPLATE_ADMINISTRATOR,
modAccessPolicy::POLICY_LOAD_ONLY => modAccessPolicyTemplate::TEMPLATE_OBJECT,
modAccessPolicy::POLICY_LOAD_LIST_VIEW => modAccessPolicyTemplate::TEMPLATE_OBJECT,
modAccessPolicy::POLICY_OBJECT => modAccessPolicyTemplate::TEMPLATE_OBJECT,
modAccessPolicy::POLICY_CONTEXT => modAccessPolicyTemplate::TEMPLATE_CONTEXT,
modAccessPolicy::POLICY_ELEMENT => modAccessPolicyTemplate::TEMPLATE_ELEMENT,
modAccessPolicy::POLICY_MEDIA_SOURCE_ADMIN => modAccessPolicyTemplate::TEMPLATE_MEDIA_SOURCE,
modAccessPolicy::POLICY_MEDIA_SOURCE_USER => modAccessPolicyTemplate::TEMPLATE_MEDIA_SOURCE,
modAccessPolicy::POLICY_HIDDEN_NAMESPACE => modAccessPolicyTemplate::TEMPLATE_NAMESPACE,
];

$policies = $transport->xpdo->getCollection(modAccessPolicy::class);
Expand Down
36 changes: 22 additions & 14 deletions _build/resolvers/resolve.policytemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,48 @@
* Resolve PolicyTemplates to their PolicyTemplateGroups
*
* @var xPDOTransport $transport
* @package modx
* @package modx
* @subpackage build
*/

use MODX\Revolution\modAccessPolicyTemplate;
use MODX\Revolution\modAccessPolicyTemplateGroup;
use xPDO\xPDO;

$success= false;
$success = false;

/* map of Template -> TemplateGroup */
$map = [
'ResourceTemplate' => 'Resource',
'AdministratorTemplate' => 'Admin',
'ObjectTemplate' => 'Object',
'ContextTemplate' => 'Object',
'ElementTemplate' => 'Element',
'MediaSourceTemplate' => 'MediaSource',
'NamespaceTemplate' => 'Namespace',
modAccessPolicyTemplate::TEMPLATE_RESOURCE => modAccessPolicyTemplateGroup::GROUP_RESOURCE,
modAccessPolicyTemplate::TEMPLATE_ADMINISTRATOR => modAccessPolicyTemplateGroup::GROUP_ADMINISTRATOR,
modAccessPolicyTemplate::TEMPLATE_OBJECT => modAccessPolicyTemplateGroup::GROUP_OBJECT,
modAccessPolicyTemplate::TEMPLATE_CONTEXT => modAccessPolicyTemplateGroup::GROUP_CONTEXT,
modAccessPolicyTemplate::TEMPLATE_ELEMENT => modAccessPolicyTemplateGroup::GROUP_ELEMENT,
modAccessPolicyTemplate::TEMPLATE_MEDIA_SOURCE => modAccessPolicyTemplateGroup::GROUP_MEDIA_SOURCE,
modAccessPolicyTemplate::TEMPLATE_NAMESPACE => modAccessPolicyTemplateGroup::GROUP_NAMESPACE,
];

$templates = $transport->xpdo->getCollection(modAccessPolicyTemplate::class);
$templates = $transport->xpdo->getIterator(modAccessPolicyTemplate::class);

/** @var modAccessPolicyTemplate $template */
foreach ($templates as $template) {
if (isset($map[$template->get('name')])) {
$templateGroup = $transport->xpdo->getObject(modAccessPolicyTemplateGroup::class,
['name' => $map[$template->get('name')]]);
$templateGroup = $transport->xpdo->getObject(
modAccessPolicyTemplateGroup::class,
['name' => $map[$template->get('name')]]
);
if ($templateGroup) {
$template->set('template_group',$templateGroup->get('id'));
$template->set('template_group', $templateGroup->get('id'));
$success = $template->save();
} else {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Core AccessPolicyTemplateGroup {$map[$template->get('name')]} is missing!");
$transport->xpdo->log(
xPDO::LOG_LEVEL_ERROR,
"Core AccessPolicyTemplateGroup {$map[$template->get('name')]} is missing!"
);
}
} else {
$success = true;
}
}

return $success;
35 changes: 31 additions & 4 deletions core/lexicon/en/policy.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @package modx
* @subpackage lexicon
*/
$_lang['template_group'] = 'Template Group';
$_lang['active_of'] = '[[+active]] of [[+total]]';
$_lang['active_permissions'] = 'Active Permissions';
$_lang['no_policy_option'] = ' (no policy) ';
Expand All @@ -29,7 +30,7 @@
$_lang['policy_data'] = 'Policy Data';
$_lang['policy_desc'] = 'Access policies are generic policies that restrict or enable certain actions with MODX.';
$_lang['policy_desc_name'] = 'The name of the Access Policy';
$_lang['policy_desc_description'] = 'Optional. A short description of the Access Policy';
$_lang['policy_desc_description'] = 'Optional. A short description of the Access Policy. Also you might use lexicon keys here.';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use all available lexicon keys or are they limited to the policy topic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on language topics defined in controllers, so I would say that yes, mostly related to access control, but need to check because the manager loads a lot of topics and all of them will be cached.

$_lang['policy_desc_template'] = 'The Policy Template used for this Policy. Policies get their Permission lists from their Template.';
$_lang['policy_desc_lexicon'] = 'Optional. The Lexicon Topic that this Policy uses to translate the Permissions it owns.';
$_lang['policy_duplicate'] = 'Duplicate Policy';
Expand All @@ -55,10 +56,11 @@
$_lang['policy_remove_multiple_confirm'] = 'Are you sure you want to delete these Access Policies? This is irreversible.';
$_lang['policy_update'] = 'Edit Policy';
$_lang['policy_template'] = 'Policy Template';
$_lang['policy_template.desc'] = 'A Policy Template defines which Permissions will show up in the Permissions grid when editing a specific Policy. You can add or delete specific Permissions from this template below. Note that deleting a Permission from a Template will delete it from any Policies that use this Template.';
$_lang['policy_template_desc'] = 'A Policy Template defines which Permissions will show up in the Permissions grid when editing a specific Policy. You can add or remove specific Permissions from this template below. Note that removing a Permission from a Template will remove it from any Policies that use this Template.';
$_lang['policy_template_create'] = 'Create Policy Template';
$_lang['policy_template_desc_name'] = 'The name of the Access Policy Template';
$_lang['policy_template_desc_description'] = 'Optional. A short description of the Access Policy Template';
$_lang['policy_template_desc_description'] = 'Optional. A short description of the Access Policy Template. Also you might use lexicon keys here.';
$_lang['policy_template_lexicon'] = 'Lexicon Topic';
$_lang['policy_template_desc_lexicon'] = 'Optional. The Lexicon Topic that this Policy Template uses to translate the Permissions it owns.';
$_lang['policy_template_desc_template_group'] = 'The Policy Template Group to use. This is used when selecting Policies from a dropdown menu; usually they are filtered by template group. Select an appropriate group for your Policy Template.';
$_lang['policy_template_duplicate'] = 'Duplicate Policy Template';
Expand All @@ -78,4 +80,29 @@
$_lang['policy_template_update'] = 'Edit Policy Template';
$_lang['policy_templates'] = 'Policy Templates';
$_lang['policy_templates.intro_msg'] = 'This is a list of Policy Templates which define lists of Permissions that are checked or unchecked in specific Policies.';
$_lang['template_group'] = 'Template Group';
$_lang['policy_template_administrator_desc'] = 'Context administration policy template with all permissions.';
$_lang['policy_template_resource_desc'] = 'Resource Policy Template with all attributes.';
$_lang['policy_template_object_desc'] = 'Object Policy Template with all attributes.';
$_lang['policy_template_element_desc'] = 'Element Policy Template with all attributes.';
$_lang['policy_template_mediasource_desc'] = 'Media Source Policy Template with all attributes.';
$_lang['policy_template_context_desc'] = 'Context Policy Template with all attributes.';
$_lang['policy_template_namespace_desc'] = 'Namespace Policy Template with all attributes.';
$_lang['policy_template_group_administrator_desc'] = 'All admin policy templates.';
$_lang['policy_template_group_object_desc'] = 'All Resource-based policy templates.';
$_lang['policy_template_group_resource_desc'] = 'All Object-based policy templates.';
$_lang['policy_template_group_element_desc'] = 'All Element-based policy templates.';
$_lang['policy_template_group_mediasource_desc'] = 'All Media Source-based policy templates.';
$_lang['policy_template_group_namespace_desc'] = 'All Namespace based policy templates.';
$_lang['policy_template_group_context_desc'] = 'All Context based policy templates.';
$_lang['policy_resource_desc'] = 'MODX Resource Policy with all attributes.';
$_lang['policy_administrator_desc'] = 'Context administration policy with all permissions.';
$_lang['policy_load_only_desc'] = 'A minimal policy with permission to load an object.';
$_lang['policy_load_list_and_view_desc'] = 'Provides load, list and view permissions only.';
$_lang['policy_object_desc'] = 'An Object policy with all permissions.';
$_lang['policy_element_desc'] = 'MODX Element policy with all attributes.';
$_lang['policy_content_editor_desc'] = 'Context administration policy with limited, content-editing related Permissions, but no publishing.';
$_lang['policy_media_source_admin_desc'] = 'Media Source administration policy.';
$_lang['policy_media_source_user_desc'] = 'Media Source user policy, with basic viewing and using - but no editing - of Media Sources.';
$_lang['policy_developer_desc'] = 'Context administration policy with most Permissions except Administrator and Security functions.';
$_lang['policy_context_desc'] = 'A standard Context policy that you can apply when creating Context ACLs for basic read/write and view_unpublished access within a Context.';
$_lang['policy_hidden_namespace_desc'] = 'Hidden Namespace policy, will not show Namespace in lists.';
3 changes: 3 additions & 0 deletions core/src/Revolution/Processors/Model/GetListProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
*/
abstract class GetListProcessor extends ModelProcessor
{
const CLASS_ALLOW_EDIT = 'pedit';
const CLASS_ALLOW_REMOVE = 'premove';

/** @var string $defaultSortField The default field to sort by */
public $defaultSortField = 'name';
/** @var string $defaultSortDirection The default direction to sort */
Expand Down
Loading