Joomla 2.5.6: Set permission for each Module

Moderators: mandville, PhilD, General Support Moderators

Locked
webspot
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Mon Aug 13, 2012 9:36 am

Joomla 2.5.6: Set permission for each Module

Post by webspot » Wed Sep 05, 2012 12:22 pm

Hi how could I set ACL permission for each module in Joomla 2.5.6? likewise for Categories, Components

User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Joomla 2.5.6: Set permission for each Module

Post by rcarey » Wed Sep 05, 2012 2:05 pm

I've yet to see permissions on a module, menu item, or plugin. I don't see why a developer could not code permissions into a module, but these would probably be a different type of permissions than what we use for components, and that idea leads into a whole new area of discussion.

Modules, menu items, and plugins do require an access level. This makes sense as the "access level" refers to whether or not the user should have access/view to this item. Perhaps what you really want for a module is an access level and not a set of permissions that determine if a person can create, edit, publish, delete. Those types of permissions belong on the content itself (component, category, item/article) whereas the module is typically a placeholder that formats and displays this content.

Keep in mind that you can create your own access levels with each declaring a different set of groups. If the only "permission" you want to set for a module is whether or not someone can view it on the site, then the access level is what you want.

If what you want is a permission to edit module settings in the backend, the best you can do is to set the permissions on the module manager. That bestows the rights to edit any module, but it does not provide per-module permissions.

As for setting permissions on a component or category... Simply go to the admin edit screen for that component or category, and look for a link that is typically labeled "options." This usually lead to the permissions section. Not all components include permissions, and aside from Articles, many/most components do not include per-category permissions on their categories.
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

webspot
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Mon Aug 13, 2012 9:36 am

Re: Joomla 2.5.6: Set permission for each Module

Post by webspot » Thu Sep 06, 2012 6:35 am

Make sense but why I need it because I downloaded JCount from http://extensions.joomla.org/extensions ... down/14989 but I want to set permission to use it only for Super Admin & a User Group. If I set permission on Modules for User Group then this group could also manage other Modules which I do not want.

User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Joomla 2.5.6: Set permission for each Module

Post by rcarey » Thu Sep 06, 2012 6:03 pm

The current ACL provides the ability for modules to add permissions that would allow what you want, but I know of no developer who is implementing permissions per module. I do have a suggested solution for you ...

First, I'd create a group that inherits from public and that provides permissions to login to the backend and to edit modules. Then, assign to this group only the person(s) who need to access this module. Add this group to the access level Special so members of this group can see the admin menu. At this point, you have created a role I call "module manager." It grants only the permissions that are needed to edit modules - albeit any module.

Second, find a way to show the user only the module(s) that this group needs to edit. There are a few ways to do this, and I show one below. Further, this approach is meant for keeping honest people honest, as a person who knows Joomla well enough can find ways to access other modules through the backend. But most users (and honest users) will just use the links you provide and will not try to access areas that require clever insight.

Here is a technique that will do what you want.... Override the view file that displays the list of modules.
take this file:

Code: Select all

/administrator/components/com_modules/views/modules/tmpl/default.php
and copy to this location (choosing the folder that corresponds to your admin template)

Code: Select all

/administrator/tempates/<your admin template>/html/com_modules/modules/default.html
You will need to create the latter two directories (com_modules/modules).
Then edit this second/copied file (to override the first file)...

Around line 111 is the foreach code that pulls up and lists each admin module. A few lines down and at the end of the php section (say, line 118), add the logic that evaluates if the user belongs to this group and if so, then show only the modules you want to show. Here is some sample code using id values that I'm just pulling out of the air, but you would need to supply specific id values.

Code: Select all

    $groups = $user->get('groups'); // get an array of the groups the user belongs to
    if(in_array(13,$groups)){ // if the special user group is in the array of the user's groups...
        if($item->id != 92) continue;  // if the module is not the target module, skip and get the next
    }
This code assume the id of the special module group is 13, and the id of the module you want to show is 92. If you want to show additional modules, just adjust the condition with the needed logic. I just tested this code, so it should work.

One more point about this code, anyone who belongs to this special group will see the limited list of modules - even if they are also a super admin.
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

142
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Wed Jan 30, 2013 11:45 am

Re: Joomla 2.5.6: Set permission for each Module

Post by 142 » Wed Jan 30, 2013 11:53 am

Hi !

Thank you very much for your example, it is exactly what I was looking for and it works great to show one module.

My problem is that I want to show 2 modules. I tried to adjust the condition with the needed logic for 2 modules ID like you said, but it nevers works.

Could you help me and show me how to adapt this logic to 2 modules ID, please ?

Thank you very much !

User avatar
rcarey
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Sat Apr 25, 2009 9:20 pm
Location: Minnesota (USA)
Contact:

Re: Joomla 2.5.6: Set permission for each Module

Post by rcarey » Wed Jan 30, 2013 3:27 pm

If you understand php code, this is a relatively simple variation.

Items are skipped when continue is called, and continue is called when the condition ($item->id != 92) is true. All you have to do is add additional evaluations within that conditional expression so that if we find a target id (the module you want to display), the whole expression is false.

single item

Code: Select all

($item->id != 92)
two items

Code: Select all

($item->id != 92 && $item->id != 42)
three items

Code: Select all

($item->id != 92 && $item->id != 42 && $item->id != 137)
By using && to connect each evaluation, the whole expression is true only if the current item's id is not any of those listed. And if the expression is true, then continue stops processing the current item and execution continues to the next item in the list.
Randy Carey, the iCue Project http://iCueProject.com : developing an intelligent approach to improving the CMS user experience,
Careytech Studios http://careytech.com custom development for tailored or value-added web solutions

fbrooks
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Tue May 28, 2013 12:09 am

Re: Joomla 2.5.6: Set permission for each Module

Post by fbrooks » Tue May 28, 2013 12:13 am

rcarey THANK YOU!!!!!!

For days I have been looking for this, spent countless hours trying workarounds and extensions.

I knew that there was a place to put in the code but I wasn't sure where and I was actually making it more complicated in my head.

Thank you so much for taking the time to make your post and enlightening me.

Cheers

FrankB


Locked

Return to “Access Control List (ACL) in Joomla! 2.5”