mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
Merge remote-tracking branch 'origin/3'
# Conflicts: # code/Report.php # composer.json # tests/ReportTest.php
This commit is contained in:
commit
f777f36c68
22
.travis.yml
22
.travis.yml
@ -1,24 +1,30 @@
|
||||
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details
|
||||
|
||||
language: php
|
||||
php:
|
||||
- 5.3
|
||||
|
||||
sudo: false
|
||||
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
|
||||
env:
|
||||
- DB=MYSQL CORE_RELEASE=master
|
||||
- DB=PGSQL CORE_RELEASE=master
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.4
|
||||
env: DB=MYSQL CORE_RELEASE=master
|
||||
- php: 5.6
|
||||
env: DB=PGSQL CORE_RELEASE=master
|
||||
allow_failures:
|
||||
- php: 7.0
|
||||
|
||||
before_script:
|
||||
- composer self-update || true
|
||||
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
|
||||
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
|
||||
- cd ~/builds/ss
|
||||
- composer install
|
||||
|
||||
script:
|
||||
- phpunit reports/tests/
|
||||
- vendor/bin/phpunit reports/tests
|
||||
|
@ -67,7 +67,13 @@ class SS_Report extends ViewableData
|
||||
public static $excluded_reports = array(
|
||||
'SS_Report',
|
||||
'SS_ReportWrapper',
|
||||
'SideReportWrapper'
|
||||
'SideReportWrapper',
|
||||
'SideReport_RecentlyEdited', // @deprecated 3.2..4.0
|
||||
'SideReport_EmptyPages', // @deprecated 3.2..4.0
|
||||
'SideReport_BrokenVirtualPages', // @deprecated 3.2..4.0
|
||||
'SideReport_BrokenRedirectorPages', // @deprecated 3.2..4.0
|
||||
'SideReport_BrokenLinks', // @deprecated 3.2..4.0
|
||||
'SideReport_BrokenFiles' // @deprecated 3.2..4.0
|
||||
);
|
||||
|
||||
/**
|
||||
@ -110,7 +116,7 @@ class SS_Report extends ViewableData
|
||||
public function sourceQuery($params)
|
||||
{
|
||||
if($this->hasMethod('sourceRecords')) {
|
||||
return $this->sourceRecords()->dataQuery();
|
||||
return $this->sourceRecords($params, null, null)->dataQuery();
|
||||
} else {
|
||||
user_error("Please override sourceQuery()/sourceRecords() and columns() or, if necessary, override getReportField()", E_USER_ERROR);
|
||||
}
|
||||
@ -358,9 +364,39 @@ class SS_Report extends ViewableData
|
||||
$member = Member::currentUser();
|
||||
}
|
||||
|
||||
$extended = $this->extendedCan('canView', $member);
|
||||
if($extended !== null) {
|
||||
return $extended;
|
||||
}
|
||||
|
||||
if($member && Permission::checkMember($member, array('CMS_ACCESS_LeftAndMain', 'CMS_ACCESS_ReportAdmin'))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to assist with permission extension
|
||||
*
|
||||
* {@see DataObject::extendedCan()}
|
||||
*
|
||||
* @param string $methodName Method on the same object, e.g. {@link canEdit()}
|
||||
* @param Member|int $member
|
||||
* @return boolean|null
|
||||
*/
|
||||
public function extendedCan($methodName, $member) {
|
||||
$results = $this->extend($methodName, $member);
|
||||
if($results && is_array($results)) {
|
||||
// Remove NULLs
|
||||
$results = array_filter($results, function($v) {return !is_null($v);});
|
||||
// If there are any non-NULL responses, then return the lowest one of them.
|
||||
// If any explicitly deny the permission, then we don't get access
|
||||
if($results) return min($results);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of this report, which
|
||||
|
@ -1,23 +1,30 @@
|
||||
{
|
||||
"name": "silverstripe/reports",
|
||||
"type": "silverstripe-module",
|
||||
"description": "Reports module for SilverStripe CMS",
|
||||
"homepage": "http://silverstripe.org",
|
||||
"license": "BSD-3-Clause",
|
||||
"keywords": ["silverstripe", "cms", "reports"],
|
||||
"authors": [{
|
||||
"authors": [
|
||||
{
|
||||
"name": "SilverStripe",
|
||||
"homepage": "http://silverstripe.com"
|
||||
}, {
|
||||
},
|
||||
{
|
||||
"name": "The SilverStripe Community",
|
||||
"homepage": "http://silverstripe.org"
|
||||
}],
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.3",
|
||||
"silverstripe/framework": ">=3.1.x-dev"
|
||||
"silverstripe/framework": "~3.3"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.0.x-dev"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/PHPUnit": "~3.7"
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,26 @@ class ReportTest extends SapphireTest
|
||||
$reportNames,
|
||||
'ReportTest_FakeTest_Abstract is NOT in reports list as it is abstract');
|
||||
}
|
||||
|
||||
public function testPermissions() {
|
||||
$report = new ReportTest_FakeTest2();
|
||||
|
||||
// Visitor cannot view
|
||||
Session::clear("loggedInAs");
|
||||
$this->assertFalse($report->canView());
|
||||
|
||||
// Logged in user that cannot view reports
|
||||
$this->logInWithPermission('SITETREE_REORGANISE');
|
||||
$this->assertFalse($report->canView());
|
||||
|
||||
// Logged in with report permissions
|
||||
$this->logInWithPermission('CMS_ACCESS_ReportAdmin');
|
||||
$this->assertTrue($report->canView());
|
||||
|
||||
// Admin can view
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$this->assertTrue($report->canView());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user