Có thể giới hạn quyền Administrator không ?

Events happening in the community are now at Drupal community events on www.drupal.org.
phuong.phuong's picture

Chào các bạn, mình có 1 issue là muốn giới hạn quyền của Administrator (uid == 1). Hiện tại tất cả các module mình viết, nếu có menu/chức năng nào thì đều show ra khi login as Administrator.

Comments

Drupal 5 & 6 <?phpfunction

thehong's picture

Drupal 5 & 6

<?php
function user_access ($something) {
 
// ...

  // User #1 has all privileges:
 
if ($account->uid == 1) {
    return
TRUE;
  }

 
// ...
}
?>

Không có cách nào khác ngoài việc hack hàm user_access

--
Thế Hồng

Đừng dùng user_access

jcisio's picture

Đừng dùng user_access nữa. Xem lại menu system của D6.

--
www.thongtincongnghe.com
Trang tin điện tử về CNTT, Viễn thông, Điện tử...

Menu show ra liệu có quan

dom.killer's picture

Menu show ra liệu có quan trọng bằng việc vẫn có thể truy cập theo path trong menu đó?

Hì mình nói về D6.

jcisio's picture

Hì mình nói về D6. 2-in-1

--
www.thongtincongnghe.com
Trang tin điện tử về CNTT, Viễn thông, Điện tử...

Đung là phần truy cập

thehong's picture

Đung là phần truy cập trong Drupal 6 tiện lợi hơn Drupal 5 rất nhiều, thử coi blog_menu ():

<?php
function blog_menu() {
 
$items['blog'] = array(
   
'title' => 'Blogs',
   
'page callback' => 'blog_page_last',
   
'access arguments' => array('access content'),
   
'type' => MENU_SUGGESTED_ITEM,
   
'file' => 'blog.pages.inc',
  );
 
$items['blog/%user_uid_optional'] = array(
   
'title' => 'My blog',
   
'page callback' => 'blog_page_user',
   
'page arguments' => array(1),
   
'access callback' => 'blog_page_user_access',
   
'access arguments' => array(1),
   
'file' => 'blog.pages.inc',
  );
 
$items['blog/%user/feed'] = array(
   
'title' => 'Blogs',
   
'page callback' => 'blog_feed_user',
   
'page arguments' => array(1),
   
'access callback' => 'blog_page_user_access',
   
'access arguments' => array(1),
   
'type' => MENU_CALLBACK,
   
'file' => 'blog.pages.inc',
  );
 
$items['blog/feed'] = array(
   
'title' => 'Blogs',
   
'page callback' => 'blog_feed_last',
   
'access arguments' => array('access content'),
   
'type' => MENU_CALLBACK,
   
'file' => 'blog.pages.inc',
  );

  return
$items;
}
?>

Nghĩa là, không phải mỗi lần hook_menu được gọi, thì hàm ***access () đều được gọi (để ý, nó chỉ là một chuỗi); và hàm kiểm soát truy cập, không chỉ là user_access, ở đây, có thể là blog_page_user_access (), tham số có thể truyền vào vô tư lự.

--
Thế Hồng