* adjust for lib priv.
This commit is contained in:
+44
-3
@@ -130,7 +130,12 @@ class docModel extends model
|
||||
$this->dao->insert(TABLE_DOCLIB)->data($lib)->autoCheck()
|
||||
->batchCheck('name', 'notempty')
|
||||
->exec();
|
||||
return $this->dao->lastInsertID();
|
||||
$libID = $this->dao->lastInsertID();
|
||||
|
||||
$libType = $this->post->libType;
|
||||
if($lib->acl != 'private' and ($libType == 'project' or $libType == 'product')) $this->setLibUsers($libType, $lib->$libType);
|
||||
|
||||
return $libID;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -594,7 +599,7 @@ class docModel extends model
|
||||
|
||||
$account = ',' . $this->app->user->account . ',';
|
||||
if(strpos($this->app->company->admins, $account) !== false) return true;
|
||||
if($object->acl == 'private' and $object->users == $this->app->user->account) return true;
|
||||
if($object->acl == 'private' and strpos(",$object->users,", $account) !== false) return true;
|
||||
if($object->acl == 'custom')
|
||||
{
|
||||
if(strpos(",$object->users,", $account) !== false) return true;
|
||||
@@ -830,7 +835,7 @@ class docModel extends model
|
||||
if(strpos($this->app->company->admins, $account) === false)
|
||||
{
|
||||
$condition .= "{$table}acl='open'";
|
||||
$condition .= " OR ({$table}acl='private' and {$table}users='{$this->app->user->account}')";
|
||||
$condition .= " OR ({$table}acl='private' and CONCAT(',', {$table}users, ',') like '%$account%')";
|
||||
$condition .= " OR ({$table}acl='custom' and (";
|
||||
foreach($this->app->user->groups as $groupID) $condition .= "(CONCAT(',', {$table}groups, ',') like '%,$groupID,%') OR ";
|
||||
$condition .= "(CONCAT(',', {$table}users, ',') like '%$account%')";
|
||||
@@ -1103,4 +1108,40 @@ class docModel extends model
|
||||
|
||||
return $crumb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set lib users.
|
||||
*
|
||||
* @param string $type
|
||||
* @param int $objectID
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function setLibUsers($type, $objectID)
|
||||
{
|
||||
if($type != 'project' and $type != 'product') return true;
|
||||
|
||||
$libs = $this->dao->select('*')->from(TABLE_DOCLIB)->where($type)->eq($objectID)->fetchAll();
|
||||
|
||||
if($type == 'product')
|
||||
{
|
||||
$teams = $this->dao->select('t1.account')->from(TABLE_TEAM)->alias('t1')
|
||||
->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2')->on('t1.project=t2.project')
|
||||
->leftJoin(TABLE_PROJECT)->alias('t3')->on('t1.project=t3.id')
|
||||
->where('t2.product')->eq($objectID)
|
||||
->andWhere('t3.deleted')->eq('0')
|
||||
->fetchPairs('account', 'account');
|
||||
}
|
||||
elseif($type == 'project')
|
||||
{
|
||||
$teams = $this->dao->select('account')->from(TABLE_TEAM)->where('project')->eq($objectID)->fetchPairs('account', 'account');
|
||||
}
|
||||
|
||||
foreach($libs as $lib)
|
||||
{
|
||||
foreach(explode(',', $lib->users) as $account) $teams[$account] = $account;
|
||||
$this->dao->update(TABLE_DOCLIB)->set('users')->eq(join(',', $teams))->where('id')->eq($lib->id)->exec();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,9 +261,9 @@ class productModel extends model
|
||||
$lib->product = $productID;
|
||||
$lib->name = $product->name;
|
||||
$lib->main = '1';
|
||||
$lib->acl = $product->acl;
|
||||
$lib->acl = $product->acl == 'open' ? 'open' : 'custom';
|
||||
$lib->users = $this->app->user->account;
|
||||
if($product->acl == 'custom') $lib->groups = $product->whitelist;
|
||||
if($product->acl == 'private') $lib->users = $this->app->user->account;
|
||||
$this->dao->insert(TABLE_DOCLIB)->data($lib)->exec();
|
||||
|
||||
return $productID;
|
||||
@@ -297,10 +297,11 @@ class productModel extends model
|
||||
{
|
||||
if($product->acl != $oldProduct->acl)
|
||||
{
|
||||
$this->dao->update(TABLE_DOCLIB)->set('acl')->eq($product->acl)->where('product')->eq($productID)->exec();
|
||||
if($product->acl == 'open') $this->dao->update(TABLE_DOCLIB)->set('groups')->eq('')->set('users')->eq('')->where('product')->eq($productID)->exec();
|
||||
$this->dao->update(TABLE_DOCLIB)->set('acl')->eq($product->acl == 'open' ? 'open' : 'custom')->where('product')->eq($productID)->exec();
|
||||
if($product->acl == 'open') $this->dao->update(TABLE_DOCLIB)->set('groups')->eq('')->where('product')->eq($productID)->exec();
|
||||
if($product->acl == 'custom') $this->dao->update(TABLE_DOCLIB)->set('groups')->eq($product->whitelist)->where('product')->eq($productID)->exec();
|
||||
if($product->acl == 'private') $this->dao->update(TABLE_DOCLIB)->set('users')->eq($oldProduct->createdBy)->set('groups')->eq('')->where('product')->eq($productID)->exec();
|
||||
if($product->acl == 'private') $this->dao->update(TABLE_DOCLIB)->set('groups')->eq('')->where('product')->eq($productID)->exec();
|
||||
if($product->acl != 'open') $this->loadModel('doc')->setLibUsers('product', $productID);
|
||||
}
|
||||
$this->file->updateObjectID($this->post->uid, $productID, 'product');
|
||||
return common::createChanges($oldProduct, $product);
|
||||
|
||||
+55
-15
@@ -274,14 +274,24 @@ class projectModel extends model
|
||||
$lib->name = $project->name;
|
||||
$lib->main = '1';
|
||||
$lib->acl = $project->acl == 'open' ? 'open' : 'custom';
|
||||
|
||||
$teams = $this->dao->select('account')->from(TABLE_TEAM)->where('project')->eq($projectID)->fetchPairs('account', 'account');
|
||||
$lib->users = join(',', $teams);
|
||||
if($project->acl == 'custom') $lib->groups = $project->whitelist;
|
||||
if($project->acl == 'private' or $project->acl == 'custom')
|
||||
{
|
||||
$teams = $this->dao->select('account')->from(TABLE_TEAM)->where('project')->eq($projectID)->fetchPairs('account', 'account');
|
||||
$lib->users = join(',', $teams);
|
||||
}
|
||||
$this->dao->insert(TABLE_DOCLIB)->data($lib)->exec();
|
||||
|
||||
$docLibs = $this->dao->select('id,users')->from(TABLE_DOCLIB)->alias('t1')
|
||||
->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2')->on('t1.product=t2.product')
|
||||
->where('t2.project')->eq($projectID)
|
||||
->andWhere('t1.acl')->eq('custom')
|
||||
->fetchAll('id');
|
||||
foreach($docLibs as $lib)
|
||||
{
|
||||
$docUsers = $teams + explode(',', $lib->users);
|
||||
$docUsers = array_unique($docUsers);
|
||||
$this->dao->update(TABLE_DOCLIB)->set('users')->eq(join(',', $docUsers))->where('id')->eq($lib->id)->exec();
|
||||
}
|
||||
|
||||
return $projectID;
|
||||
}
|
||||
}
|
||||
@@ -341,7 +351,7 @@ class projectModel extends model
|
||||
if($project->acl != $oldProject->acl)
|
||||
{
|
||||
$this->dao->update(TABLE_DOCLIB)->set('acl')->eq($project->acl == 'open' ? 'open' : 'custom')->where('project')->eq($projectID)->exec();
|
||||
if($project->acl == 'open') $this->dao->update(TABLE_DOCLIB)->set('groups')->eq('')->set('users')->eq('')->where('project')->eq($projectID)->exec();
|
||||
if($project->acl == 'open') $this->dao->update(TABLE_DOCLIB)->set('groups')->eq('')->where('project')->eq($projectID)->exec();
|
||||
if($project->acl == 'custom')
|
||||
{
|
||||
$teams = $this->dao->select('account')->from(TABLE_TEAM)->where('project')->eq($projectID)->fetchPairs('account', 'account');
|
||||
@@ -989,16 +999,26 @@ class projectModel extends model
|
||||
*/
|
||||
public function updateProducts($projectID)
|
||||
{
|
||||
$deletedProducts = $this->dao->select('product')->from(TABLE_PROJECTPRODUCT)->where('project')->eq((int)$projectID)->fetchPairs('product', 'product');
|
||||
$this->dao->delete()->from(TABLE_PROJECTPRODUCT)->where('project')->eq((int)$projectID)->exec();
|
||||
if(!isset($_POST['products'])) return;
|
||||
$products = $_POST['products'];
|
||||
$branches = $_POST['branch'];
|
||||
|
||||
$existedProducts = array();
|
||||
$addedProducts = array();
|
||||
foreach($products as $i => $productID)
|
||||
{
|
||||
if(empty($productID)) continue;
|
||||
if(isset($existedProducts[$productID])) continue;
|
||||
if(isset($deletedProducts[$productID]))
|
||||
{
|
||||
unset($deletedProducts[$productID]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$addedProducts[$productID] = $productID;
|
||||
}
|
||||
|
||||
$data = new stdclass();
|
||||
$data->project = $projectID;
|
||||
@@ -1007,6 +1027,10 @@ class projectModel extends model
|
||||
$this->dao->insert(TABLE_PROJECTPRODUCT)->data($data)->exec();
|
||||
$existedProducts[$productID] = true;
|
||||
}
|
||||
|
||||
$this->loadModel('doc');
|
||||
foreach($deletedProducts as $productID) $this->doc->setLibUsers('product', $productID);
|
||||
foreach($addedProducts as $productID) $this->doc->setLibUsers('product', $productID);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1428,16 +1452,18 @@ class projectModel extends model
|
||||
}
|
||||
|
||||
$acl = $this->dao->select('acl')->from(TABLE_PROJECT)->where('id')->eq($projectID)->fetch('acl');
|
||||
if($acl == 'private')
|
||||
if($acl != 'open') $this->loadModel('doc')->setLibUsers('project', $projectID);
|
||||
|
||||
$docLibs = $this->dao->select('id,users')->from(TABLE_DOCLIB)->alias('t1')
|
||||
->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2')->on('t1.product=t2.product')
|
||||
->where('t2.project')->eq($projectID)
|
||||
->andWhere('t1.acl')->eq('custom')
|
||||
->fetchAll('id');
|
||||
foreach($docLibs as $lib)
|
||||
{
|
||||
$docLibs = $this->dao->select('id,users')->from(TABLE_DOCLIB)->where('project')->eq($projectID)->fetchAll('id');
|
||||
foreach($docLibs as $lib)
|
||||
{
|
||||
if(empty($lib->users)) continue;
|
||||
$docUsers = $accounts + explode(',', $lib->users);
|
||||
$docUsers = array_unique($docUsers);
|
||||
$this->dao->update(TABLE_DOCLIB)->set('users')->eq(join(',', $docUsers))->where('id')->eq($lib->id)->exec();
|
||||
}
|
||||
$docUsers = $accounts + explode(',', $lib->users);
|
||||
$docUsers = array_unique($docUsers);
|
||||
$this->dao->update(TABLE_DOCLIB)->set('users')->eq(join(',', $docUsers))->where('id')->eq($lib->id)->exec();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1452,6 +1478,20 @@ class projectModel extends model
|
||||
public function unlinkMember($projectID, $account)
|
||||
{
|
||||
$this->dao->delete()->from(TABLE_TEAM)->where('project')->eq((int)$projectID)->andWhere('account')->eq($account)->exec();
|
||||
|
||||
$acl = $this->dao->select('acl')->from(TABLE_PROJECT)->where('id')->eq($projectID)->fetch('acl');
|
||||
if($acl != 'open') $this->loadModel('doc')->setLibUsers('project', $projectID);
|
||||
|
||||
$docLibs = $this->dao->select('id,users')->from(TABLE_DOCLIB)->alias('t1')
|
||||
->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2')->on('t1.product=t2.product')
|
||||
->where('t2.project')->eq($projectID)
|
||||
->andWhere('t1.acl')->eq('custom')
|
||||
->fetchAll('id');
|
||||
foreach($docLibs as $lib)
|
||||
{
|
||||
$docUsers = str_replace(",$account,", '', ",{$lib->users},");
|
||||
$this->dao->update(TABLE_DOCLIB)->set('users')->eq($docUsers)->where('id')->eq($lib->id)->exec();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1173,9 +1173,9 @@ class upgradeModel extends model
|
||||
$lib->product = $productID;
|
||||
$lib->name = $product->name;
|
||||
$lib->main = 1;
|
||||
$lib->acl = $product->acl;
|
||||
$lib->acl = $product->acl == 'open' ? 'open' : 'custom';
|
||||
$lib->users = $product->createdBy;
|
||||
if($product->acl == 'custom') $lib->groups = $product->whitelist;
|
||||
if($product->acl == 'private') $lib->users = $product->createdBy;
|
||||
$this->dao->insert(TABLE_DOCLIB)->data($lib)->exec();
|
||||
$libID = $this->dao->lastInsertID();
|
||||
|
||||
@@ -1216,15 +1216,25 @@ class upgradeModel extends model
|
||||
$lib->name = $project->name;
|
||||
$lib->main = 1;
|
||||
$lib->acl = $project->acl == 'open' ? 'open' : 'custom';
|
||||
|
||||
$teams = $this->dao->select('project, account')->from(TABLE_TEAM)->where('project')->eq($projectID)->fetchPairs('account', 'account');
|
||||
$lib->users = join(',', $teams);
|
||||
if($project->acl == 'custom') $lib->groups = $project->whitelist;
|
||||
if($project->acl == 'private' or $project->acl == 'custom')
|
||||
{
|
||||
$teams = $this->dao->select('project, account')->from(TABLE_TEAM)->where('project')->eq($projectID)->fetchPairs('account', 'account');
|
||||
$lib->users = join(',', $teams);
|
||||
}
|
||||
$this->dao->insert(TABLE_DOCLIB)->data($lib)->exec();
|
||||
$libID = $this->dao->lastInsertID();
|
||||
|
||||
$docLibs = $this->dao->select('id,users')->from(TABLE_DOCLIB)->alias('t1')
|
||||
->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2')->on('t1.product=t2.product')
|
||||
->where('t2.project')->eq($projectID)
|
||||
->andWhere('t1.acl')->eq('custom')
|
||||
->fetchAll('id');
|
||||
foreach($docLibs as $lib)
|
||||
{
|
||||
$docUsers = $teams + explode(',', $lib->users);
|
||||
$docUsers = array_unique($docUsers);
|
||||
$this->dao->update(TABLE_DOCLIB)->set('users')->eq(join(',', $docUsers))->where('id')->eq($lib->id)->exec();
|
||||
}
|
||||
|
||||
$relation = array();
|
||||
foreach($projectDocModules as $moduleID => $module)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user