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

Ticket #5425 - Tasks: Functionality improvements. Stage 2.

AntonLV 5 месяцев назад
Родитель
Сommit
f999cc02e2

+ 1 - 1
modules/boonex/tasks/classes/BxTasksDb.php

@@ -62,7 +62,7 @@ class BxTasksDb extends BxBaseModTextDb
             'id' => $iId
         ]);
 
-        return $aContext && is_array($aContext) ? [$aContext['gh_username'], $aContext['gh_repository']] : false;
+        return $aContext && is_array($aContext) ? $aContext : false;
     }
 
     public function getLists ($iContextId = 0)

+ 12 - 3
modules/boonex/tasks/classes/BxTasksFormContext.php

@@ -28,11 +28,20 @@ class BxTasksFormContext extends BxTemplFormView
             $sMethod = 'get_apps';
             if(bx_is_srv($sModule, $sMethod)) {
                 $aApps = bx_srv($sModule, $sMethod, [$iProfileId]);
-                foreach($aApps as $aApp)
+                if($aApps !== false) {
                     $this->aInputs[$sKey]['values'][] = [
-                        'key' => $aApp['id'],
-                        'value' => $aApp['title'],
+                        'key' => '',
+                        'value' => _t('_sys_please_select'),
                     ];
+
+                    foreach($aApps as $aApp)
+                        $this->aInputs[$sKey]['values'][] = [
+                            'key' => $aApp['id'],
+                            'value' => $aApp['title'],
+                        ];
+                }
+                else
+                    unset($this->aInputs[$sKey]);
             }
         }
     }

+ 32 - 10
modules/boonex/tasks/classes/BxTasksModule.php

@@ -1109,9 +1109,9 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
         if(($iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0) {
             $iContextId = abs($iContextId);
 
-            $mixedRepo = $this->_oDb->getContextRepository($iContextId);
+            $mixedRepo = $this->ghGetRepository($iContextId);
             if($mixedRepo !== false && ($sMl = 'bx_github') && ($sMd = 'create_issue') && bx_is_srv($sMl, $sMd)) {
-                list($sGhUsername, $sGhRepository) = $mixedRepo;
+                list($sGhUsername, $sGhRepository, $mixedAuth) = $mixedRepo;
 
                 $aFldLoc2Repo = [
                     $CNF['FIELD_STICKERS'] => 'labels', 
@@ -1139,7 +1139,7 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
                                 $aGhFields[$sRepoField] = $sLocValue;
                         }
 
-                $aIssue = bx_srv($sMl, $sMd, [$sGhUsername, $sGhRepository, $aContentInfo[$CNF['FIELD_TITLE']], $aContentInfo[$CNF['FIELD_TEXT']], $aGhFields]);
+                $aIssue = bx_srv($sMl, $sMd, [$sGhUsername, $sGhRepository, $mixedAuth, $aContentInfo[$CNF['FIELD_TITLE']], $aContentInfo[$CNF['FIELD_TEXT']], $aGhFields]);
                 if($aIssue && is_array($aIssue) && ($iNumber = (int)($aIssue['number'] ?? 0)) != 0 && ($sUrl = $aIssue['html_url'] ?? '') != '') {
                     $this->_oDb->updateEntriesBy([
                         $CNF['FIELD_GH_ISSUE'] => $iNumber,
@@ -1215,7 +1215,16 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
         
         return false;
     }
-    
+
+    public function isAllowEdit($mixedContent)
+    {
+        $aContentInfo = !is_array($mixedContent) ? $this->_oDb->getContentInfoById((int)$mixedContent) : $mixedContent;
+        if($this->checkAllowedEdit($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED)
+            return true;
+
+        return false;
+    }
+
     public function isAllowManage($mixedContent)
     {
         $CNF = &$this->_oConfig->CNF;
@@ -1299,13 +1308,13 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
 
         $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_' . ($iCompleted ? '' : 'un') . 'completed']);
 
-        if(($iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0 && ($mixedRepository = $this->_oDb->getContextRepository(abs($iContextId))) !== false) {
+        if(($iContextId = (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) < 0 && ($mixedRepo = $this->ghGetRepository(abs($iContextId))) !== false) {
             $sModule = 'bx_github';
             $sMethod = ($iCompleted ? 'close' : 'reopen') . '_issue';
             if(bx_is_srv($sModule, $sMethod) && ($iGhIssue = (int)$aContentInfo[$CNF['FIELD_GH_ISSUE']]) != 0) {
-                list($sGhUsername, $sGhRepository) = $mixedRepository;
+                list($sGhUsername, $sGhRepository, $mixedAuth) = $mixedRepo;
 
-                bx_srv($sModule, $sMethod, [$sGhUsername, $sGhRepository, $iGhIssue]);
+                bx_srv($sModule, $sMethod, [$sGhUsername, $sGhRepository, $mixedAuth, $iGhIssue]);
             }
         }
 
@@ -1329,6 +1338,19 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
         return $oCmts->addAuto($aMessage);
     }
 
+    public function ghGetRepository($iContextId)
+    {
+        $mixedRepo = $this->_oDb->getContextRepository($iContextId);
+        if($mixedRepo === false) 
+            return false;
+
+        return [
+            $mixedRepo['gh_username'], 
+            $mixedRepo['gh_repository'], 
+            $mixedRepo['gh_app_id'] ? [$this->_iProfileId, (int)$mixedRepo['gh_app_id']] : $this->_iProfileId
+        ];
+    }
+
     public function ghUpdateIssue($mixedContent, $aGhFields = [])
     {
         $aContentInfo = is_array($mixedContent) ? $mixedContent : $this->_oDb->getContentInfoById((int)$mixedContent);
@@ -1342,17 +1364,17 @@ class BxTasksModule extends BxBaseModTextModule implements iBxDolCalendarService
         if($iContextId >= 0) 
             return false;
 
-        $mixedRepo = $this->_oDb->getContextRepository(abs($iContextId));
+        $mixedRepo = $this->ghGetRepository(abs($iContextId));
         if($mixedRepo === false) 
             return false;
 
-        list($sGhUsername, $sGhRepository) = $mixedRepo;
+        list($sGhUsername, $sGhRepository, $mixedAuth) = $mixedRepo;
 
         $iGhIssue = (int)$aContentInfo[$CNF['FIELD_GH_ISSUE']];
 
         $sMl = 'bx_github';
         if($aGhFields && ($sMd = 'update_issue') && bx_is_srv($sMl, $sMd))
-            if(bx_srv($sMl, $sMd, [$sGhUsername, $sGhRepository, $iGhIssue, $aGhFields]) !== false) 
+            if(bx_srv($sMl, $sMd, [$sGhUsername, $sGhRepository, $mixedAuth, $iGhIssue, $aGhFields]) !== false) 
                 $this->logActivity($iContentId, ['key' => '_bx_tasks_txt_msg_synced', 'markers' => [
                     'ghi_link' => $aContentInfo[$CNF['FIELD_GH_ISSUE_URL']],
                     'ghi_number' => $iGhIssue

+ 1 - 1
modules/boonex/tasks/classes/BxTasksTemplate.php

@@ -98,7 +98,7 @@ class BxTasksTemplate extends BxBaseModTextTemplate
         $iContentId = (int)$aData[$CNF['FIELD_ID']];
 
         $sResult = '';
-        if(!$this->_oModule->isAllowManage($iContentId)) {
+        if(!$this->_oModule->isAllowEdit($iContentId)) {
             $aVars = $this->getTmplVarsText($aData);
 
             $sResult = $this->parseHtmlByName($sTemplateName, $aVars);

+ 3 - 3
modules/boonex/tasks/install/sql/install.sql

@@ -634,9 +634,9 @@ INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `c
 ('bx_tasks_context', 'bx_tasks', 'controls', '', 'do_submit,do_cancel', 0, 'input_set', '_bx_tasks_form_context_input_sys_controls', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0);
 
 INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_for_levels`, `active`, `order`) VALUES
-('bx_tasks_context_edit', 'gh_app_id', 2147483647, 1, 1),
-('bx_tasks_context_edit', 'gh_username', 2147483647, 1, 2),
-('bx_tasks_context_edit', 'gh_repository', 2147483647, 1, 3),
+('bx_tasks_context_edit', 'gh_username', 2147483647, 1, 1),
+('bx_tasks_context_edit', 'gh_repository', 2147483647, 1, 2),
+('bx_tasks_context_edit', 'gh_app_id', 2147483647, 1, 3),
 ('bx_tasks_context_edit', 'do_submit', 2147483647, 1, 4);
 
 -- FORMS: time