来源:http://trac.seagullproject.org/wiki/Howto/UI/SetAdminGuiForOtherRoles

如何为其它角色用户设置使用管理员的界面

这是http://trac.seagullproject.org/wiki/RFC/AdminGui这篇文章的扩充版本以帮助解决同样的问题。这里的代码只适用于2006年7月05日的SGL0.6 RC3版本。

注意

从eagull 0.6.3开始你只需将需要使用管理员GUI的角色添加到全局配置文件中就可以了。

在 <host>.conf.php file:

$conf['site']['rolesHaveAdminGui'] = 'SGL_ADMIN,SGL_TRANSLATOR';

或以admin登陆:

General → Configuration → General → 可以使用查看管理员GUI界面的角色

问题

我想创建一个只有访问站点内某些模块的管理员角色,这些角色的用户也只用SGL中超级用户的默认管理界面。

按下列步骤添加新用户

1. 复制member角色,并将其重命名为maintainer。在我的情况下,它的role_id = 3;

2. 创建一个新用户并赋予它maintainer角色权限。

3. 将你的maintainer角色添加到/branches/0.6-bugfix/lib/SGL/Task/Init.php,下面是现有的Seagull用户角色,所有修改后你的代码应该是:

      //  Seagull user roles
      define('SGL_ANY_ROLE',                  -2);
      define('SGL_UNASSIGNED',                -1);
      define('SGL_GUEST',                     0);
      define('SGL_ADMIN',                     1);
      define('SGL_MEMBER',                    2);
      define('SGL_MAINTAINER',                3); //这便添加了你的新角色

4. 将/branches/0.6-bugfix/lib/SGL/Task/Process.php文件中的下列代码:

           if ($userRid == SGL_ADMIN) {
              $adminGuiAllowed = true;
          }

替换成下面这段代码,这样就给maintainer角色用户以访问超级用户的管理界面的权限:

          // first check if userRID allows to switch to adminGUI
          if ($userRid == SGL_ADMIN || $userRid == SGL_MAINTAINER) {
              $adminGuiAllowed = true;
          }

5. 将/branches/0.6-bugfix/lib/SGL/Task/Manager.php文件中的下列获取模板的代码:

 function getTemplate(&$input)
  {
      $req = $input->getRequest();
      $mgrName = $req->get('managerName');
      $userRid = SGL_Session::getRoleId();
      if (isset($this->conf[$mgrName]['adminGuiAllowed'])
             && $this->conf[$mgrName]['adminGuiAllowed']
             && $userRid == SGL_ADMIN) {
          $this->template = 'admin_' . $this->template;
      }
  }

替换成这个函数:

  function getTemplate(&$input)
  {
      $req = $input->getRequest();
      $mgr = $req->get('managerName');
      $userRid = SGL_Session::getRoleId();
      if (isset($this->conf[$mgrName]['adminGuiAllowed'])
             && $this->conf[$mgrName]['adminGuiAllowed']
             && ($userRid == SGL_ADMIN || $userRid == SGL_MAINTAINER)) {
          $this->template = 'admin_' . $this->template;
      }
  }

6. 如果想让maintainer角色的用户可以使用Publisher模块添加并编辑文章,那么请将

/branches/0.6-bugfix/modules/publisher/classes/ArticleMgr.php文件中的下列代码:

&& SGL_Session::getRoleId() != SGL_ADMIN) {

替换成下列代码:

&& SGL_Session::getRoleId() != SGL_ADMIN && SGL_Session::getRoleId() != SGL_MAINTAINER) {

(Contributed by jpaszek on Fri Mar 2 17:13:28 2007)

Manager specific steps

步骤7,8,9 不是必须的,只在你想要让maintainer角色的用户能够有访问这些管理类的权限时修改。

7. 将|/branches/0.6-bugfix/modules/publisher/classes/DocumentMgr.php文件中的这行代码:

 $input->isAdmin = (SGL_Session::getRoleId() == SGL_ADMIN)

替换成:

 $input->isAdmin = (SGL_Session::getRoleId() == SGL_ADMIN || SGL_Session::getRoleId() == SGL_MAINTAINER)

8. 将|/branches/0.6-bugfix/modules/publisher/classes/ArticleMgr.php文件中的这行代码:

 if (SGL_Session::getRoleId() == SGL_ADMIN) {

替换成:

 if (SGL_Session::getRoleId() == SGL_ADMIN || SGL_Session::getRoleId() == SGL_MAINTAINER) {

9. 如果你想让Section Manager |/branches/0.6-bugfix/modules/navigation/classes/SectionMgr.php 只显示允许maintainer角色用户修改的导航菜单,将函数_cmd_list替换成这段代码:

      //  get all sections
      $aSections = $this->da->getSectionTree();
      $output->results  = &$aSections;
$userRid = SGL_Session::getRoleId();
      if($userRid == SGL_ADMIN) {
          //  get all sections
          $aSections        = $this->da->getSectionTree();
      } else {
          // get only sections visible by this role
          $aSections        = $this->da->getSectionTree($userRid);
      }

并将 |/branches/0.6-bugfix/modules/navigation/classes/SectionMgr.php 文件中的函数 _editDisplay的这行代码:

    $aNodesForSelect = $this->da->getSectionsForSelect();

替换成这段代码:

      $userRid = SGL_Session::getRoleId();
      if($userRid == SGL_ADMIN) {
          //  get all sections
          $aNodesForSelect = $this->da->getSectionsForSelect();
      } else {
          // get only sections visible by this role
          $aNodesForSelect = $this->da->getSectionsForSelect($userRid);
      }

使用admin section修改某些偏好

10. 在Block中设置,使用maintainer角色可以访问这些section

  • Admin Menu - AdminNav
  • Categories - AdminCategory

11. 设置允许maintainer角色用户访问navigation section。我的设置是:

  • Navigation
  • My Account
  • Publishing

12. 为maintainer角色设置访问managers/actions的权限,我的设置是:

  • articlemgr
  • articleviewmgr
  • categorymgr
  • documentmgr
  • filemgr
  • sectionmgr

其它修改

下面的修改不是必须的,当然如果你觉得合适的话,你也可以修改。

修改|/branches/0.6-bugfix/modules/navigation/classes/NavigationDAO.php中的函数getSectionTree,修改后,它的前面几行应该是这样的:

function getSectionTree($roleId = null)

      {
          $this->nestedSet->setImage('folder', 'images/treeNav/file.png');
          $sectionNodes = $this->nestedSet->getTree();
          //  remove the nodes that are not visible by roleId
          if(!empty($roleId)) {
              foreach ($sectionNodes as $k => $aValues) {
                  $aPerms = explode(',', $aValues['perms']);
                  if(!in_array($roleId, $aPerms) && !in_array(SGL_ANY_ROLE, $aPerms)) {
                      unset($sectionNodes[$k]);
                  }
              }
          }

和getSectionTree函数一样,修改|/branches/0.6-bugfix/modules/navigation/classes/NavigationDAO.php 中的函数getSectionsForSelect,修改后它的前几行应该是:

  function getSectionsForSelect($roleId = null)
+/- line 453
      foreach ($sectionNodesArray as $k => $sectionNode) {
     // show only sections visible by roleId
           if(!empty($roleId)) { 
              $aPerms = explode(',', $sectionNode['perms']);
              if(!in_array($roleId, $aPerms) && !in_array(SGL_ANY_ROLE, $aPerms)) {
                  unset($sectionNodesArray[$k]);
                  continue; 
              }
          }

补丁文件

如果你想马上尝试一上,你可以从SVN上下一个SGL,安装后应用maintainer_full_patch.txt补丁。以下列账户登陆:maintainer,密码:admin

maintainer_patch.txt只包含在3,4,5,8步骤中出现的代码。

结论

本指南讲述了如何在0.6.3中实现一个maintainer角色的方法,但并不是最好的方法,因为php中比较困难的代码,但是在更有效的解决方案出现之前,这应该是一个有效的解决方法。本指南最好也是简单的部分是使用了标准的user/roles/perms。

注意:要使用更改生效不要忘了:

  • 为用户做完整同步
  • 清除缓存
  • 登出,并以maintainer用户登陆
 
howto/setadminguiforotherroles.txt · 最后更改: 2010/05/30 00:21 (外部编辑)
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2