Permission names like:

1. "Administrative Settings"
2. "edit entries"
3. "view entry list"

are not so good names. Change them to be more gotwo specific, please. Have a look how other modules are doing...

Some much better examples:
1. "administer gotwo"
2. "edit gotwo entries"
3. "view gotwo list"

this names will not have side effects on other modules. if someone else using the same unspecific names like above, this will result in user permissions that a user couldn't get. I have never seen a module using mixed case permission names.

CommentFileSizeAuthor
#7 gotwo.141677_0.patch4.13 KBspiderman
#3 gotwo.141677.patch3.14 KBspiderman

Comments

BioALIEN’s picture

Valid suggestion, +1

BioALIEN’s picture

Priority: Normal » Minor

"administer gotwo" = DONE!

The remainder still require work but it's a *minor* problem.

spiderman’s picture

Title: user_access: to general » user_access: permissions too general
Status: Active » Needs review
StatusFileSize
new3.14 KB

attached is a quick patch i just rolled, since i'm on a roll with this module today anyway ;)

i believe it covers all the cases of these perms getting used, and also adds a definition for the 'administer gotwo' perm in the _perm hook. seems to be working on my test site, but please review for correctness & completeness ;)

spiderman’s picture

Assigned: Unassigned » spiderman

volunteering to follow this one through

hass’s picture

Should we build in an automated upgrade path from old names to new names via .install file?

spiderman’s picture

@hass: good idea- how about something like this (off the top of my head, totally untested):

Index: gotwo.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gotwo/gotwo.install,v
retrieving revision 1.1
diff -u -p -r1.1 gotwo.install
--- gotwo.install       4 Jul 2006 18:55:59 -0000       1.1
+++ gotwo.install       30 Oct 2007 03:50:04 -0000
@@ -32,3 +32,20 @@ function gotwo_install() {
       break;
    }
 }
+
+# update the permissions table, to reflect changes to hook_perm
+function gotwo_update_5100() {
+  $res = db_query("SELECT rid,perm FROM {permission}");
+  $perms = array();
+  while ($p = db_fetch_object($res)) {
+    $perm = $p->perm;
+    $perm = preg_replace('/Administrative Settings/', 'administer gotwo', $perm);
+    $perm = preg_replace('/view entry list/', 'view gotwo entry list', $perm);
+    $perm = preg_replace('/edit entries/', 'edit gotwo entries',  $perm);
+    $perms[$p->rid] = $perm;
+  }
+
+  foreach (array_keys($perms) as $rid) {
+    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $perms[$rid], $rid);
+  }
+}

i'll re-roll this patch tomorrow and test the update process on my test site :)

spiderman’s picture

StatusFileSize
new4.13 KB

here's a new patch which includes a hook_update_N implementation in the .install file, and works great on my test site. i should note that the old "Administrative Settings" perm wasn't actually being set by hook_perm, so the first preg_replace in this function may only apply to very old installations of this module..

spiderman’s picture

Status: Needs review » Fixed

i've gone ahead and committed this patch, since it seems to be working fine, and i'm eager to move onto other things :)

the latest module code is here

Anonymous’s picture

Status: Fixed » Closed (fixed)

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