Just getting used to D7 and wanted to see about a Drupal 7 version of this module or equivalent ... it doesn't seem like a similar functionality is built into D7.

Assigned to 6.x-dev as there is no 7.x (yet?).

Comments

jarush’s picture

Any update of Menu_Per_Role for Drupal 7??
I'm using Drupal 7 now, and also want to use this module...
Hope it will come to Drupal 7 soon...

AlexisWilke’s picture

Whoever wants to take over the D7 version, let me know. 8-)

I don't have the time and we're not yet using D7.

Thank you.
Alexis Wilke

ken hawkins’s picture

Title: Drupal 7 version? » Coder needed for Drupal 7 version
Priority: Normal » Major

Changing title to reflect need of coder. Also setting status to major as I think we'll soon see an influx of those looking for a D7 version.

I'd be happy to help debug, test, etc, but my Drupal code skills just aren't there to port something like this.

jarush’s picture

Great!
I'd be happy to help debug & test also.

AdrianC-1’s picture

Subscribing

bigdave’s picture

subscribing

thekevinday’s picture

I really do not want to stretch myself thin, so I am trying to avoid picking up another project at them moment.
That said, I might be able to provide the initial coding and then leave the rest to the admins here.

Before I do that, however, you might want to also look at and consider this module: http://drupal.org/project/chain_menu_access.

It may/may not be a good to use the API that module provides for the drupal 7 version of this module.

AlexisWilke’s picture

thekevinday,

I can create the D7 version once you have a tarball ready.

Thank you.
Alexis Wilke

Anonymous’s picture

subscribing for D7

sapox’s picture

Subscribing.

Could be an option to try to port it to D7 using the coder module?

AlexisWilke’s picture

Coder module?! Would that really help in changing all the code? I think it only checks the validity of your code by trying to see whether there's bugs in there.

sapox’s picture

Sure, it'll do half of the job. Because it will help to port al the functions API's that are used from version 6 to 7, database calls, etc. Coder module will not do it by itself, but it'll show line by line where is something that must be changed.

Of course the other half can't be done this way, which includes the actual integration of the module with the rest of drupal. This part requires, more close knowledge of how this module works and how must be integrated with the new D7.

AlexisWilke’s picture

Menu per Role is a rather small module, so it should not be that bad.

From what I've seen of D7, the changes to the roles are non-existent.

However, the menu handling is completely transformed. So there could be a bit of work, not just API call because we had hooks, etc. that were D6 specific and it is not unlikely that in D7 you want to use a different approach. So that will take a little bit of thinking for the core of Menu per Role. The rest (i.e. admin forms) would certainly be easy to transform just with coder.

Thank you.
Alexis

kvanlombeek’s picture

Curious as well to test the updated D7 module

thekevinday’s picture

StatusFileSize
new8.87 KB

Sorry for the late submit, I am behind.

Here is a working D7 version, but much testing and review is needed.

There is only 1 outstanding problem that may/maynot be a core bug:

in includes/menu.inc, around line #3025 inside menu_link_save():

<?php
if (!$existing_item || (array_intersect_assoc($item, $existing_item)) != $existing_item) {
?>

In my case, that if case is failing to succeed even when (array_intersect_assoc($item, $existing_item)) != $existing_item is TRUE.
This could be a bug with my PHP version.

My work-around is adding:

<?php
$intersected = ((array_intersect_assoc($item, $existing_item)) != $existing_item) ? TRUE : FALSE;
?>

and replacing:

<?php
if (!$existing_item || (array_intersect_assoc($item, $existing_item)) != $existing_item) {
?>

with

<?php
if (!$existing_item || $intersected) {
?>

The problem seems to cause the hook_menu_link_update() to not fire and therefore updating a menu link will not do anything.
Please let me know if anyone comes across this issue and what PHP version they are using.
I am using PHP 5.3.2.

AlexisWilke’s picture

Hi thekevinday,

Okay, I tested and #15 package works for me.

Note that I made some changes in the D6 version so the users can decide whether UID=1 and menu administrators can see or not the hidden menus. I thought later I could have used another permission and a per user flag instead of just a couple flags as it is now. But it serves the purpose for this simple module. It most certainly will be asked for you to do the same in D7.

One thing that is definitively missing is an upgrade route. You must reformat the old D6 data from my explode() to your serialize(). I used explode() because it is a lot faster, although I don't mind it being done either way, yet this means you need an upgrade path...

Thank you.
Alexis Wilke

thekevinday’s picture

StatusFileSize
new8.97 KB

Well then lets keep life simple and stick with your higher-performance "explode" approach.

I moved the explode/implode operations into two functions so that if this were to be changed in the future, there is only one spot to change.

For those of you who tested #15, it is best to uninstall that version and re-install this version of the proposed D7 menu_per_role.

This one should not need an upgrade path.

ronino’s picture

Is there a D7 dev version, so installing and testing is much easier? So far I only see different separate packages. I'd very much like to use this module in D7...

AlexisWilke’s picture

Ronino,

That's the way it is generally done when we move from one major version to another, unless the author does the move him/herself.

I suggest you test the version in #17 and report your results (i.e. working/not working)

Thank you.
Alexis

SMonsen’s picture

Subscribing

simg’s picture

seems to work fine for me (thanks !!!)

only issue that I've found is that the admin user (ie uid = 1) gets to see all menu items regardless of settings - this may be by design?

AlexisWilke’s picture

simg,

Yes. uid = 1 "problem" is by design. Although now there is a flag in the settings in D6.

Thank you for the report.
Alexis Wilke

clashar’s picture

+1

Joe90’s picture

Thanks for the 7.x version from #17. It worked for me, but I did have problems changing the settings. Eventually had to reset "Blogs" which was the menu item I was working on, and even then the settings didn't go away but was then allowed to save changes. Possibly a cache issue? Also note when un-gzipping, edit out the last _ after the tar before doing so!

AlexisWilke’s picture

Joe90,

When you say "settings", I suppose you mean the flags appearing in the Menu fieldset?

There was a problem like that in D6 that I fixed recently and it is not unlikely that the D7 presented here used the previous version of Menu per role, so we'd have to port the fixes. If my assumption is correct, it will not save anything when you create a new node. After that, editing works just fine.

Thank you.
Alexis

Joe90’s picture

OK thanks Alexis.

Should I be able to type in a url that is covered by menu per role and see it without being logged in, as I can.

Example:

Blogs is "protected" for the role "Staff" to only view. So "Blogs" does not show in the navigation menu when not logged in but shows when logged in. Good :). However if I type in the url of a blog post when not logged (http://example.com/node/22) in I can see it. Not good :(. Is this by design or have I missed something?

AlexisWilke’s picture

Joe90,

You missed something. We clearly say that the destination is not in any way affected. In other words it doesn't get protected just because you hide the menu. To do so, you want to use another module that protects nodes. There are many such modules to choose from. tac_lite is a bit complicated, it protects using taxonomy terms but you can use rules to automatically assign terms to your nodes.

Anyway, a list of such is presented in the Menu per Role project page.

http://drupal.org/project/menu_per_role

Thank you.
Alexis Wilke

Joe90’s picture

Thanks Alexis, I kind of figured this out, after I had walked away and thought about it ;) Have had some success with taxonomy elsewhere on my site so will give it a go, unless I decide to give Views a crack :)

simg’s picture

I've noticed the same problem as joe90 on #24.
not sure about it being a new node (this was a link to a forum) but the role permissions flags weren't being saved. clicking reset on the forum link made it start working fine.

simg’s picture

also just found with a menu link created from node/add that the roles weren't saving.
there is no "reset" link, but disabling then re-enabling the link made it work correctly.

AlexisWilke’s picture

simg,

There was a problem in D6 saving a new menu item. It was fixed in D6, but it could be that D7 was created before D6 and the fix did not make it in D7. Core is expected to call module hooks to ensure such things don't happen... If that's the case, then we'll need to emit a patch for Core, unfortunately.

Thank you.
Alexis

simg’s picture

Alexis,

No, thank *you* :)

ps: I would also say I think the "by design" issue I mentioned in #21 is a design bug. I can (almost) see an argument for having uid =1 see all menu items but the code currently allows anyone with "Administer menu per role" permission to see all menu items.

I could be missing something, but most times, I want to hide menu items from a role (or an administrator) for their "convenience" not really for "security" purposes.

Would happily submit a patch if would be included into the module :)?

Cheers

Simon.

AlexisWilke’s picture

There is a "fix" in D6, a new administrative page which let you select whether UID = 1 and administrators should see the menus or not (there are 2 flags)

I guess I'd be more interested in having a fix for the 2 save problems.

simg’s picture

Hey, thanks Alexis will wait for the extra D6 flag to make it into D7.

Would offer to look at the "saves" issue but currently flat out on two D7 projects. Might come back to this issue in a couple of weeks if it hasn't already been solved.

thekevinday’s picture

D7 does not need to care about whether or not UID = 1 has the appropriate roles.
UID = 1 in D7 bypasses all permissions, so this is not a problem. (or is something that cannot be changed??)

All other administrators would have to be in a role that enables the "Administer menu per role" permissions.

AlexisWilke’s picture

thekevinday,

UID = 1 sees everything in D6 too... except the Log In menu item once logged in. So to be consistent, it makes sense to hide some other menus to UID = 1 too.

And for the administrators, unless we put yet another permission, it makes sense to eventually hide the menus from them otherwise they cannot directly see the result and they are the only ones who can modify those menu per role flags.

Thank you.
Alexis

geert’s picture

Hello,
The version #17 did not work for me
----------------------------------------------------
* Notice: Undefined index: log in update_authorize_install_batch_finished() (line 236 of C:\xampp\htdocs\drupal7\modules\update\update.authorize.inc).
* Warning: Invalid argument supplied for foreach() in update_authorize_install_batch_finished() (line 236 of C:\xampp\htdocs\drupal7\modules\update\update.authorize.inc).
* Notice: Undefined index: log in update_authorize_install_batch_finished() (line 277 of C:\xampp\htdocs\drupal7\modules\update\update.authorize.inc).
* Notice: Undefined index: tasks in update_authorize_install_batch_finished() (line 278 of C:\xampp\htdocs\drupal7\modules\update\update.authorize.inc).
* Installation failed! See the log below for more information.
---------------------------------------------------

I removed all from the system and tried #15. So far, this works ok for me and does what I expect it to do: hide the menu item, role based.

Geert

joelstein’s picture

The module attached in #17 worked great for me. Note: I was not upgrading... just installing fresh. Thanks!

shadowdknight’s picture

Hi,
Im using version on #17,
It seems I have problem updating the menu for selected roles,
after changing the role the changes is not saved.

Thanks

AlexisWilke’s picture

shadowhitman,

Is that when creating a new page, or even when editing a page?

Thank you.
Alexis

shadowdknight’s picture

Hi,
Excuse me for lack of info, I had a site with 3 roles : editor , manager and admin:
1.I created Menu called "Testing" :
Under "Hide menu item for selected roles", I checked : Anonymous, Editor and Manager
Save
2.I wanted to change my setting and allow Manager to access that menu:
I unchecked Manager from the list of "Hide menu item for selected roles"
Save

But when I reload, the menu is still invisible for Manager role,
and when I went back to check the settings still the same : Manager is still checked on the list of of "Hide menu item for selected roles"

AlexisWilke’s picture

Ah! So the flags did stick, it's the functionality that isn't working...

As a manager, can you go to that page? If not, then the Core system is hiding that menu, not Menu per Role.

Thank you.
Alexis

devtherock’s picture

StatusFileSize
new10.18 KB

Hi All

I download and install #17 but I was unable to alter roles once selected, so I made changes on menu_per_role.module file call "menu_per_role_menu_link_update" function inside "menu_per_role_menu_link_alter" now it is saving multiple roles. Attached the changed code. I hope I solve it in a right way, comments and feedback are welcomed.

Thanks

Regards
Dev/Kuldev

likewhoa’s picture

Title: Coder needed for Drupal 7 version » Port menu per role to Drupal 7
Category: support » task

Subscribing

nfriend’s picture

#43 works like a charm for me. New D7 install. So glad to see this here as I got very used to it in D6! Thanks!

Neil

hermes14’s picture

This is my scenario:
User menu, that contains User account and Logout items. I'm adding a 'Reserved area' item, that should only show up whenever a user is not logged in (i.e. anonymous role), but when I log in as administrator it actually shows always up. This doesn't happen with other roles I created, i.e. it correctly hides the item whenever I log in. I tried to deny access to logged user and administrator, besides allowing only to anonymous but it's always there...
Am I missing something?

nfriend’s picture

@hermes14
If by Administrator you mean User 1, I believe this Admin gets to see the whole show - that's a perk for being admin! Typically that's only going to be a developer and the like. Create another role with most of the permissions you want but is not an admin and use that to eliminate that menu from showing.
Neil

hermes14’s picture

That's what I meant, but I find it a bit confusing to have administrator listed in "Hide menu item from selected roles" and cannot actually hide the selected item.

modoq’s picture

subscribing

underwearninja’s picture

I installed along side version 7.x-2.x-dev of Simple Access (http://drupal.org/project/simple_access) hoping I could enable menus even though Simple Access hides the menus. It didn't work as I expected.

It does work as advertised though, it just doesn't play with SA as I would have desired. If someone knows of a way to protect the content, yet still show it in a menu, that'd be great!

AlexisWilke’s picture

underwearninja,

Yes, you have to edit the menu link and enter a full path that starts with http://... then the menu system treats it as an external link and does not hide it if the destination is not reachable.

Obviously, if someone then goes to that page, he/she will get an access denied error (at least, that's what's expected by default.)

Thank you.
Alexis

bkudrle’s picture

Code from #43 worked well for me also. Am only using it to allow access for roles, not deny access to roles. Thanks so much for the good work.

laroccadahouse’s picture

fresh install of d7 + file from #43. created a test menu. when i go to edit the menu, there is no fieldset for setting what roles can access.

AlexisWilke’s picture

laroccadahouse,

Are you testing as UID 1? If not, you may need to check out permissions...

Thank you.
Alexis

laroccadahouse’s picture

yes i was logged in as UID1. i eventually gave up and installed this module: http://drupal.org/project/menu_admin_per_menu

AlexisWilke’s picture

laroccadahouse,

That looks like a cool module and much better adapted to what you were trying to do.

Thank you.
Alexis

OldAccount’s picture

#43 is working for me, thank you!

AlexisWilke’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Fixed

I now created a new version 7.x-1.x-dev.

Note that I'm not supporting it, so if you have problems, you may have to find someone to fix it.

Thank you.
Alexis Wilke

See: http://drupal.org/node/1189878

Status: Fixed » Closed (fixed)

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

heymjo’s picture

works like a charm on D7.8, many thanks !

benjamin69’s picture

Component: Code » Miscellaneous
Assigned: Unassigned » benjamin69
Priority: Major » Normal

Hello,

Thank you for this module he works very well !
it really does what i want for my sidemenu.

AlexisWilke’s picture

Assigned: benjamin69 » Unassigned

You shouldn't change post settings on closed issues unless you are re-opening it.

Thank you.
Alexis