Merge remote-tracking branch 'origin/3'

# Conflicts:
#	code/Report.php
#	composer.json
#	tests/ReportTest.php
This commit is contained in:
Damian Mooyman 2016-01-25 16:20:10 +13:00
commit f777f36c68
4 changed files with 464 additions and 395 deletions

View File

@ -1,24 +1,30 @@
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details # See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details
language: php
php:
- 5.3
sudo: false sudo: false
language: php
php:
- 5.5
- 5.6
- 7.0
env: env:
- DB=MYSQL CORE_RELEASE=master - DB=MYSQL CORE_RELEASE=master
- DB=PGSQL CORE_RELEASE=master
matrix: matrix:
include: include:
- php: 5.4 - php: 5.6
env: DB=MYSQL CORE_RELEASE=master env: DB=PGSQL CORE_RELEASE=master
allow_failures:
- php: 7.0
before_script: before_script:
- composer self-update || true
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss - cd ~/builds/ss
- composer install
script: script:
- phpunit reports/tests/ - vendor/bin/phpunit reports/tests

View File

@ -67,7 +67,13 @@ class SS_Report extends ViewableData
public static $excluded_reports = array( public static $excluded_reports = array(
'SS_Report', 'SS_Report',
'SS_ReportWrapper', '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) public function sourceQuery($params)
{ {
if($this->hasMethod('sourceRecords')) { if($this->hasMethod('sourceRecords')) {
return $this->sourceRecords()->dataQuery(); return $this->sourceRecords($params, null, null)->dataQuery();
} else { } else {
user_error("Please override sourceQuery()/sourceRecords() and columns() or, if necessary, override getReportField()", E_USER_ERROR); 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(); $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 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 * Return the name of this report, which

View File

@ -1,23 +1,30 @@
{ {
"name": "silverstripe/reports", "name": "silverstripe/reports",
"type": "silverstripe-module", "type": "silverstripe-module",
"description": "Reports module for SilverStripe CMS",
"homepage": "http://silverstripe.org", "homepage": "http://silverstripe.org",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"keywords": ["silverstripe", "cms", "reports"], "keywords": ["silverstripe", "cms", "reports"],
"authors": [{ "authors": [
{
"name": "SilverStripe", "name": "SilverStripe",
"homepage": "http://silverstripe.com" "homepage": "http://silverstripe.com"
}, { },
{
"name": "The SilverStripe Community", "name": "The SilverStripe Community",
"homepage": "http://silverstripe.org" "homepage": "http://silverstripe.org"
}], }
],
"require": { "require": {
"php": ">=5.3.3", "php": ">=5.3.3",
"silverstripe/framework": ">=3.1.x-dev" "silverstripe/framework": "~3.3"
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "4.0.x-dev" "dev-master": "4.0.x-dev"
} }
},
"require-dev": {
"phpunit/PHPUnit": "~3.7"
} }
} }

View File

@ -60,6 +60,26 @@ class ReportTest extends SapphireTest
$reportNames, $reportNames,
'ReportTest_FakeTest_Abstract is NOT in reports list as it is abstract'); '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());
}
} }
/** /**