天天看點

drupal7分類權限控制方法

在CMS網站中,我們常常需要給不同的角色配置設定不同的浏覽權限。在drupal7中,采用分類權限控制法就可以實作此功能。比如:我們設定了“分公司上司”、“分公司中層”、和“分公司員工”等角色,在分類詞彙“分享對象”中設定“分公司上司”、“分公司中層”、“分公司員工”等。如果我們希望角色“分公司上司”可以浏覽上述全部内容,角色“分公司中層”可以浏覽“分公司中層”和“分公司員工”分類的内容,角色“分公司員工”隻能浏覽“分公司員工”分類的内容。下面介紹具體的實作方法。

1、安裝Taxonomy Access Control子產品并啟用。 2、點選配置》使用者》Taxonomy Access Control。

drupal7分類權限控制方法
drupal7分類權限控制方法

3、編輯匿名使用者和注冊使用者的角色權限。

drupal7分類權限控制方法

勾選Global下面的default選框,檢視、更新、删除選項都選“D”,Add Tag、View Tag 不勾選。儲存。

drupal7分類權限控制方法

4、設定“分公司上司”、“分公司中層”、“分公司員工”角色為可編輯狀态。

編輯“分公司上司”角色的權限:

drupal7分類權限控制方法

設定好分享對象“分公司上司”的相應權限後,再依次增加分享對象“分公司中層”和“分公司員工”并設定好相應的權限。

drupal7分類權限控制方法

至此,完成了角色“分公司上司”的分類通路授權。如果登入使用者的角色是“分公司上司”,那麼他就可以浏覽“分公司上司”、“分公司中層”、“分公司員工”三個分類下面的内容了。

其他角色的分類權限設定照此辦理。

5、應用案例

在新增文章時,選擇相應的分享對象,文章儲存後,會有分享對象的術語列示,點選可連結到相關分類的頁面清單。當然,對無權使用者,這個标簽和連結都是不可見的。假如使用者不屬于“分公司上司”角色,建立一篇文章,選擇“分享對象”為“分公司上司”:

drupal7分類權限控制方法

以使用者hyh登入。使用者hyh屬于“分公司上司”角色。那麼他可以看到這篇文章和相應的分類标簽:

drupal7分類權限控制方法

點選“分享對象”下的“分公司上司”連結,就可以浏覽“分公司上司”分類下的文章清單:

drupal7分類權限控制方法

現在以“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.
drupal7分類權限控制方法
Here's how we use Taxonomy Access Control to solve this problem.
  • Install and enable Taxonomy Access Control: http://drupal.org/project/taxonomy_access
drupal7分類權限控制方法
  • Install the Taxonomy Access Control module: http://drupal.org/project/taxonomy_access
  • Enable the module.
  • Click the Rebuild permissions button.
drupal7分類權限控制方法
  • 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.
drupal7分類權限控制方法
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.
drupal7分類權限控制方法
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.
drupal7分類權限控制方法
  Now let's look across the top of the page:
drupal7分類權限控制方法
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.
drupal7分類權限控制方法
Look back up to the image at the start of this tutorial. Here's how that screen now appears to anonymous users.
drupal7分類權限控制方法

繼續閱讀