Merge branch 'sprint/180_mayue_46526' into 'sprint/180'

* Finish task #46526.

See merge request easycorp/zentaopms!1249
This commit is contained in:
李玉春
2022-01-04 07:32:59 +00:00
8 changed files with 108 additions and 13 deletions
+31
View File
@@ -778,6 +778,37 @@ class doc extends control
$this->doc->saveDraft($docID);
}
/**
* Ajax get doclib whitelist.
*
* @param int $doclibID
* @param string $acl open|custom|private
* @access public
* @return string
*/
public function ajaxGetWhitelist($doclibID, $acl)
{
$doclib = $this->doc->getLibById($doclibID);
$users = $this->user->getPairs('noletter|noempty|noclosed');
if($doclib->acl != 'custom' and !empty($doclib->project) and $acl == 'custom')
{
$project = $this->loadModel('project')->getById($doclib->project);
$userList = array();
$projectTeams = $this->loadModel('user')->getTeamMemberPairs($doclib->project);
$stakeholders = $this->loadModel('stakeholder')->getStakeHolderPairs($doclib->project);
foreach($stakeholders as $stakeholder) $userList[$stakeholder] = $users[$stakeholder];
$userList += $projectTeams;
$whitelist = implode(',', array_keys($userList)) . $project->whitelist . ',' .$project->PM . ',' . $doclib->users;
return print(html::select('users[]', $users, $whitelist, "class='form-control chosen' multiple"));
}
return print(html::select('users[]', $users, $doclib->users, "class='form-control chosen' multiple"));
}
/**
* Show files.
*
+20
View File
@@ -24,16 +24,36 @@ function toggleAcl(acl, type)
if(acl == 'custom')
{
$('#whiteListBox').removeClass('hidden');
$('#groupWhiteListBox').removeClass('hidden');
}
else if(acl == 'private')
{
$('#whiteListBox').removeClass('hidden');
$('#groupWhiteListBox').addClass('hidden');
}
else
{
$('#whiteListBox').addClass('hidden');
}
if(type == 'lib')
{
var libType = $('input[name="type"]:checked').val();
var notice = typeof(noticeAcl[libType][acl]) != 'undefined' ? noticeAcl[libType][acl] : '';
$('#noticeAcl').html(notice);
if(libType == 'custom' && acl == 'private') $('#whiteListBox').addClass('hidden');
if(libType == 'project' && typeof(doclibID) != 'undefined')
{
link = createLink('doc', 'ajaxGetWhitelist', 'doclibID=' + doclibID + '&acl=' + acl);
$.get(link, function(users)
{
$('#users').replaceWith(users);
$('#users_chosen').remove();
$('#users').chosen();
})
}
}
else
{
+3 -1
View File
@@ -206,7 +206,9 @@ $lang->doc->selectLibType = 'Please select a type of doc library.';
$lang->doc->noticeAcl['lib']['product']['default'] = 'Users who can access the selected product can access it.';
$lang->doc->noticeAcl['lib']['product']['custom'] = 'Users who can access the selected product or users in the whiltelist can access it.';
$lang->doc->noticeAcl['lib']['project']['default'] = 'Users who can access the selected project can access it.';
$lang->doc->noticeAcl['lib']['project']['custom'] = 'Users who can access the selected project or users in the whiltelist can access it.';
$lang->doc->noticeAcl['lib']['project']['open'] = 'Users who can access the selected project can access it.';
$lang->doc->noticeAcl['lib']['project']['private'] = 'Users who can access the selected project or users in the whiltelist can access it.';
$lang->doc->noticeAcl['lib']['project']['custom'] = 'Users in the whiltelist can access it.';
$lang->doc->noticeAcl['lib']['execution']['default'] = "Users who can access the selected {$lang->executionCommon} can access it.";
$lang->doc->noticeAcl['lib']['execution']['custom'] = "Users who can access the selected {$lang->executionCommon} or users in the whiltelist can access it.";
$lang->doc->noticeAcl['lib']['custom']['open'] = 'All users can access it.';
+3 -1
View File
@@ -206,7 +206,9 @@ $lang->doc->selectLibType = '请选择文档库类型';
$lang->doc->noticeAcl['lib']['product']['default'] = '有所选产品访问权限的用户可以访问。';
$lang->doc->noticeAcl['lib']['product']['custom'] = '有所选产品访问权限或白名单里的用户可以访问。';
$lang->doc->noticeAcl['lib']['project']['default'] = "有所选项目访问权限的用户可以访问。";
$lang->doc->noticeAcl['lib']['project']['custom'] = "有所选项目访问权限或白名单里的用户可以访问。";
$lang->doc->noticeAcl['lib']['project']['open'] = "有所选项目访问权限的用户可以访问。";
$lang->doc->noticeAcl['lib']['project']['private'] = "有所选项目访问权限或白名单里的用户可以访问。";
$lang->doc->noticeAcl['lib']['project']['custom'] = "白名单的用户可以访问。";
$lang->doc->noticeAcl['lib']['execution']['default'] = "有所选{$lang->executionCommon}访问权限的用户可以访问。";
$lang->doc->noticeAcl['lib']['execution']['custom'] = "有所选{$lang->executionCommon}访问权限或白名单里的用户可以访问。";
$lang->doc->noticeAcl['lib']['custom']['open'] = '所有人都可以访问。';
+30 -6
View File
@@ -177,8 +177,7 @@ class docModel extends model
$lib->project = $execution->project;
}
if($lib->acl == 'private') $lib->users = $this->app->user->account;
if($lib->acl == 'custom')
if($lib->acl == 'custom' or $lib->acl == 'private')
{
$trimedUsers = ',' . trim($lib->users, ',') . ',';
if(strpos($trimedUsers, ',' . $this->app->user->account . ',') === false) $lib->users .= ',' . $this->app->user->account;
@@ -254,10 +253,20 @@ class docModel extends model
->join('groups', ',')
->join('users', ',')
->get();
if($lib->acl == 'private')
if($oldLib->type == 'project' or $oldLib->type == 'custom')
{
$libCreatedBy = $this->dao->select('*')->from(TABLE_ACTION)->where('objectType')->eq('doclib')->andWhere('objectID')->eq($libID)->andWhere('action')->eq('created')->fetch('actor');
$lib->users = $libCreatedBy ? $libCreatedBy : $this->app->user->account;
if($oldLib->type == 'custom')
{
if($lib->acl == 'private') $lib->users = $libCreatedBy ? $libCreatedBy : $this->app->user->account;
}
else
{
$openedBy = $this->dao->findById($oldLib->project)->from(TABLE_PROJECT)->fetch('openedBy');
if($lib->acl == 'private' and $lib->acl == 'custom') $lib->users .= ',' . $libCreatedBy ? $libCreatedBy : $openedBy;
}
}
$lib->name = trim($lib->name); //Temporary treatment: Code for bug #15528.
@@ -906,11 +915,17 @@ class docModel extends model
if(isset($object->addedBy) and $object->addedBy == $this->app->user->account) return true;
if(isset($object->users) and strpos(",{$object->users},", $account) !== false) return true;
if($object->project and $object->main)
if($object->project and $object->acl == 'private')
{
$stakeHolders = array();
$project = $this->loadModel('project')->getById($object->project);
$projectTeams = $this->loadModel('user')->getTeamMemberPairs($object->project);
$authorizedUsers = $this->user->getProjectAuthedUsers($project, '', $projectTeams, array_flip(explode(",", $project->whitelist)));
$stakeHolderList = $this->loadModel('stakeholder')->getStakeHolderPairs($object->project);
foreach($stakeHolderList as $stakeHolder) $stakeHolders[$stakeHolder] = $stakeHolder;
$authorizedUsers = $this->user->getProjectAuthedUsers($project, $stakeHolders, $projectTeams, array_flip(explode(",", $project->whitelist)));
if(strpos(",{$object->users},", $account) !== false) return true;
if(array_key_exists($this->app->user->account, array_filter($authorizedUsers))) return true;
}
@@ -1318,6 +1333,15 @@ class docModel extends model
/* Sort project. */
$orderedProjects = array();
/* Project permissions for DocLib whitelist */
if($this->app->tab == 'doc')
{
$myObjects = $this->dao->select('t2.id, t2.name')->from(TABLE_DOCLIB)->alias('t1')
->leftjoin(TABLE_PROJECT)->alias('t2')->on('t1.project=t2.id')
->where("CONCAT(',', t1.users, ',')")->like("%,{$this->app->user->account},%")
->fetchPairs();
}
$objects = $this->dao->select('*')->from(TABLE_PROJECT)
->where('type')->eq('project')
->andWhere('deleted')->eq(0)
+1 -1
View File
@@ -59,7 +59,7 @@
<tr id='whiteListBox' class='hidden'>
<th><?php echo $lang->doc->whiteList;?></th>
<td>
<div class='input-group'>
<div id='groupWhiteListBox' class='input-group'>
<span class='input-group-addon groups-addon'><?php echo $lang->doclib->group?></span>
<?php echo html::select('groups[]', $groups, '', "class='form-control chosen' multiple")?>
</div>
+2 -1
View File
@@ -12,6 +12,7 @@
?>
<?php include '../../common/view/header.lite.html.php';?>
<?php include '../../common/view/chosen.html.php';?>
<?php js::set('doclibID', $lib->id);?>
<?php if($lib->type == 'product'):?>
<style> .chosen-container .chosen-results {max-height: 180px;}</style>
<?php else:?>
@@ -63,7 +64,7 @@
<tr id='whiteListBox' class='hidden'>
<th><?php echo $lang->doc->whiteList?></th>
<td>
<div class='input-group'>
<div id='groupWhiteListBox' class='input-group'>
<span class='input-group-addon groups-addon'><?php echo $lang->doclib->group?></span>
<?php echo html::select('groups[]', $groups, $lib->groups, "class='form-control chosen' multiple")?>
</div>
+18 -3
View File
@@ -874,9 +874,24 @@ class projectModel extends model
/* Create doc lib. */
$this->app->loadLang('doc');
$authorizedUsers = array();
$authorizedUsers = $project->whitelist . ',' . $project->PM . ',' . $project->openedBy . ',';
$authorizedUsers = array_unique(explode(',', trim($authorizedUsers, ',')));
if($project->parent and $project->acl == 'program')
{
$stakeHolders = $this->loadModel('stakeholder')->getStakeHolderPairs($project->parent);
foreach($stakeHolders as $stakeHolder) $authorizedUsers[$stakeHolder] = $stakeHolder;
foreach(explode(',', $project->whitelist) as $white)
{
if(empty($white)) continue;
$authorizedUsers[$white] = $white;
}
$authorizedUsers[$project->PM] = $project->PM;
$authorizedUsers[$project->openedBy] = $project->openedBy;
$authorizedUsers[$program->PM] = $program->PM;
$authorizedUsers[$program->openedBy] = $program->openedBy;
}
$lib = new stdclass();
$lib->project = $projectID;
@@ -884,7 +899,7 @@ class projectModel extends model
$lib->type = 'project';
$lib->main = '1';
$lib->acl = $project->acl != 'program' ? $project->acl : 'custom';
if($project->acl == 'private') $lib->users = ',' . implode(',', $authorizedUsers) . ',';
$lib->users = ',' . implode(',', array_filter($authorizedUsers)) . ',';
$this->dao->insert(TABLE_DOCLIB)->data($lib)->exec();
$this->updateProducts($projectID);