Просмотр исходного кода

#53 - get rid of defines for acl actions

Alex Trofimov 12 лет назад
Родитель
Сommit
c39db18af2

+ 0 - 12
inc/classes/BxDolAcl.php

@@ -37,18 +37,6 @@ define('CHECK_ACTION_LANG_FILE_AFTER', 5);
 define('CHECK_ACTION_LANG_FILE_BEFORE', 6);
 define('CHECK_ACTION_LANG_FILE_SITE_EMAIL',	7);
 
-/**
- * Action ID's
- */
-define('ACTION_ID_VOTE', 3);
-define('ACTION_ID_COMMENTS_POST', 6);
-define('ACTION_ID_COMMENTS_EDIT_OWN', 8);
-define('ACTION_ID_COMMENTS_REMOVE_OWN', 9);
-define('ACTION_ID_COMMENTS_EDIT_ALL', 10);
-define('ACTION_ID_COMMENTS_REMOVE_ALL', 11);
-define('ACTION_ID_CREATE_ACCOUNT', 12);
-define('ACTION_ID_DELETE_ACCOUNT', 13);
-
 /**
  * Standard membership ID's
  */

+ 33 - 32
inc/classes/BxDolCmts.php

@@ -95,10 +95,10 @@ define('BX_CMT_RATE_VALUE_MINUS', -1);
  *
  *
  * @section acl Memberships/ACL:
- * - comments post - ACTION_ID_COMMENTS_POST
- * - comments vote - ACTION_ID_COMMENTS_VOTE
- * - comments edit own - ACTION_ID_COMMENTS_EDIT_OWN
- * - comments remove own - ACTION_ID_COMMENTS_REMOVE_OWN
+ * - comments post
+ * - comments edit own
+ * - comments remove own 
+ * - comments edit all
  *
  *
  *
@@ -309,7 +309,8 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
 	/**
      * it is called on cron every day or similar period to clean old comment votes
      */
-    public static function maintenance() {        
+    public static function maintenance() 
+    {
         $iResult = 0;
         $oDb = BxDolDb::getInstance();
 
@@ -458,7 +459,8 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
      * @param $a array of markers as key => value
      * @return true on success or false on error
      */
-    public function addMarkers ($a) {
+    public function addMarkers ($a) 
+    {
         if (empty($a) || !is_array($a))
             return false;
         $this->_aMarkers = array_merge ($this->_aMarkers, $a);
@@ -563,18 +565,18 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
     /** 
      * Permissions functions
      */
-    public function checkAction ($iAction, $isPerformAction = false)
+    public function checkAction ($sAction, $isPerformAction = false)
     {
         $iId = $this->_getAuthorId();
-        $check_res = checkAction($iId, $iAction, $isPerformAction);
-        return $check_res[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
+        $a = checkActionModule($iId, $sAction, 'system', $isPerformAction);
+        return $a[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
     }
 
-    public function checkActionErrorMsg ($iAction)
+    public function checkActionErrorMsg ($sAction)
     {
         $iId = $this->_getAuthorId();
-        $check_res = checkAction($iId, $iAction);
-        return $check_res[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $check_res[CHECK_ACTION_MESSAGE] : '';
+        $a = checkActionModule($iId, $sAction, 'system');
+        return $a[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $a[CHECK_ACTION_MESSAGE] : '';
     }
 
     public function isVoteAllowed ($aCmt, $isPerformAction = false)
@@ -596,19 +598,14 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
         return $oVote->isAllowedVote($isPerformAction); 
     }
 
-    public function msgErrVoteAllowed ()
-    { 
-        return $this->checkActionErrorMsg(ACTION_ID_VOTE);
-    }
-
     public function isPostReplyAllowed ($isPerformAction = false)
     {
-        return $this->checkAction (ACTION_ID_COMMENTS_POST, $isPerformAction);
+        return $this->checkAction ('comments post', $isPerformAction);
     }
 
     public function msgErrPostReplyAllowed ()
     {
-        return $this->checkActionErrorMsg(ACTION_ID_COMMENTS_POST);
+        return $this->checkActionErrorMsg('comments post');
     }
 
     public function isEditAllowed ($aCmt, $isPerformAction = false)
@@ -616,15 +613,15 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
     	if(isAdmin())
     		return true;
 
-		if($aCmt['cmt_author_id'] == $this->_getAuthorId() && $this->checkAction (ACTION_ID_COMMENTS_EDIT_OWN, $isPerformAction))
+		if($aCmt['cmt_author_id'] == $this->_getAuthorId() && $this->checkAction ('comments edit own', $isPerformAction))
 			return true;
 
-        return $this->checkAction(ACTION_ID_COMMENTS_EDIT_ALL, $isPerformAction);
+        return $this->checkAction('comments edit all', $isPerformAction);
     }
 
     public function msgErrEditAllowed ()
     {
-        return $this->checkActionErrorMsg (ACTION_ID_COMMENTS_EDIT_OWN);
+        return $this->checkActionErrorMsg ('comments edit own');
     }
 
     public function isRemoveAllowed ($aCmt, $isPerformAction = false)
@@ -632,23 +629,24 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
     	if(isAdmin())
     		return true;
 
-		if($aCmt['cmt_author_id'] == $this->_getAuthorId() && $this->checkAction (ACTION_ID_COMMENTS_REMOVE_OWN, $isPerformAction))
+		if($aCmt['cmt_author_id'] == $this->_getAuthorId() && $this->checkAction ('comments remove own', $isPerformAction))
 			return true;
 
-        return $this->checkAction (ACTION_ID_COMMENTS_REMOVE_ALL, $isPerformAction);
+        return $this->checkAction ('comments remove all', $isPerformAction);
     }
 
     public function msgErrRemoveAllowed ()
     {
-        return $this->checkActionErrorMsg(ACTION_ID_COMMENTS_REMOVE_OWN);
+        return $this->checkActionErrorMsg('comments remove own');
     }
 
     /**
      * Actions functions
      */
-    public function actionGetFormPost () {
+    public function actionGetFormPost () 
+    {
         if (!$this->isEnabled())
-           return '';
+            return '';
 
         $iCmtParentId= isset($_REQUEST['CmtParent']) ? bx_process_input($_REQUEST['CmtParent'], BX_DATA_INT) : 0;
         $sCmtBrowse = isset($_REQUEST['CmtBrowse']) ? bx_process_input($_REQUEST['CmtBrowse'], BX_DATA_TEXT) : '';
@@ -668,9 +666,10 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
         $this->_echoResultJson($this->getFormEdit($iCmtId));
     }
 
-    public function actionGetCmt () {
+    public function actionGetCmt () 
+    {
         if (!$this->isEnabled())
-           return '';
+            return '';
 
         $iCmtId = bx_process_input($_REQUEST['Cmt'], BX_DATA_INT);
         $sCmtBrowse = isset($_REQUEST['CmtBrowse']) ? bx_process_input($_REQUEST['CmtBrowse'], BX_DATA_TEXT) : '';
@@ -684,9 +683,10 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
         ));
     }
 
-    public function actionGetCmts () {
+    public function actionGetCmts () 
+    {
         if (!$this->isEnabled())
-           return '';
+            return '';
 
         $iCmtVParentId = bx_process_input($_REQUEST['CmtParent'], BX_DATA_INT);
         $iCmtStart = isset($_REQUEST['CmtStart']) ? bx_process_input($_REQUEST['CmtStart'], BX_DATA_INT) : -1;
@@ -927,7 +927,8 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
      * @param $mixed string or array to replace markers in
      * @return string where all occured markers are replaced
      */ 
-    protected function _replaceMarkers ($mixed) {
+    protected function _replaceMarkers ($mixed) 
+    {
         return bx_replace_markers($mixed, $this->_aMarkers);
     }
 

+ 9 - 9
inc/classes/BxDolVote.php

@@ -71,7 +71,7 @@ define('BX_DOL_VOTE_USAGE_DEFAULT', BX_DOL_VOTE_USAGE_BLOCK);
  *
  *
  * @section acl Memberships/ACL:
- * vote - ACTION_ID_VOTE
+ * - vote
  *
  *
  *
@@ -294,18 +294,18 @@ class BxDolVote extends BxDolObject
     /** 
      * Permissions functions
      */
-	public function checkAction ($iAction, $isPerformAction = false)
+	public function checkAction ($sAction, $isPerformAction = false)
     {
         $iId = $this->_getAuthorId();
-        $check_res = checkAction($iId, $iAction, $isPerformAction);
-        return $check_res[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
+        $a = checkActionModule($iId, $sAction, 'system', $isPerformAction);
+        return $a[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
     }
 
-    public function checkActionErrorMsg ($iAction)
+    public function checkActionErrorMsg ($sAction)
     {
         $iId = $this->_getAuthorId();
-        $check_res = checkAction($iId, $iAction);
-        return $check_res[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $check_res[CHECK_ACTION_MESSAGE] : '';
+        $a = checkActionModule($iId, $sAction, 'system');
+        return $a[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $a[CHECK_ACTION_MESSAGE] : '';
     }
 
 	public function isAllowedVote($isPerformAction = false)
@@ -313,12 +313,12 @@ class BxDolVote extends BxDolObject
     	if(isAdmin())
     		return true;
 
-        return $this->checkAction(ACTION_ID_VOTE, $isPerformAction); 
+        return $this->checkAction('vote', $isPerformAction); 
     }
 
     public function msgErrAllowedVote()
     { 
-        return $this->checkActionErrorMsg(ACTION_ID_VOTE);
+        return $this->checkActionErrorMsg('vote');
     }
 
     function onObjectDelete($iObjectId = 0)

+ 9 - 9
install/sql/system.sql

@@ -454,15 +454,15 @@ CREATE TABLE `sys_acl_actions` (
   FULLTEXT KEY `ModuleAndName` (`Module`, `Name`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
-INSERT INTO `sys_acl_actions` (`ID`, `Module`, `Name`, `AdditionalParamName`, `Title`, `Desc`, `Countable`, `DisabledForLevels`) VALUES
-(3, 'system', 'vote', NULL, '_sys_acl_action_vote', '', 0, 0),
-(6, 'system', 'comments post', NULL, '_sys_acl_action_comments_post', '', 0, 1),
-(8, 'system', 'comments edit own', NULL, '_sys_acl_action_comments_edit_own', '', 0, 1),
-(9, 'system', 'comments remove own', NULL, '_sys_acl_action_comments_remove_own', '', 0, 1),
-(10, 'system', 'comments edit all', NULL, '_sys_acl_action_comments_edit_all', '', 0, 1),
-(11, 'system', 'comments remove all', NULL, '_sys_acl_action_comments_remove_all', '', 0, 1),
-(12, 'system', 'create account', NULL, '_sys_acl_action_create_account', '_sys_acl_action_create_account_desc', 0, 2147483646),
-(13, 'system', 'delete account', NULL, '_sys_acl_action_delete_account', '_sys_acl_action_delete_account_desc', 0, 2147483646);
+INSERT INTO `sys_acl_actions` (`Module`, `Name`, `AdditionalParamName`, `Title`, `Desc`, `Countable`, `DisabledForLevels`) VALUES
+('system', 'vote', NULL, '_sys_acl_action_vote', '', 0, 0),
+('system', 'comments post', NULL, '_sys_acl_action_comments_post', '', 0, 1),
+('system', 'comments edit own', NULL, '_sys_acl_action_comments_edit_own', '', 0, 1),
+('system', 'comments remove own', NULL, '_sys_acl_action_comments_remove_own', '', 0, 1),
+('system', 'comments edit all', NULL, '_sys_acl_action_comments_edit_all', '', 0, 1),
+('system', 'comments remove all', NULL, '_sys_acl_action_comments_remove_all', '', 0, 1),
+('system', 'create account', NULL, '_sys_acl_action_create_account', '_sys_acl_action_create_account_desc', 0, 2147483646),
+('system', 'delete account', NULL, '_sys_acl_action_delete_account', '_sys_acl_action_delete_account_desc', 0, 2147483646);
 
 
 CREATE TABLE `sys_acl_actions_track` (

+ 2 - 0
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -655,6 +655,8 @@ class BxTimelineModule extends BxDolModule
     }
 
     //--- Check permissions methods ---//
+
+    // TODO: this function is incorrect ,$iAction is never defined, also it looks like it is not used anywhere: rewrite it or delete
     public function checkActionErrorMsg ($iAction)
     {
         $iId = $this->_getAuthorId();