Development for a Drupal 6 port of Admin Role

Pasqualle - January 6, 2008 - 07:02
Project:Admin Role
Version:5.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:closed
Description

improvements:
Try to find the admin role by name when enabling adminrole module, and admin role is not selected. (create role "admin" or "administrator", enable module, everithing is ok)
Message cleanup
phpdoc
menuitem permission changed to 'administer permissions'
settings page moved under user management
second menuitem removed
roles 'anonymous user' and 'authenticated user' can't be selected as admin role

partial bugfix:
bug: the permission update is not called when enabling the adminrole module, because the form_alter hook is not called for adminrole module, because the module is disabled at that moment when system_modules form is submitted

solution: hook_enable() is used also for setting the permissions for admin role
but some permissions are still not set when enabling other modules same time when enabling adminrole module
I can't find better hook to use

problem fix: resave the system_modules form or do not enable other modules same time when enabling adminrole module

test it before using it!!!

AttachmentSize
adminrole.module_.txt3.07 KB
adminrole.info_.txt177 bytes

#1

Pasqualle - January 6, 2008 - 07:02
Status:active» needs review

#2

deekayen - February 5, 2008 - 21:39
Status:needs review» needs work
  • Why did you re-write .info?
  • Don't t() in hook_menu() anymore.
  • "access arguments" should be plural, not singular
  • I created a role named administrator, then selected it at admin/user/adminrole, and when I loaded admin/user/permissions, anonymous had all the permissions.
  • Uploading whole files makes it really hard to see what changes you made from what's in CVS without doing a diff myself. You should follow http://drupal.org/patch/create

#3

Pasqualle - February 5, 2008 - 22:50
Status:needs work» needs review

I wrote it for drupal 6 not drupal 5. Your arguments does not stand under drupal 6..
Please test it with drupal6.

#4

deekayen - February 6, 2008 - 03:09
Status:needs review» needs work

If it helps, to reproduce:

  1. Fresh install of Drupal 6-rc3
  2. Enable adminrole
  3. Create administrator role
  4. Create test user (uid 2) and assign to administrator role
  5. Go to Administrator Role page and pick administrator
  6. Go to Permissions page and anonymous and administrator have all permissions

In addition to the previous list, in .info

version = "6.x-1.x-dev"
project = "adminrole"

is added by project.module during packaging and shouldn't be added as part of the module's source in CVS.

You can find the plural vs singular docs at http://drupal.org/node/109157 for access arguments.

The standard capitalization of menu links means the link to the config page should be "Administrator role" not "Administrator Role".

#5

Pasqualle - February 6, 2008 - 04:11
Status:needs work» needs review

Yes, you are right. I misunderstood you.

I think I addressed all your problems here, but I do not created a diff, sorry.
The main problem was the use of array_merge() function.

please test again

AttachmentSize
adminrole.module_2.txt 3.1 KB
adminrole.info_2.txt 109 bytes

#6

deekayen - February 6, 2008 - 17:01
Status:needs review» needs work

Much better.

I did some more in-depth testing this time. I put a bunch of modules in my install, then installed two that added more permissions to the permissions page. When I viewed the permissions page, only one of the new modules was auto-selected for the administrator role, the other was unchecked. I went back to enable more modules that added permission options and tried three more. On the permissions page, the one that was not enabled from before is now enabled, but the other new ones were not.

It appears, without looking at the code, that the permissions updater is only updating one at a time instead of fully looping through all the newly enabled modules. Whatever the cause, not all modules are being granted to the administrator role when I enable more than one at a time.

#7

Pasqualle - February 6, 2008 - 19:04
Status:needs work» needs review

thanks for the review

please change the code on line 63
from

  foreach (module_list(FALSE, FALSE, TRUE) as $module) {

to
  foreach (module_list(TRUE, FALSE, TRUE) as $module) {

that should fix the problem

#8

deekayen - February 7, 2008 - 19:12
Status:needs review» needs work

Here's a patch against HEAD (revision 1.3). I started to mark it ready to commit, but I think these lines need a bit more attention:

  unset($user_roles[DRUPAL_AUTHENTICATED_RID]);
  unset($user_roles[DRUPAL_ANONYMOUS_RID]);

That only prevents anon and auth from showing in the form, not from being submitted. I can imagine an intranet allowing anon or auth users to have the admin role.

First I ask, is preventing anon and auth users from having this role something that should be enforced in the first place? If so, I think it also needs to be in adminrole_admin_settings_validate() as a check with error message result. Either way, the patch needs work.

Thoughts?

AttachmentSize
adminrole-diff-2008-02-07-13-34-01.patch 5.97 KB

#9

Pasqualle - February 7, 2008 - 19:35

These roles are hard coded into drupal. They have some functionality associated to them. (Search for references in drupal source) Using any of them as an administrator role is not recommended.

Please explain how can you submit these values if they are not listed.

#10

tecto - February 7, 2008 - 20:08

at least the anonymous role should be moved into the validation function to prevent random visitors receiving admin rights.

#11

deekayen - February 7, 2008 - 21:53
Status:needs work» reviewed & tested by the community

This adds validate hook to check for anonymous and authenticated user submission attempts (against HEAD revision 1.3).

AttachmentSize
adminrole-diff-2008-02-07-16-43-18.patch 6.47 KB

#12

Pasqualle - February 7, 2008 - 22:12

but I don't understand how do you trigger this error message

if you need validation, then the adminrole_update_perms() function could do some validation..

#13

deekayen - February 7, 2008 - 22:41

Many of the functions of Drupal are self-documenting. adminrole_update_perms() is to update permissions so that's what it should do, hook_validate() is to validate form submissions. In the Drupal bootstrap process, setting an error at validate prevents hook_submit() from even being called. See also http://drupal.org/node/202756

#14

Pasqualle - February 8, 2008 - 00:14

I understand all this hook thing.
But tell me the reproduction steps to show the error message in your validation hook.

(I should not write short sentences, because people do not understand what I try to say..)

#15

Christefano - February 8, 2008 - 00:34

#209842 was marked a duplicate of this issue. In that issue I proposed changing the package for Admin Role from "User Access" to "Administration" so that it's listed with other modules. One objective reason to list Admin Role in "Administration" is simply because Admin Role one of the first modules I install on any site and find it more convenient to have it listed at the top.

That being said, I'm biased in favor of "Administration" since several of my modules list "Administration" in their info files, but other modules I know of that also do this are Admin RSS and Masquerade. In #209842 deekayen also lists Zimbra, Logwatcher, LDAP Integration, LDAP Provisioning, Front Page, Default filter and Abuse.

#16

deekayen - February 8, 2008 - 00:33

I don't need to reproduce it to know what it does and I know never to trust user input. For example, I didn't like any of the choices to show my relationship to http://advogato.org/proj/PHP-Nuke/, so I created a form of my own where the action was set to submit to advogato.org and it injected "Source" as my relationship instead of the standard form options at the bottom (None, Helper, Documenter, Contributor, Developer, and Lead Developer).

Granted, you'd already have to have administer permissions login to do the alternate post, but if you're going to block submission of anon and auth users, do it right.

#17

deekayen - February 8, 2008 - 00:38

#15, I removed the package in .info in my patch. I like to think the package definition is more suited for modules related to a larger module that accepts plugins like CCK, OG, or CAPTCHA.

#18

Christefano - February 8, 2008 - 00:40

Sounds good, thanks deekayen.

#19

Pasqualle - February 8, 2008 - 01:30

#16 ok, I understand. You created the validation for "bulletproof" blocking these roles. No more objections on using this validation hook, because I can't tell any example when this validation would cause a problem. But here is one example when something is over-validated and the validation hook is removed: #209584: Cannot set custom error pages to URL aliases.

really "bulletproof" validation would be changing

if ($admin_role == 0) {
   return;
}

if (in_array($admin_role, array(0, DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
   return;
}

in adminrole_update_perms()

but as I said I have no objection on your patch, I am fine with it..

#20

deekayen - February 8, 2008 - 14:21

I disagree on #19. The point is to prevent the form submission. If you also do it in the update function, you block other modules from using the update function as part of extending functionality.

#21

JacobSingh - February 14, 2008 - 08:56
Status:reviewed & tested by the community» needs review

Hey guys,

Sorry to be an absentee maintainer, and I appreciate all the work and argument!

I'm going to change this back to CNR until I get a clear indication that the current patch is the real one.

Also, see http://drupal.org/node/221124#comment-729552

This patch may need to be included as well... To be honest, I haven't been following the 6.x thread here other than being happy someone is taking up the mantle here.

When you guys push it back to RTBC, I'll do a review and pass it around a bit and then commit it.

Thanks again!

Jacob

#22

deekayen - February 15, 2008 - 19:52

Jacob, I'm leaving this as CNR because I think it needs a maintainer's intervention in decision making if you're going to want http://drupal.org/node/221124 included. One of the biggest differences is strings and I like mine.

I researched and included in this patch a less hacky way of doing the alternate settings submit handler. That specifically meant diverging from the code difference at the bottom of the other issue's patch to form_alter().

Patch against HEAD.

AttachmentSize
adminrole-diff-2008-02-15-14-50-30.patch 6.72 KB

#23

JacobSingh - April 14, 2008 - 19:04
Status:needs review» needs work

Hi Guys,

Thanks a lot for this. My life has been pretty hectic the past few months, and I'm getting involved again. If any of you wants to take up maint of this mod, I'd be happy to include you.

I looked over the patch and tested superficially. It doesn't seem to work for me.

Here's what I did:

Installed the mod
went to settings page
saved as "none", nothing happened - Good!
Added a role called "admin" , selected and saved, all perms given - good!
Went to permissions, unchecked something and submitted, when I came back, was still off (not good :( ).

I think the module is supposed to give all perms to that role, so unchecking shouldn't do anything. It might be a nice addition to remove that role from the listing on the page somehow (menu override?) and just display some text like "all perms automatically provided" so people don't get confused.

Let me know if you see something similar.

Btw, this is against the patch in #22, didn't check earlier ones.

#24

akahn - June 21, 2008 - 19:56
Title:6.x version» Development for a Drupal 6 port of Admin Role

Making the name clearer so that the duplicates don't keep popping up.

#25

sfranchi - June 22, 2008 - 15:00

Sorry, but I can't find the link for download the 6.x port in http://drupal.org/project/adminrole, where is it?

Thanks,

#26

deekayen - June 22, 2008 - 20:14

That's because there isn't one. It would at least be listed on http://drupal.org/node/128621/release if there was.

#27

sfranchi - June 24, 2008 - 00:04

Yes I know that, thanks, I'm not new in the neighborhood, but I did imagine a dev version of this module if it's being ported, not a couple of txt files for copy and pasting.

Thanks anyway.

#28

JacobSingh - June 25, 2008 - 12:15

Hey Guys,

I made a few updates to the DRUPAL-5 branch (probably the last ones coming).

Can someone re-roll the patch against that? I promise, I will review again and commit ASAP. Also, please note my comment about unchecking from the module page.

Best,
J

#29

darumaki - July 13, 2008 - 06:41

subscribing

#30

darumaki - July 15, 2008 - 15:27

The above module files when enabled allow anonymous roll all admin functions instead of the role created for that purpose, not sure why

#31

moshe weitzman - October 20, 2008 - 18:26
Status:needs work» fixed

D6 release exists now.

--project followup subject--

Anonymous (not verified) - November 3, 2008 - 18:29

Automatically closed -- issue fixed for two weeks with no activity.

#32

Anonymous (not verified) - November 3, 2008 - 18:42
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.