Friday, August 17, 2007

Setting group permissions in JCalPro

For a client of mine, I tried to change the permissions of JCalPro, the calendar extension for Joomla!. It turned out to be easy, but not after quite a long search. This is how I managed to do it in the end.

This client uses Joomla! with the JACLPlus extension to manage several usergroups. What they wanted was pretty straightforward: a calendar that everyone can see, but only users of one particular usergroup can add events to.

JCalPro was the calendar of choice. Now, this calendar has settings for exactly what we wanted: which usergroup can add, edit, delete or approve events. But... this works for the default Joomla! groups only, not for the JACLPlus groups my client uses.

So, after some wading through the code I discovered that JCalPro calls the function $acl->check_acl() to see what permissions a certain user has. It calls this function with the following parameters (see components\com_jcalpro\include\functions.inc.php):

$acl->acl_check( 'content', $action, 'users', $my->usertype, 'calendar', 'all' )

I debugged and found that in my particular case, the value of $my->usertype was 'Members'.

I never really looked into the acl system before and since I couldn't add the desired record in the jos_jaclplus table via the JACLPlus User Group Manager, I added the following record to the database manually (feeling quite awkward adding something to the database this way, but still, I just tried it on my test system anyway... ):

INSERT INTO `jos_jaclplus` ( `id` , `aco_section` , `aco_value` , `aro_section` , `aro_value` , `axo_section` , `axo_value` , `enable` )
VALUES (NULL , 'content', 'add', 'users', 'members', 'calendar', 'all', '0');

What happened? Nothing! That is, everything stayed the same, as if I hadn't added the record.

My first thought was that it had to do with the uppercase M of the usertype 'Members'. But, changing the record had no effect.

After some more code-wading, I stumbled over a very usefull file:
components\com_jcalpro\config.inc.php

This happened to include calls to add records to the jaclplus or acl tables in a sort of temporary way.

I added some calls to this file for my members group:

setRights ( 'add', 'calendar', 'members' );
setRights ( 'edit', 'calendar', 'members' );
setRights ( 'approve', 'calendar', 'members' );

and... tadaa... there it was: all users of my members group could add, edit and approve calendar events.

Since this was an easy, but very hidden kind of solution, I wrote it down here. For others to be usefull for, or for others to comment on. Feel free to leave your comment if you have a much better or simpler way to do this!

No comments: