* Adjust whitelist deletion logic.

This commit is contained in:
leiyong
2020-10-27 16:08:46 +08:00
parent 0f3348ad2a
commit abf386a1e3
5 changed files with 79 additions and 12 deletions
+2 -2
View File
@@ -544,7 +544,7 @@ class commonModel extends model
echo '<li><hr></li>';
echo '<li><span id="mainRecent"><i class="icon icon-menu-doc"></i> ' . $lang->recent . '</span></li>';
$extraWhere = empty($app->user->admin) ? ' and id in (' . $app->user->view->sprints . ') and project in (' . $app->user->view->projects . ') ' : '';
$extraWhere = empty($app->user->admin) ? ' and id in (' . $app->user->view->sprints . ') and project in (' . $app->user->view->projects . ') ' : '';
if(empty($app->user->admin) && (empty($app->user->view->sprints) || empty($app->user->view->projects)))
{
@@ -552,7 +552,7 @@ class commonModel extends model
return false;
}
$recentProjects = $dbh->query('select * from ' . TABLE_PROJECT . " where type in ('stage','sprint') $extraWhere and status != 'close' and deleted = '0' order by 'id' desc limit 6")->fetchAll();
$recentProjects = $dbh->query('select * from ' . TABLE_PROJECT . " where type in ('stage','sprint') $extraWhere and status != 'close' and deleted = '0' order by id desc limit 6")->fetchAll();
if(!empty($recentProjects))
{
+5 -1
View File
@@ -184,13 +184,17 @@ class personnel extends control
else
{
$acl = $this->dao->select('*')->from(TABLE_ACL)->where('id')->eq($id)->fetch();
if(empty($acl)) die(js::reload('parent'));
$objectTable = $acl->objectType == 'product' ? TABLE_PRODUCT : TABLE_PROJECT;
$whitelist = $this->dao->select('whitelist')->from($objectTable)->where('id')->eq($acl->objectID)->fetch('whitelist');
$newWhitelist = str_replace(',' . $acl->account, '', $whitelist);
$this->dao->update($objectTable)->set('whitelist')->eq($newWhitelist)->where('id')->eq($acl->objectID)->exec();
$this->dao->delete()->from(TABLE_ACL)->where('id')->eq($id)->exec();
if($acl->objectType == 'product') $this->personnel->deleteProgramWhitelist($acl->objectID, $acl->account);
if($acl->objectType == 'sprint') $this->personnel->deleteProjectWhitelist($acl->objectID, $acl->account);
die(js::reload('parent'));
}
}
+71 -2
View File
@@ -243,15 +243,22 @@ class personnelModel extends model
*/
public function updateWhitelist($users = array(), $objectType = '', $objectID = 0, $type = 'whitelist', $source = 'add', $desc = '')
{
$oldWhitelist = $this->dao->select('account,objectType,objectID,type,source,`desc`')->from(TABLE_ACL)->where('objectID')->eq($objectID)->andWhere('objectType')->eq($objectType)->fetchAll('account');
$this->dao->delete()->from(TABLE_ACL)->where('objectID')->eq($objectID)->andWhere('objectType')->eq($objectType)->exec();
$users = array_filter($users);
$users = array_unique($users);
if(empty($users)) return false;
$accounts = '';
$accounts = array();
foreach($users as $account)
{
if(isset($oldWhitelist[$account]))
{
$this->dao->insert(TABLE_ACL)->data($oldWhitelist[$account])->exec();
$accounts[$account] = $account;
continue;
}
$acl = new stdClass();
$acl->account = $account;
$acl->objectType = $objectType;
@@ -267,6 +274,12 @@ class personnelModel extends model
$whitelist = ',' . implode(',', $accounts);
$this->dao->update($objectTable)->set('whitelist')->eq($whitelist)->where('id')->eq($objectID)->exec();
$deletedAccouns = array();
foreach($oldWhitelist as $account => $whitelist)
{
if(!isset($accounts[$account])) $deletedAccouns[] = $account;
}
/* Synchronization of people from the product whitelist to the program set. */
if($objectType == 'product')
{
@@ -274,6 +287,9 @@ class personnelModel extends model
$programWhitelist = $this->getWhitelistAccount($product->program, 'program');
$newWhitelist = array_merge($programWhitelist, $accounts);
$this->updateWhitelist($newWhitelist, 'program', $product->program, 'whitelist', 'sync', 'From product synchronization to program set.');
/* Removal of persons from centralized program whitelisting. */
foreach($deletedAccouns as $account) $this->deleteProgramWhitelist($objectID, $account);
}
/* Synchronization of people from the sprint white list to the project. */
@@ -283,6 +299,9 @@ class personnelModel extends model
$projectWhitelist = $this->getWhitelistAccount($project, 'project');
$newWhitelist = array_merge($projectWhitelist, $accounts);
$this->updateWhitelist($newWhitelist, 'project', $project, 'whitelist', 'sync', 'From sprint synchronization to project.');
/* Removal of whitelisted persons from projects. */
foreach($deletedAccouns as $account) $this->deleteProjectWhitelist($objectID, $account);
}
}
@@ -300,6 +319,56 @@ class personnelModel extends model
$this->updateWhitelist($users, $objectType, $objectID);
}
/**
* Determine whether the user exists in the white list of multiple products.
*
* @param int $objectID
* @param string $account
* @access public
* @return void
*/
public function deleteProgramWhitelist($objectID = 0, $account = '')
{
$program = $this->dao->select('id,program,whitelist')->from(TABLE_PRODUCT)->where('id')->eq($objectID)->fetch();
if(empty($program)) return false;
$programID = $program->program;
$products = $this->dao->select('id')->from(TABLE_PRODUCT)->where('program')->eq($programID)->andWhere('deleted')->eq('0')->fetchPairs('id');
$whitelist = $this->dao->select('*')->from(TABLE_ACL)->where('objectID')->in($products)->andWhere('account')->eq($account)->andWhere('objectType')->eq('product')->fetch();
/* Determine if the user exists in other products in the program set. */
if(empty($whitelist))
{
$newWhitelist = str_replace(',' . $account, '', $program->whitelist);
$this->dao->update(TABLE_PROGRAM)->set('whitelist')->eq($newWhitelist)->where('id')->eq($programID)->exec();
$this->dao->delete()->from(TABLE_ACL)->where('objectID')->eq($programID)->andWhere('account')->eq($account)->andWhere('objectType')->eq('program')->exec();
}
}
/**
* Determine if the user is on a whitelist for multiple sprints
*
* @param int $objectID
* @param string $account
* @access public
* @return void
*/
public function deleteProjectWhitelist($objectID = 0, $account = '')
{
$project = $this->dao->select('id,project,whitelist')->from(TABLE_PROJECT)->where('id')->eq($objectID)->fetch();
if(empty($project)) return false;
$projectID = $project->project;
$sprints = $this->dao->select('id')->from(TABLE_PROJECT)->where('project')->eq($projectID)->andWhere('deleted')->eq('0')->fetchPairs('id');
$whitelist = $this->dao->select('*')->from(TABLE_ACL)->where('objectID')->in($sprints)->andWhere('account')->eq($account)->andWhere('objectType')->eq('sprint')->fetch();
/* Determine if the user exists in other sprints in the project set. */
if(empty($whitelist))
{
$newWhitelist = str_replace(',' . $account, '', $project->whitelist);
$this->dao->update(TABLE_PROJECT)->set('whitelist')->eq($newWhitelist)->where('id')->eq($projectID)->exec();
$this->dao->delete()->from(TABLE_ACL)->where('objectID')->eq($projectID)->andWhere('account')->eq($account)->andWhere('objectType')->eq('project')->exec();
}
}
/**
* Create access links by department.
*
-3
View File
@@ -40,7 +40,6 @@ $config->program->sortFields->end = 'end';
$config->program->sortFields->PRJStatus = 'status';
$config->program->sortFields->PRJBudget = 'budget';
global $lang;
$config->program->datatable = new stdclass();
$config->program->datatable->defaultField = array('idAB', 'PRJCode', 'PRJName', 'PRJModel', 'PRJPM', 'begin', 'end', 'PRJStatus', 'PRJBudget', 'teamCount','PRJEstimate','PRJConsume', 'PRJProgress', 'actions');
@@ -110,7 +109,6 @@ $config->program->datatable->fieldList['PRJConsume']['width'] = '60';
$config->program->datatable->fieldList['PRJConsume']['required'] = 'no';
$config->program->datatable->fieldList['PRJConsume']['sort'] = 'no';
$config->program->datatable->fieldList['PRJProgress']['title'] = 'PRJProgress';
$config->program->datatable->fieldList['PRJProgress']['fixed'] = 'right';
$config->program->datatable->fieldList['PRJProgress']['width'] = '80';
@@ -123,7 +121,6 @@ $config->program->datatable->fieldList['PRJSurplus']['width'] = '80';
$config->program->datatable->fieldList['PRJSurplus']['required'] = 'no';
$config->program->datatable->fieldList['PRJSurplus']['sort'] = 'no';
$config->program->datatable->fieldList['actions']['title'] = 'actions';
$config->program->datatable->fieldList['actions']['fixed'] = 'right';
$config->program->datatable->fieldList['actions']['width'] = '240';
+1 -4
View File
@@ -4068,10 +4068,7 @@ class upgradeModel extends model
foreach($users as $account) $whiteList[$account] = $account;
/* Insert whiteList into program and projec. */
if($whiteList)
{
}
if($whiteList) $this->loadModel('personnel')->updateWhitelist($whiteList, 'project', $projectiD, 'whitelist', 'upgrade', 'Upgrade synced accounts.');
}
/**