* Code for manage priv.

This commit is contained in:
liumengyi
2023-04-04 15:58:01 +08:00
parent 543e719155
commit 6f8390a091
4 changed files with 28 additions and 23 deletions
+1 -1
View File
@@ -250,7 +250,7 @@ class group extends control
$privLang = $this->group->transformPrivLang($privs);
$privList = array();
foreach($privs as $privID => $priv)
foreach($privs as $priv)
{
if(!isset($privList[$priv->parentCode])) $privList[$priv->parentCode] = array();
if(!isset($privList[$priv->parentCode][$priv->package])) $privList[$priv->parentCode][$priv->package] = array();
+18 -13
View File
@@ -1430,16 +1430,20 @@ class groupModel extends model
$modules = array_keys($modules);
$modules = implode(',', $modules);
$privs = $this->dao->select("t1.*, t2.`key`, t2.`value`, t2.desc, t4.code as parentCode, INSTR('$modules', t4.id) as moduleOrder")->from(TABLE_PRIV)->alias('t1')
$privs = $this->dao->select("t1.*, t2.`key`, t2.`value`, t2.desc, IFNULL(t4.code, t1.module) as parentCode, INSTR('$modules', t4.id) as moduleOrder")->from(TABLE_PRIV)->alias('t1')
->leftJoin(TABLE_PRIVLANG)->alias('t2')->on('t1.id=t2.objectID')
->leftJoin(TABLE_PRIVMANAGER)->alias('t3')->on('t1.package=t3.id')
->leftJoin(TABLE_PRIVMANAGER)->alias('t4')->on('t3.parent=t4.id')
->where('1=1')
->beginIF(!empty($view) and $view != 'general')->andWhere('t4.id')->in($modules)->fi()
->andWhere('t2.lang')->eq($this->app->getClientLang())
->andWhere('t2.objectType')->eq('priv')
->andWhere('t3.type')->eq('package')
->andWhere('((t3.type')->eq('package')
->andWhere('t4.type')->eq('module')
->beginIF(!empty($view) and $view != 'general')->andWhere('t4.code')->in($modules)->fi()
->markRight(1)
->orWhere('(t1.package')->eq('0')
->beginIF(!empty($view) and $view != 'general')->andWhere('t1.module')->in($modules)->fi()
->markRight(2)
->orderBy("moduleOrder asc, t3.order asc, `order` asc")
->page($pager)
->fetchAll('key');
@@ -1853,7 +1857,7 @@ class groupModel extends model
*/
public function getPrivLangPairs()
{
return $this->dao->select('priv,name')->from(TABLE_PRIVLANG)
return $this->dao->select('objectID as priv,value as name')->from(TABLE_PRIVLANG)
->where('lang')->eq($this->app->clientLang)
->fetchPairs();
}
@@ -1878,12 +1882,12 @@ class groupModel extends model
* @access public
* @return array
*/
public function getPrivManagerPairs($type, $parent = 0, $field = 'value')
public function getPrivManagerPairs($type, $parent = 0)
{
$parentType = $type == 'module' ? 'view' : 'module';
$parent = $this->dao->select('id as parent')->from(TABLE_PRIVMANAGER)->where('type')->eq($parentType)->andWhere('code')->eq($parent)->fetch('parent');
$parentType = $type == 'package' ? 'module' : 'view';
$parent = !empty($parent) ? $this->dao->select('id as parent')->from(TABLE_PRIVMANAGER)->where('type')->eq($parentType)->andWhere('code')->eq($parent)->fetch('parent') : 0;
$managers = $this->dao->select('t1.id,t2.key,t2.value')
$managers = $this->dao->select('t1.id,t1.code,t2.key,t2.value')
->from(TABLE_PRIVMANAGER)->alias('t1')
->leftJoin(TABLE_PRIVLANG)->alias('t2')->on('t1.id=t2.objectID')
->where('t1.type')->eq($type)
@@ -1897,11 +1901,12 @@ class groupModel extends model
$moduleLang = $type == 'module' ? $this->getMenuModules('', true) : array();
$pairs = array();
foreach($managers as $id => $manager)
foreach($managers as $managerID => $manager)
{
if(!empty($manager->value)) $pairs[$id] = $manager->value;
if(empty($manager->value) and $type == 'view') $pairs[$id] = $this->lang->{$manager->key}->common;
if(empty($manager->value) and $type == 'module') $pairs[$id] = zget($moduleLang, $manager->key);
$key = $type == 'package' ? $managerID : $manager->code;
if(!empty($manager->value)) $pairs[$key] = $manager->value;
if(empty($manager->value) and $type == 'view') $pairs[$key] = $this->lang->{$manager->key}->common;
if(empty($manager->value) and $type == 'module') $pairs[$key] = zget($moduleLang, $manager->key);
}
return $pairs;
}
@@ -1927,7 +1932,7 @@ class groupModel extends model
list($moduleName, $methodLang) = explode('-', $priv->key);
$this->app->loadLang($moduleName);
$priv->name = $this->lang->{$moduleName}->$methodLang;
$priv->name = !empty($moduleName) && !empty($methodLang) ? $this->lang->{$moduleName}->$methodLang : '';
}
}
@@ -35,8 +35,8 @@
<?php foreach($privs as $privID => $priv):?>
<div class="group-item">
<div class="checkbox-primary">
<?php $action = $priv->methodName;?>
<?php $label = zget($privLang, $privID, $action);?>
<?php $action = $priv->method;?>
<?php $label = zget($privLang, $privID, $lang->$module->$action);?>
<?php echo html::checkbox("actions[$module][]", array($action => $label), '', "title='{$label}' id='actions[$module]$action' data-id='$privID'");?>
</div>
</div>
+7 -7
View File
@@ -133,13 +133,13 @@
</td>
<?php endif;?>
<td id='<?php echo $moduleName;?>' class='pv-10px' colspan='<?php echo !empty($lang->$moduleName->menus) ? 1 : 2?>'>
<?php foreach($moduleActions as $action => $actionLabel):?>
<?php if(!empty($lang->$moduleName->menus) and $action == 'browse') continue;;?>
<?php if(!empty($version) and strpos($changelogs, ",$moduleName-$actionLabel,") === false) continue;?>
<?php if(!isset($privs["$moduleName-$actionLabel"])) continue;?>
<?php $privName = (isset($privLang["$moduleName-$actionLabel"]) and !empty($privLang->name)) ? $privLang["$moduleName-$actionLabel"]->name : $lang->$moduleName->$actionLabel;?>
<div class='group-item'>
<?php echo html::checkbox("actions[{$moduleName}]", array($action => $privName), isset($groupPrivs[$moduleName][$action]) ? $action : '', "title='{$privName}'", 'inline');?>
<?php foreach($privs as $privID => $priv):?>
<div class="group-item">
<div class="checkbox-primary">
<?php $action = $priv->method;?>
<?php $privName = $privLang[$privID]->name;?>
<?php echo html::checkbox("actions[$moduleName][]", array($action => $privName), '', "title='{$privName}' id='actions[$moduleName]$action' data-id='$privID'");?>
</div>
</div>
<?php endforeach;?>
</td>