Results 1 to 6 of 6

Thread: hasAccess function

  1. #1

    Default 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?

  2. #2

    Default 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?

  3. #3
    User Toflar's Avatar
    Join Date
    06-19-09.
    Location
    Lyss, Switzerland
    Posts
    170

    Default 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
    Regards

    Yanick - Contao core developer @terminal42 gmbh

  4. #4

    Default 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

  5. #5
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default 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:ublished (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...

  6. #6

    Default Re: hasAccess function

    Thankx!!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •