Преглед изворни кода

#281 Groups: correct checking for group admin

Alex Trofimov пре 10 година
родитељ
комит
54b7029787

+ 4 - 1
modules/boonex/groups/classes/BxGroupsDb.php

@@ -64,8 +64,11 @@ class BxGroupsDb extends BxBaseModProfileDb
         return $this->res($sQuery);
     }
 
-    public function isAdmin ($iGroupProfileId, $iFanId)
+    public function isAdmin ($iGroupProfileId, $iFanId, $aDataEntry = array())
     {
+        if (isset($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']]) && $iFanId == $aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']])
+            return true;
+
         $sQuery = $this->prepare("SELECT `id` FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `group_profile_id` = ? AND `fan_id` = ?", $iGroupProfileId, $iFanId);
         return $this->getOne($sQuery) ? true : false;
     }

+ 3 - 2
modules/boonex/groups/classes/BxGroupsGridConnections.php

@@ -14,6 +14,7 @@ class BxGroupsGridConnections extends BxDolGridConnections
     protected $_iGroupProfileId;
     protected $_oModule;
     protected $_oConnection;
+    protected $_aContentInfo = array();
 
     public function __construct ($aOptions, $oTemplate = false)
     {
@@ -34,8 +35,8 @@ class BxGroupsGridConnections extends BxDolGridConnections
         $aProfileInfo = $oProfile->getInfo();
         $this->_iGroupProfileId = $oProfile->id();
 
-        $aContentInfo = BxDolService::call($aProfileInfo['type'], 'get_content_info_by_id', array($aProfileInfo['content_id']));
-        if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedEdit($aContentInfo) || $oProfile->id() == bx_get_logged_profile_id())
+        $this->_aContentInfo = BxDolService::call($aProfileInfo['type'], 'get_content_info_by_id', array($aProfileInfo['content_id']));
+        if (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedEdit($this->_aContentInfo) || $oProfile->id() == bx_get_logged_profile_id())
             $this->_bOwner = true;
 
         $aSQLParts = $this->_oConnection->getConnectedInitiatorsAsSQLParts('p', 'id', $this->_iGroupProfileId, $this->_bOwner ? false : true);

+ 10 - 4
modules/boonex/groups/classes/BxGroupsModule.php

@@ -240,7 +240,13 @@ class BxGroupsModule extends BxBaseModProfileModule
 
     public function checkAllowedManageAdmins ($mixedDataEntry, $isPerformAction = false)
     {
-        $aDataEntry = is_array($mixedDataEntry) ? $mixedDataEntry : $this->_oDb->getContentInfoById((int)$mixedDataEntry);
+        if (is_array($mixedDataEntry)) {
+            $aDataEntry = $mixedDataEntry;
+        }
+        else {
+            $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
+            $aDataEntry = $oGroupProfile && $this->getName() == $oGroupProfile->getModule() ? $this->_oDb->getContentInfoById($oGroupProfile->getContentId()) : array();
+        }
 
         return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
     }
@@ -248,7 +254,7 @@ class BxGroupsModule extends BxBaseModProfileModule
     public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
     {
         $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
-        if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id()))
+        if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id(), $aDataEntry))
             return CHECK_ACTION_RESULT_ALLOWED;
         return parent::checkAllowedEdit ($aDataEntry, $isPerformAction);
     }
@@ -256,7 +262,7 @@ class BxGroupsModule extends BxBaseModProfileModule
     public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
     {
         $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
-        if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id()))
+        if ($this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id(), $aDataEntry))
             return CHECK_ACTION_RESULT_ALLOWED;
         return parent::checkAllowedChangeCover ($aDataEntry, $isPerformAction);
     }
@@ -264,7 +270,7 @@ class BxGroupsModule extends BxBaseModProfileModule
     public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
     {
         $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
-        if ($oGroupProfile && $this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id()))
+        if ($oGroupProfile && $this->_oDb->isAdmin($oGroupProfile->id(), bx_get_logged_profile_id(), $aDataEntry))
             return CHECK_ACTION_RESULT_ALLOWED;
         return parent::checkAllowedDelete ($aDataEntry, $isPerformAction);
     }