From 2d8656e72b64d9b7ef63234c488421136d2e516b Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 22 Sep 2008 16:07:28 +0000 Subject: [PATCH] API CHANGE Deprecated Member::isInGroup() - use Member::inGroup() instead ENHANCEMENT Allowing usage of ID, Code-String or Object as $group parameter in Member::inGroup() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@62847 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/SiteTree.php | 4 ++-- security/Member.php | 43 ++++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index ce3213ac1..9692418c1 100644 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -588,7 +588,7 @@ class SiteTree extends DataObject { if(((!$this->Viewers) || ($this->Viewers == 'Anyone') || ($this->Viewers == 'LoggedInUsers' && $member) || ($this->Viewers == 'OnlyTheseUsers' && $member && - $member->isInGroup($this->ViewersGroup))) == false) + $member->inGroup($this->ViewersGroup))) == false) return false; return true; } @@ -696,7 +696,7 @@ class SiteTree extends DataObject { if((Permission::check('CMS_ACCESS_CMSMain') && (($this->Editors == 'LoggedInUsers' && $member) || ($this->Editors == 'OnlyTheseUsers' && $member && - $member->isInGroup($this->EditorsGroup)))) == false) + $member->inGroup($this->EditorsGroup)))) == false) return false; return true; diff --git a/security/Member.php b/security/Member.php index 1105e5008..cf26dd5ed 100644 --- a/security/Member.php +++ b/security/Member.php @@ -601,33 +601,29 @@ class Member extends DataObject { /** * Check if the member is in the given group * - * @param int $groupID ID of the group to check - * @return bool Returns TRUE if the member is in the given group, - * otherwise FALSE. + * @param int|Group|string $group Group instance, Group Code or ID + * @return bool Returns TRUE if the member is in the given group, otherwise FALSE. */ - - public function inGroup($groupID) { - foreach($this->Groups() as $group) { - if($groupID == $group->ID) + public function inGroup($group) { + if(is_numeric($group)) { + $groupCheckObj = DataObject::get_by_id('Group', $group); + } elseif(is_string($group)) { + $SQL_group = Convert::raw2sql($group); + $groupCheckObj = DataObject::get_one('Group', "Code = '{$SQL_group}'"); + } elseif(is_a('Group', $group)) { + $groupCheckObj = $group; + } else { + user_error('Member::inGroup(): Wrong format for $group parameter', E_USER_ERROR); + } + + foreach($this->Groups() as $groupCandidateObj) { + if($groupCandidateObj->ID == $groupCheckObj->ID) return true; } return false; } - /** - * Alias for {@link inGroup} - * - * @param int $groupID ID of the group to check - * @return bool Returns TRUE if the member is in the given group, - * otherwise FALSE. - * @see inGroup() - */ - public function isInGroup($groupID) { - return $this->inGroup($groupID); - } - - /** * Returns true if this user is an administrator. * Administrators have access to everything. The lucky bastards! ;-) @@ -1024,6 +1020,13 @@ class Member extends DataObject { } } } + + /** + * @deprecated 2.3 Use inGroup() + */ + public function isInGroup($groupID) { + user_error('Member::isInGroup() is deprecated. Please use inGroup() instead.', E_USER_NOTICE); + } }