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

#798 Moderator permissions to delete/add files

Alex Trofimov пре 9 година
родитељ
комит
92a41e97e1

+ 8 - 5
inc/classes/BxDolStorage.php

@@ -709,17 +709,18 @@ abstract class BxDolStorage extends BxDolFactory implements iBxDolFactoryObject
      * @param $iProfileId profile id
      * @param $iContentId content id, or false to not consider content id at all
      * @param $isCheckAllAccountProfiles get all files associated with all account profiles
+     * @param $isAdmin if true, then don't check files ownership, it makes sense when $iContentId is provided, so it will return all files assiciated with content
      * @return array of arrays
      */
-    public function getGhosts($iProfileId, $iContentId = false, $isCheckAllAccountProfiles = false)
+    public function getGhosts($iProfileId, $iContentId = false, $isCheckAllAccountProfiles = false, $isAdmin = false)
     {
         if ($isCheckAllAccountProfiles && ($oProfile = BxDolProfile::getInstance($iProfileId))) {
             $oAccount = $oProfile->getAccountObject();
             $aProfiles = $oAccount->getProfilesIds(false);
-            return $this->_oDb->getGhosts($aProfiles, $iContentId);
+            return $this->_oDb->getGhosts($aProfiles, $iContentId, $isAdmin);
         }
         
-        return $this->_oDb->getGhosts($iProfileId, $iContentId);
+        return $this->_oDb->getGhosts($iProfileId, $iContentId, $isAdmin);
     }
 
     /**
@@ -727,16 +728,18 @@ abstract class BxDolStorage extends BxDolFactory implements iBxDolFactoryObject
      * @param $mixedFileIds array of file ids or just one file id
      * @param $iProfileId profile id
      * @param $iContentId content id
+     * @param $isAdmin if true, then don't check files ownership
      * @return true on success or false otherwise
      */
-    public function updateGhostsContentId($mixedFileIds, $iProfileId, $iContentId)
+    public function updateGhostsContentId($mixedFileIds, $iProfileId, $iContentId, $isAdmin = false)
     {
         $aProfiles = array();
         if ($oProfile = BxDolProfile::getInstance($iProfileId)) {
             $oAccount = $oProfile->getAccountObject();
             $aProfiles = $oAccount->getProfilesIds(false);
         }
-        return $this->_oDb->updateGhostsContentId($mixedFileIds, $iProfileId, $iContentId, $aProfiles);
+
+        return $this->_oDb->updateGhostsContentId($mixedFileIds, $iProfileId, $iContentId, $aProfiles, $isAdmin);
     }
 
     /**

+ 7 - 7
inc/classes/BxDolStorageQuery.php

@@ -241,7 +241,7 @@ class BxDolStorageQuery extends BxDolDb
         return $iCount;
     }
 
-    public function updateGhostsContentId($mixedFileIds, $iProfileId, $iContentId, $aProfiles = array())
+    public function updateGhostsContentId($mixedFileIds, $iProfileId, $iContentId, $aProfiles = array(), $isAdmin = false)
     {
         $aBindings = array(
             'content' => $iContentId,
@@ -251,9 +251,9 @@ class BxDolStorageQuery extends BxDolDb
 
         $sSetAddon = '';
         $sWhere = " AND `profile_id` = :profile ";
-        if ($aProfiles || isAdmin()) {
+        if ($aProfiles || $isAdmin) {
             $sSetAddon = ', `profile_id` = :profile ';
-            $sWhere = isAdmin() ? "" : " AND `profile_id` IN(" . $this->implode_escape($aProfiles) . ")";
+            $sWhere = $isAdmin ? "" : " AND `profile_id` IN(" . $this->implode_escape($aProfiles) . ")";
         }
         
         $sQuery = $this->prepare("UPDATE `sys_storage_ghosts` SET `content_id` = :content $sSetAddon WHERE `object` = :object $sWhere AND `id` IN (" . $this->implode_escape($mixedFileIds) . ")");
@@ -278,9 +278,9 @@ class BxDolStorageQuery extends BxDolDb
         return $iCount;
     }
 
-    public function getGhosts($mixedProfileId, $iContentId = false)
+    public function getGhosts($mixedProfileId, $iContentId = false, $isAdmin = false)
     {
-        return $this->getFiles($mixedProfileId, true, $iContentId);
+        return $this->getFiles($mixedProfileId, true, $iContentId, $isAdmin);
     }
 
     public function getGhost($iFileId)
@@ -289,7 +289,7 @@ class BxDolStorageQuery extends BxDolDb
         return $this->getRow($sQuery);
     }
 
-    public function getFiles($mixedProfileId, $isGhostsOnly = false, $iContentId = false)
+    public function getFiles($mixedProfileId, $isGhostsOnly = false, $iContentId = false, $isAdmin = false)
     {
         $aBindings = array();        
 
@@ -299,7 +299,7 @@ class BxDolStorageQuery extends BxDolDb
             $aBindings['object'] = $this->_aObject['object'];
 
             $sOnProfile = '';
-            if (isAdmin() && $iContentId) {
+            if ($isAdmin && $iContentId) {
                 // don't check profile id for admins, so admin can edit any entry
             }
             elseif (is_array($mixedProfileId) && $mixedProfileId) {

+ 7 - 2
inc/classes/BxDolUploader.php

@@ -317,7 +317,7 @@ abstract class BxDolUploader extends BxDolFactory
             $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sImagesTranscoder);
 
         $a = array();
-        $aGhosts = $oStorage->getGhosts(isAdmin() && $iContentId ? false : $iProfileId, $iContentId);
+        $aGhosts = $oStorage->getGhosts($this->isAdmin() && $iContentId ? false : $iProfileId, $iContentId);
         foreach ($aGhosts as $aFile) {
             $sFileIcon = '';
 
@@ -364,7 +364,7 @@ abstract class BxDolUploader extends BxDolFactory
         $oProfile = BxDolProfile::getInstance($iProfileId);
         $oAccount = $oProfile ? $oProfile->getAccountObject() : null;
         $aProfiles = $oAccount ? $oAccount->getProfiles(false) : array();
-        if (!isset($aProfiles[$aFile['profile_id']]) && !isAdmin())
+        if (!isset($aProfiles[$aFile['profile_id']]) && !$this->isAdmin())
             return _t('_sys_txt_access_denied');
 
         if (!$oStorage->deleteFile($iFileId))
@@ -432,6 +432,11 @@ abstract class BxDolUploader extends BxDolFactory
 
         return false;
     }
+
+    protected function isAdmin ()
+    {
+        return isAdmin();
+    }
 }
 
 /** @} */

+ 1 - 1
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -136,7 +136,7 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
 
         $iProfileId = $this->getContentOwnerProfileId($iContentId);
 
-        $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId, true);
+        $aGhostFiles = $oStorage->getGhosts ($iProfileId, $isAssociateWithContent ? 0 : $iContentId, true, $this->_oModule->_isModerator());
         if (!$aGhostFiles)
             return true;
 

+ 3 - 2
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -929,12 +929,13 @@ class BxBaseModGeneralModule extends BxDolModule
         );
     }
 
-    // ====== PROTECTED METHODS
-    protected function _isModerator ($isPerformAction = false)
+    public function _isModerator ($isPerformAction = false)
     {
         return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
     }
 
+    // ====== PROTECTED METHODS
+
     protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false)
     {
         $iContentId = $this->_getContent($iContentId, false);

+ 1 - 1
modules/base/profile/classes/BxBaseModProfileFormEntry.php

@@ -120,7 +120,7 @@ class BxBaseModProfileFormEntry extends BxBaseModGeneralFormEntry
 
     protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
     {
-        $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId);
+        $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId, $this->_oModule->_isModerator());
         $this->_oModule->_oDb->updateContentPictureById($iContentId, 0/*$iProfileId*/, $iFileId, $sPictureField);
     }
 

+ 6 - 1
modules/base/profile/classes/BxBaseModProfileUploaderCoverCrop.php

@@ -66,7 +66,12 @@ class BxBaseModProfileUploaderCoverCrop extends BxTemplUploaderCrop
         }
 
         return json_encode($aResult);
-    }    
+    }
+
+    protected function isAdmin ()
+    {
+        return $this->_oModule->_isModerator (false);
+    }
 }
 
 /** @} */

+ 7 - 1
modules/base/profile/classes/BxBaseModProfileUploaderPictureCrop.php

@@ -16,6 +16,7 @@ class BxBaseModProfileUploaderPictureCrop extends BxTemplUploaderCrop
     public function __construct ($aObject, $sStorageObject, $sUniqId, $oTemplate)
     {
         parent::__construct($aObject, $sStorageObject, $sUniqId, $oTemplate);
+        
     }
 
     public function deleteGhostsForProfile($iProfileId, $iContentId = false)
@@ -64,7 +65,12 @@ class BxBaseModProfileUploaderPictureCrop extends BxTemplUploaderCrop
         }
 
         return json_encode($aResult);
-    }    
+    }
+
+    protected function isAdmin ()
+    {
+        return $this->_oModule->_isModerator (false);
+    }
 }
 
 /** @} */

+ 1 - 1
modules/base/text/classes/BxBaseModTextFormEntry.php

@@ -121,7 +121,7 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
 
     protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
     {
-        $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId);
+        $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId, $this->_oModule->_isModerator());
     }
 
     protected function _getPhotoGhostTmplVars($aContentInfo = array())

+ 5 - 0
modules/boonex/albums/classes/BxAlbumsUploaderCrop.php

@@ -28,6 +28,11 @@ class BxAlbumsUploaderCrop extends BxTemplUploaderCrop
         $a['file_title_attr'] = bx_html_attribute($a['file_title']);
         return $a;
     }
+
+    protected function isAdmin ()
+    {
+        return $this->_oModule->_isModerator (false);
+    }
 }
 
 /** @} */

+ 5 - 0
modules/boonex/albums/classes/BxAlbumsUploaderHTML5.php

@@ -28,6 +28,11 @@ class BxAlbumsUploaderHTML5 extends BxTemplUploaderHTML5
         $a['file_title_attr'] = bx_html_attribute($a['file_title']);
         return $a;
     }
+
+    protected function isAdmin ()
+    {
+        return $this->_oModule->_isModerator (false);
+    }
 }
 
 /** @} */

+ 5 - 0
modules/boonex/albums/classes/BxAlbumsUploaderSimple.php

@@ -28,6 +28,11 @@ class BxAlbumsUploaderSimple extends BxTemplUploaderSimple
         $a['file_title_attr'] = bx_html_attribute($a['file_title']);
         return $a;
     }
+
+    protected function isAdmin ()
+    {
+        return $this->_oModule->_isModerator (false);
+    }
 }
 
 /** @} */

+ 1 - 1
modules/boonex/convos/classes/BxCnvModule.php

@@ -317,7 +317,7 @@ class BxCnvModule extends BxBaseModTextModule
     /**
      * No moderators for personal convos
      */
-    protected function _isModerator ($isPerformAction = false)
+    public function _isModerator ($isPerformAction = false)
     {
         return false;
     }