-
hasAccess function
Hi,
I am trying to use the following function:
$this->User->hasAccess('xlsexport', 'boek_acc');
Ive cretaed a field 'boek_acc' in the BE for tl_user and the same field for tl_user_group
When setting security settings on user level (xlsexport=checked), the above is working, but when putting the user in a group and setting xlsexport=checked on group level. The above function is not working.
Im I correct to say that hasAccess only contains user level access settings and not group level settings?
-
Re: hasAccess function
Strange,
I've found that I had to add in User.php inside the function setUserFromDb:
//HOOK: add zsnowflake permissions
if (in_array('zsnowflake', $this->Config->getActiveModules()))
{
$depends[] = 'boekingen';
$depends[] = 'boek_acc';
}
Can this be done with a hook instead of changing the core code?
-
Re: hasAccess function
User::hasAccess() is for the current user only, yes.
You can get the User's usergroups and check it manually:
Code:
$this->User->groups
or write an intelligent method and ask Leo (http://dev.contao.org) to add it to the framework? :)
The second post I can't answer because I don't know what you're trying to do but a core hack is 99.9% the wrong way ;)
-
Re: hasAccess function
Thx for the reply;
I've added the request to add a hook so that permissions can be set on group level:
http://dev.contao.org/issues/2159
Rgds,
Frederick
-
Re: hasAccess function
The hasAccess function simply checks if a field provided as parameter 2, contains the value provided in parameter 1.
You can apply this (as the News, Events) in the following way.
Note, that in both cases a field was added (extended) to BOTH tl_user and tl_user_group for gallery permissions. The statement below will check if the checkbox create has been checked for gallery permissions (galleryp).
Code:
if (!$this->User->hasAccess('create', 'galleryp'))
The second way to use it would be to validate if a user has access to a field or not. The example below checks that the alexf (access field permissions matrix) contains a parameter tl_gallery::published (the published field in the tl_gallery table).
Code:
if (!$this->User->hasAccess('tl_gallery::published', 'alexf'))
The hook you needed, was already there, just add your fields to the $GLOBALS['TL_PERMISSIONS'][] array...
-
Re: hasAccess function