From 358c294092918d17df1b59078783ee0d0d48afff Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 3 Nov 2015 11:35:31 +1300 Subject: [PATCH 1/7] FIX Tests for 3.2 --- .travis.yml | 13 ++++++++----- composer.json | 22 ++++++++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0a558db1..7b72a18f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,18 +2,21 @@ language: php php: - - 5.3 + - 5.6 sudo: false env: - - DB=MYSQL CORE_RELEASE=master - - DB=PGSQL CORE_RELEASE=master + - DB=MYSQL CORE_RELEASE=3.2 matrix: include: - php: 5.4 - env: DB=MYSQL CORE_RELEASE=master + env: DB=PGSQL CORE_RELEASE=3.2 + - php: 5.3 + env: DB=MYSQL CORE_RELEASE=3.2 + - php: 5.5 + env: DB=MYSQL CORE_RELEASE=3 before_script: - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support @@ -21,4 +24,4 @@ before_script: - cd ~/builds/ss script: - - phpunit reports/tests/ + - vendor/bin/phpunit reports/tests/ diff --git a/composer.json b/composer.json index 1bc62e31..bc2941a6 100644 --- a/composer.json +++ b/composer.json @@ -4,15 +4,21 @@ "homepage": "http://silverstripe.org", "license": "BSD-3-Clause", "keywords": ["silverstripe", "cms", "reports"], - "authors": [{ - "name": "SilverStripe", - "homepage": "http://silverstripe.com" - }, { - "name": "The SilverStripe Community", - "homepage": "http://silverstripe.org" - }], + "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.2" + }, + "require-dev": { + "phpunit/PHPUnit": "~3.7" } } From 82eb191bf441723d36d797de0dd56f8e4de7a3f5 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 10 Nov 2015 15:20:44 +1300 Subject: [PATCH 2/7] Restore deprecated reports --- code/Report.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/code/Report.php b/code/Report.php index fa7fe026..47796c43 100644 --- a/code/Report.php +++ b/code/Report.php @@ -66,9 +66,15 @@ 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 ); - + /** * Return the title of this report. * @@ -105,7 +111,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); } From 9f780b3eeb297012738555bf56febef221f5926e Mon Sep 17 00:00:00 2001 From: helpfulrobot Date: Wed, 16 Dec 2015 11:06:57 +1300 Subject: [PATCH 3/7] fixing travis config --- .travis.yml | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7b72a18f..e3c2f8c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,27 +1,34 @@ # See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details -language: php -php: - - 5.6 - sudo: false +language: php + +php: + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - 7.0 + env: - - DB=MYSQL CORE_RELEASE=3.2 + - DB=MYSQL CORE_RELEASE=3.2 matrix: include: - - php: 5.4 - env: DB=PGSQL CORE_RELEASE=3.2 - - php: 5.3 - env: DB=MYSQL CORE_RELEASE=3.2 - - php: 5.5 + - php: 5.6 env: DB=MYSQL CORE_RELEASE=3 + - php: 5.6 + env: DB=PGSQL CORE_RELEASE=3.2 + allow_failures: + - php: 7.0 before_script: - - 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 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: - - vendor/bin/phpunit reports/tests/ +script: + - vendor/bin/phpunit reports/tests From 648b6bac404fa144b145cf9ee757d84ab144bbc8 Mon Sep 17 00:00:00 2001 From: helpfulrobot Date: Wed, 16 Dec 2015 11:06:57 +1300 Subject: [PATCH 4/7] Added standard Travis config --- .travis.yml | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0a558db1..4798e607 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,32 @@ # See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details -language: php -php: - - 5.3 - sudo: false +language: php + +php: + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - 7.0 + env: - - DB=MYSQL CORE_RELEASE=master - - DB=PGSQL CORE_RELEASE=master + - DB=MYSQL CORE_RELEASE=3 matrix: include: - - php: 5.4 - env: DB=MYSQL CORE_RELEASE=master + - php: 5.6 + env: DB=PGSQL CORE_RELEASE=3 + allow_failures: + - php: 7.0 before_script: - - 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 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/ +script: + - vendor/bin/phpunit reports/tests From 5d0f833a397a2ce937e25b6a7c0350fdabdac63c Mon Sep 17 00:00:00 2001 From: Christopher Darling Date: Tue, 15 Dec 2015 16:32:23 +0000 Subject: [PATCH 5/7] FIX: SS_Report canView should check permissions ... checks for ADMIN / CMS_ACCESS_ReportAdmin (from ReportAdmin) fixes #13 --- code/Report.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/code/Report.php b/code/Report.php index fa7fe026..2248fb2a 100644 --- a/code/Report.php +++ b/code/Report.php @@ -308,8 +308,15 @@ class SS_Report extends ViewableData { if(!$member && $member !== FALSE) { $member = Member::currentUser(); } - - return true; + + $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; } From 36241d52a08ebce841f50fff91f3e4f4ac591be4 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Fri, 18 Dec 2015 11:41:34 +1300 Subject: [PATCH 6/7] BUG Fix regressions is SS_Report::canView --- code/Report.php | 25 ++++++++++++++++++++++++- tests/ReportTest.php | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/code/Report.php b/code/Report.php index 2248fb2a..071e1cc6 100644 --- a/code/Report.php +++ b/code/Report.php @@ -310,7 +310,9 @@ class SS_Report extends ViewableData { } $extended = $this->extendedCan('canView', $member); - if($extended !== null) return $extended; + if($extended !== null) { + return $extended; + } if($member && Permission::checkMember($member, array('CMS_ACCESS_LeftAndMain', 'CMS_ACCESS_ReportAdmin'))) { return true; @@ -318,6 +320,27 @@ class SS_Report extends ViewableData { 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; + } /** diff --git a/tests/ReportTest.php b/tests/ReportTest.php index dada8a4d..2df30585 100644 --- a/tests/ReportTest.php +++ b/tests/ReportTest.php @@ -56,6 +56,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()); + } } /** From 59cff00bb70b9dfb01b3f7a3aba3bd1042c4fce7 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 23 Dec 2015 14:24:14 +1300 Subject: [PATCH 7/7] Alias 3 branch as 3.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0e16eb71..519c8a1c 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "extra": { "branch-alias": { - "3.x-dev": "3.3.x-dev" + "3.x-dev": "3.4.x-dev" } }, "require-dev": {