Thanks for your module! I very much liked it, and have extended it a bit, with another module, which will give the users editing permissions, if they have the subtree permission. This allows one to delegate subtrees of the website to specific roles. I am attaching it here in case anybody wants to use it.
Waldemar
menu_stna.info
; $Id: menu_stna.info 1 21 Sep 2007 13:42:24Z schlacko $
name = Menu Subtree Nodeaccess
description = Inherit the node access permissions from the subtree permissions
package = Other
dependencies = menu_stp
; Information added by drupal.org packaging script on 2007-07-24
version = "5.x-0.x-dev"
menu_stna.module
<?php
/*
* $Id: menu_stp_nodeaccess.module 1 21 Sep 2007 13:42:24Z schlacko $
*
* menu_stp_nodeaccess.module
* Copyright (C) 2000-2007 Waldemar Schlackow
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* @version $Revision: 1 $ $LastChangedDate: 21 Sep 2007 13:42:24 $
* @package menu_stna
* @author Waldemar Schlackow <waldemar@opencodes.org>
*/
/**
* Implementation of hook_enable().
*
* A node access module needs to force a rebuild of the node access table
* when it is enabled to ensure that things are set up.
*/
function menu_stna_enable() {
node_access_rebuild();
}
/**
* Implementation of hook_disable().
*
* A node access module needs to force a rebuild of the node access table
* when it is disabled to ensure that its entries are removed from the table.
*/
function menu_stna_disable() {
menu_stna_disabling(TRUE);
node_access_rebuild();
}
/**
* Simple function to make sure we don't respond with grants when disabling
* ourselves.
*/
function menu_stna_disabling($set = NULL) {
static $disabling = false;
if ($set !== NULL) {
$disabling = $set;
}
return $disabling;
}
/**
* Implementation of hook_node_grants().
*
* Tell the node access system what GIDs the user belongs to for each realm.
* In this example, we are providing two realms: the example realm, which
* has just one group id (1) and the user is either a member or not depending
* upon the operation and the access permission set.
*
* We are also setting up a realm for the node author, though, to give it
* special privileges. That has 1 GID for every UID, and each user is
* automatically a member of the group where GID == UID.
*
*/
function menu_stna_node_grants($user, $op) {
switch ($op) {
case 'view' :
$grants['menu_stna'][] = 0;
break;
case 'update' :
case 'delete' :
$rids = _menu_stp_user_roles();
if (!$rids)
return;
$mids = _menu_stp_editable_mids_by_roles($rids);
$grants['menu_stna'] = array_keys($mids);
}
return $grants;
}
/**
* Implementation of hook_node_access_records().
*
* All node access modules must implement this hook. If the module is
* interested in the privacy of the node passed in, return a list
* of node access values for each grant ID we offer. Since this
* example module only offers 1 grant ID, we will only ever be
* returning one record.
*/
function menu_stna_node_access_records($node) {
if (menu_stna_disabling()) {
return;
}
$mid = _menu_get_node_mid($node);
if ($mid) {
$grants[] = array (
'realm' => 'menu_stna',
'gid' => $mid,
'grant_view' => TRUE,
'grant_update' => TRUE,
'grant_delete' => TRUE,
'priority' => 0
);
$grants[] = array (
'realm' => 'menu_stna',
'gid' => 0,
'grant_view' => TRUE,
'grant_update' => FALSE,
'grant_delete' => FALSE,
'priority' => 0
);
return $grants;
}
}
function _menu_get_node_mid($node) {
if ($node) {
$result = db_query("SELECT mid FROM {menu} WHERE path = '%s'", "node/{$node->nid}");
$menu = db_fetch_object($result);
return $menu->mid;
}
}
?>
Comments
Comment #1
TripleEmcoder commentedWill this work in 6.x? Are there any modules for 6.x offering such funtionality? I would like to delegate editing content placed under menu subtrees to users/roles.
Comment #2
avpadernoI am closing this issue, as Drupal 5 is now not supported.