Moved out common functionality to a static method

This commit is contained in:
Stig Lindqvist 2014-03-07 14:48:51 +13:00
parent c904ec1a15
commit 9317dbaa8c
3 changed files with 33 additions and 53 deletions

View File

@ -101,26 +101,7 @@ class ContentReviewDefaultSettings extends DataExtension {
* @return \ArrayList
*/
public function ContentReviewOwners() {
$contentReviewOwners = new ArrayList();
$toplevelGroups = $this->OwnerGroups();
if($toplevelGroups->count()) {
$groupIDs = array();
foreach($toplevelGroups as $group) {
$familyIDs = $group->collateFamilyIDs();
if(is_array($familyIDs)) {
$groupIDs = array_merge($groupIDs, array_values($familyIDs));
}
}
array_unique($groupIDs);
if(count($groupIDs)) {
$groupMembers = DataObject::get('Member')->where("\"Group\".\"ID\" IN (" . implode(",",$groupIDs) . ")")
->leftJoin("Group_Members", "\"Member\".\"ID\" = \"Group_Members\".\"MemberID\"")
->leftJoin("Group", "\"Group_Members\".\"GroupID\" = \"Group\".\"ID\"");
$contentReviewOwners->merge($groupMembers);
}
}
$contentReviewOwners->merge($this->OwnerUsers());
$contentReviewOwners->removeDuplicates();
return $contentReviewOwners;
return new ArrayList();
return SiteTreeContentReview::merge_owners($this->OwnerGroups(), $this->OwnerUsers());
}
}

View File

@ -69,6 +69,36 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
return self::$schedule;
}
/**
* Takes a list of groups and members and return a list of unique member
*
* @param SS_List $groups
* @param SS_List $members
* @return ArrayList
*/
public static function merge_owners(SS_List $groups, SS_List $members) {
$contentReviewOwners = new ArrayList();
if($groups->count()) {
$groupIDs = array();
foreach($groups as $group) {
$familyIDs = $group->collateFamilyIDs();
if(is_array($familyIDs)) {
$groupIDs = array_merge($groupIDs, array_values($familyIDs));
}
}
array_unique($groupIDs);
if(count($groupIDs)) {
$groupMembers = DataObject::get('Member')->where("\"Group\".\"ID\" IN (" . implode(",",$groupIDs) . ")")
->leftJoin("Group_Members", "\"Member\".\"ID\" = \"Group_Members\".\"MemberID\"")
->leftJoin("Group", "\"Group_Members\".\"GroupID\" = \"Group\".\"ID\"");
$contentReviewOwners->merge($groupMembers);
}
}
$contentReviewOwners->merge($members);
$contentReviewOwners->removeDuplicates();
return $contentReviewOwners;
}
/**
*
* @param \FieldList $actions
@ -189,27 +219,7 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
* @return \ArrayList
*/
public function ContentReviewOwners() {
$contentReviewOwners = new ArrayList();
$toplevelGroups = $this->OwnerGroups();
if($toplevelGroups->count()) {
$groupIDs = array();
foreach($toplevelGroups as $group) {
$familyIDs = $group->collateFamilyIDs();
if(is_array($familyIDs)) {
$groupIDs = array_merge($groupIDs, array_values($familyIDs));
}
}
array_unique($groupIDs);
if(count($groupIDs)) {
$groupMembers = DataObject::get('Member')->where("\"Group\".\"ID\" IN (" . implode(",",$groupIDs) . ")")
->leftJoin("Group_Members", "\"Member\".\"ID\" = \"Group_Members\".\"MemberID\"")
->leftJoin("Group", "\"Group_Members\".\"GroupID\" = \"Group\".\"ID\"");
$contentReviewOwners->merge($groupMembers);
}
}
$contentReviewOwners->merge($this->OwnerUsers());
$contentReviewOwners->removeDuplicates();
return $contentReviewOwners;
return SiteTreeContentReview::merge_owners($this->OwnerGroups(), $this->OwnerUsers());
}
/**

View File

@ -26,17 +26,6 @@ class ContentReviewCMSPageEditControllerTest extends FunctionalTest {
$controller->reviewed(array('ID'=>'FAIL', 'Message' => null), $dummyForm);
}
public function testReviewedThrowsExceptionWithWrongAccess() {
$visitor = $this->objFromFixture('Member', 'visitor');
$this->loginAs($visitor);
$page = $this->objFromFixture('Page', 'home');
$data = array(
'action_reviewed' => 1
);
$response = $this->post('admin/pages/edit/EditForm', $data);
$this->assertEquals(403, $response->getStatusCode());
}
public function testReviewedWithAuthor() {
$author = $this->objFromFixture('Member', 'author');
$this->loginAs($author);