跳转到主要内容
laoxue 提交于 6 April 2014

在CMS网站中,我们常常需要给不同的角色分配不同的浏览权限。在drupal7中,采用分类权限控制法就可以实现此功能。比如:我们设置了“分公司领导”、“分公司中层”、和“分公司员工”等角色,在分类词汇“分享对象”中设置“分公司领导”、“分公司中层”、“分公司员工”等。如果我们希望角色“分公司领导”可以浏览上述全部内容,角色“分公司中层”可以浏览“分公司中层”和“分公司员工”分类的内容,角色“分公司员工”只能浏览“分公司员工”分类的内容。下面介绍具体的实现方法。

1、安装Taxonomy Access Control模块并启用。

2、点击配置》用户》Taxonomy Access Control。说明: http://img.blog.csdn.net/20140406082344703?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFveHVlNjY5OQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast

 

3、编辑匿名用户和注册用户的角色权限。

 

勾选Global下面的default选框,查看、更新、删除选项都选“D”,Add Tag、View Tag 不勾选。保存。

说明: http://img.blog.csdn.net/20140406082353390?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFveHVlNjY5OQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast

 

4、设置“分公司领导”、“分公司中层”、“分公司员工”角色为可编辑状态。

编辑“分公司领导”角色的权限:

说明: http://img.blog.csdn.net/20140406094053234?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFveHVlNjY5OQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

设置好分享对象“分公司领导”的相应权限后,再依次增加分享对象“分公司中层”和“分公司员工”并设置好相应的权限。

说明: http://img.blog.csdn.net/20140406094101640?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFveHVlNjY5OQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

至此,完成了角色“分公司领导”的分类访问授权。如果登录用户的角色是“分公司领导”,那么他就可以浏览“分公司领导”、“分公司中层”、“分公司员工”三个分类下面的内容了。

其他角色的分类权限设置照此办理。

5、应用案例

在新增文章时,选择相应的分享对象,文章保存后,会有分享对象的术语列示,点击可链接到相关分类的页面列表。当然,对无权用户,这个标签和链接都是不可见的。假如用户不属于“分公司领导”角色,新建一篇文章,选择“分享对象”为“分公司领导”:

说明: http://img.blog.csdn.net/20140406095810781?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFveHVlNjY5OQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

以用户hyh登录。用户hyh属于“分公司领导”角色。那么他可以看到这篇文章和相应的分类标签:

说明: http://img.blog.csdn.net/20140406095954437?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFveHVlNjY5OQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

点击“分享对象”下的“分公司领导”链接,就可以浏览“分公司领导”分类下的文章列表:

说明: http://img.blog.csdn.net/20140406100930250?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFveHVlNjY5OQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

 

现在以“gechene”用户登录。因为““gechene”不属于“分公司领导”角色,他看不到上面的页面。

6、下面是Taxonomy Access Control 的英文用法说明。

Using the Taxonomy Access Control Module

Here's the example we're going to use in this tutorial.

  • On this screen we have 5 content items, all of the same content type.
  • Each content item is tagged with the appropriate state. For example, San Francisco is tagged with "California".
  • We want to deny anonymous users the ability to view items from some states.

说明: edia_1355778945289.png

Here's how we use Taxonomy Access Control to solve this problem.

说明: edia_1355777813695.png

说明: edia_1355777829342.png

  • You'll see a message saying, The content access permissions have been rebuilt.
  • Go to Configuration > Taxonomy Access Control.
  • You'll see that you have options for each user role. Click "edit access" rules next to anonymous user.

说明: edia_1355778312806.png

You'll now see the main Taxonomy Access Control page. Here's how to understand the page:

  • You add the tags on the left.
  • You look for the permissions across the top.

说明: edia_1355778345432.png

First, let's add the tags:

  • Under New, choose a tag.
  • Click Add.
  • Repeat until you've chosen all the tags that you want to control access for.

说明: edia_1355778451527.png

 

Now let's look across the top of the page:

说明: edia_1355778577251.png

Here are 5 new permissions that Drupal doesn't have by default:

  • View: can the user see nodes with this term?
  • Update: can the user edit node with this term?
  • Delete: can the user delete nodes with this term?
  • Add: can the user add this term to a node?
  • View: can the user see the term when looking at a node?

Now that we've seen both the left and the top of the page, we can start to apply permissions.

For each permssion, you choose the setting for each tag. Here's what the labels A, I, D mean:

  • A: people in this user role (in this case, anonymous) have this permission (in this case, View)
  • I: people in this user role have the same permissions as the default setting above
  • D: people in this user role do not have this permission.

So, if we the permissions as in the image below, anonymous users can view content tagged with Texas and Washington but they can't view content tagged with California or Georgia.

说明: edia_1355778552743.png

Look back up to the image at the start of this tutorial. Here's how that screen now appears to anonymous users.

 

说明: edia_1355779013696.png

  

Drupal 版本