[drupal-devel] [feature] Block access by role patch (attached)

kbahey drupal-devel at drupal.org
Sun Feb 27 03:47:36 UTC 2005

 Project:      Drupal
 Version:      cvs
 Component:    block.module
 Category:     feature requests
 Priority:     normal
 Assigned to:  Anonymous
 Reported by:  flexer
 Updated by:   kbahey
 Status:       patch

I agree that this functionality is needed in one form or another. I will
leave others who need this functionality to try it out and comment on
Perhaps it is best that the access by role thing should be unified,
instead of having one for nodes and another for blocks, and each with
its own set of tables.
You are doing just GREAT for someone who has submitted their first
patch to Drupal. You provided an overview for developers, another for
users, security risks, description of files included, performance
impact, ...etc. That is way more than 99% of other new contributors do.
So, good work and keep it up. Looking forward to more contributions.


Previous comments:

February 26, 2005 - 18:36 : flexer

Attachment: http://drupal.org/files/issues/block_access_by_role.tar.gz (2.54 KB)

This is my patch(es) to add support for a per-role basis blocks
How it works (user):
block administrators can select which role(s) could access every block,
via the configure block setting. In the same way one could "Restrict
block to specific content types", now can "Show block to specific
roles". Selecting one or more roles will cause the block to only be
shown if the current user belongs to one of the selected roles. If no
role is selected, the block is showed to everyone. Selecting all roles
or selecting none, has the same effect. Note that Administrator (user
1) is never affected by this restriction.
How it works (developer):
I have added a new table to the system (block_access). It contains the
module, delta and role for each defined block. Permission check is made
in the "list" hook of the block module. A patch is given also for the
*user.module*: when a role is deleted, we need to delete the specific
records in block_access.
Why this is useful:
I use the menu.module very much, so I wondering why there was no way to
create menu (as blocks) with content visible only to certain roles. So,
my patch prevent the menu blocks to be displayed only for certain
roles. I have also create, with this patch, an admin block that say
"Register now ! Blah blah...", visibile only to anonymous users.
Security issues:
None that I could be awaew of...
Performace issues:
Every time a block_list is called, an additional database query is
What the file contains:
The attached file contains:

the block.module patch *block.module.patch*
the user.module patch *user.module.patch*
the MySQL DDL for block_access *block_access.mysql.sql*
the PostgreSQL DDL for block_access *block_access.pgsql.sql*

What to worry about

This is my first contribution to Drupal 
English is not my first language :)


February 26, 2005 - 20:12 : flexer

/"I have also create, with this patch, an admin block that say "Register
now ! Blah blah..."/ " should be read:
/"For example, I have created, THANKS TO this patch, an admin block
that say "Register now ! Blah blah...""/

View: http://drupal.org/node/18018
Edit: http://drupal.org/project/comments/add/18018

More information about the drupal-devel mailing list