Skip to content
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

Fix for #101 (access to restricted resources) #102

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions core/components/versionx/controllers/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@
$v = $versionx->getVersionDetails('vxResource',$versionid,true);
if ($v !== false)
Copy link
Member

Choose a reason for hiding this comment

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

Ew, Mark-from-5-years-ago, y u no use braces 😧

$modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.record = '.$v.'; </script>');
else
return $modx->error->failure($modx->lexicon('versionx.error.noresults'));
Mark-H marked this conversation as resolved.
Show resolved Hide resolved
}
/* If an ID to compare to was passed, fetch that aswell. */
if ($compareid > 0) {
$v = $versionx->getVersionDetails('vxResource',$compareid,true);
if ($v !== false)
$modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.cmrecord = '.$v.'; </script>');
else
return $modx->error->failure($modx->lexicon('versionx.error.noresults'));
}

$scripts[] = $versionx->config['js_url'].'mgr/action.resource.js';
Expand Down
4 changes: 4 additions & 0 deletions core/components/versionx/model/versionx.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ public function getVersionDetails($class = 'vxResource',$id = 0, $json = false,
/* Class specific processing */
switch ($class) {
case 'vxResource':
$resource = $this->modx->getObject('modResource',$v->get('content_id'));
if(!$resource) {
Copy link
Member

Choose a reason for hiding this comment

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

This check should be removed; just because a resource no longer exists does not mean it should not be available in VersionX. Restoring resources that were deleted is kind of a big deal for a versioning plugin.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, you're right. I will check for a better solution later on.

return false;
}
$vArray = array_merge($vArray,$vArray['fields']);

if ($vArray['parent'] != 0) {
Expand Down
29 changes: 29 additions & 0 deletions core/components/versionx/processors/mgr/resources/get_versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
$current = intval($modx->getOption('current',$scriptProperties,0));

$c = $modx->newQuery('vxResource');
$c->leftJoin('modContextSetting','ContextSetting','ContextSetting.context_key = vxResource.context_key');
$c->leftJoin('modResourceGroupResource','ResourceGroup','ResourceGroup.document = vxResource.content_id');
$c->select(array('version_id','saved','mode'));

if (strlen($search) > 1) {
Expand All @@ -22,6 +24,33 @@
if ($current > 0)
$c->where(array('version_id:!=' => $current));

/* 1. The connected context has is ignoring access through resource groups */
$where = [
[
[
'ContextSetting.key' => 'access_resource_group_enabled',
'ContextSetting.value' => 0
]
]
];

/* 2. The default context is ignoring access through resource groups disabled */
if(!$modx->getOption('access_resource_group_enabled', null, true)) {
array_push($where, [
'OR:vxResource.context_key:=' => $modx->getOption('default_context')
]);
array_push($where[0], [
'OR:ContextSetting.key' => 'access_resource_group_enabled',
'ContextSetting.value:IS' => null,
]);
}

/* 3. The resource is not restricted or the user has access to the resourcegroup */
array_push($where, [
'OR:ResourceGroup.id:IS' => null,
'OR:ResourceGroup.document_group:IN' => $modx->user->getResourceGroups(),
]);
$c->where($where);
$total = $modx->getCount('vxResource',$c);

$c->sortby($sort,$dir);
Expand Down
31 changes: 30 additions & 1 deletion core/components/versionx/processors/mgr/resources/getlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
$c = $modx->newQuery('vxResource');
$c->leftJoin('modUser','User');
$c->leftJoin('modUserProfile','Profile','Profile.internalKey = User.id');
$c->select(array('version_id','content_id','saved','mode','marked','title','context_key','class','User.username'));
$c->leftJoin('modContextSetting','ContextSetting','ContextSetting.context_key = vxResource.context_key');
$c->leftJoin('modResourceGroupResource','ResourceGroup','ResourceGroup.document = vxResource.content_id');
$c->select(array('vxResource.version_id','vxResource.content_id','vxResource.saved','vxResource.mode','vxResource.marked','vxResource.title','vxResource.context_key','vxResource.class','User.username'));

/* Filter */
if ($search)
Expand All @@ -39,6 +41,33 @@
if ($until)
$c->where(array('saved:<' => $until));

/* 1. The connected context has is ignoring access through resource groups */
$where = [
[
[
'ContextSetting.key' => 'access_resource_group_enabled',
'ContextSetting.value' => 0
]
]
];

/* 2. The default context is ignoring access through resource groups disabled */
if(!$modx->getOption('access_resource_group_enabled', null, true)) {
array_push($where, [
'OR:vxResource.context_key:=' => $modx->getOption('default_context')
]);
array_push($where[0], [
'OR:ContextSetting.key' => 'access_resource_group_enabled',
'ContextSetting.value:IS' => null,
]);
}

/* 3. The resource is not restricted or the user has access to the resourcegroup */
array_push($where, [
'OR:ResourceGroup.id:IS' => null,
'OR:ResourceGroup.document_group:IN' => $modx->user->getResourceGroups(),
]);
$c->where($where);

$total = $modx->getCount('vxResource',$c);

Expand Down