Project

General

Profile

Actions

Feature #89983

open

Allow comma separated list of roles in f:security.ifHasRole

Added by Dieter Porth over 4 years ago. Updated about 4 years ago.

Status:
Accepted
Priority:
Should have
Assignee:
-
Category:
-
Start date:
2019-12-18
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

Instead of


 protected static function evaluateCondition($arguments = null)
    {
        $role = $arguments['role'];
        /** @var UserAspect $userAspect */
        $userAspect = GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user');
        if (!$userAspect->isLoggedIn()) {
            return false;
        }
        if (is_numeric($role)) {
            $groupIds = $userAspect->getGroupIds();
            return in_array((int)$role, $groupIds, true);
        }
        return in_array($role, $userAspect->getGroupNames(), true);
    }

use
// Code ist not tested.
 protected static function evaluateCondition($arguments = null)
    {
        $role = $arguments['role'];
        /** @var UserAspect $userAspect */
        $userAspect = GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user');
        if (!$userAspect->isLoggedIn()) {
            return false;
        }
        if (is_numeric($role)) {
            $groupIds = $userAspect->getGroupIds();
            $roles = array_filter( array_map('intval',explode(',',$role)));
            return ((array_sect(($roles, $groupIds) >0);
        }
        $roles = array_filter( array_map('trim',explode(',',$role)));
        return (array_sect($roles, $userAspect->getGroupNames())>0);
    }

Actions #1

Updated by Bastian Bringenberg over 4 years ago

  • Project changed from 9 to TYPO3 Core

Moved right Project.

Actions #2

Updated by Dieter Porth over 4 years ago

Better (Tested for list of Ints)

    protected static function evaluateCondition($arguments = null)
    {
        $role = $arguments['role'];
        /** @var UserAspect $userAspect */
        $userAspect = GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user');
        if (!$userAspect->isLoggedIn()) {
            return false;
        }
        if ((int)trim($role) >0) {
            $groupIds = array_filter( array_map('intval',$userAspect->getGroupIds()));
            $roles = array_filter( array_map('intval',explode(',',$role)));
            return  (count(array_intersect($roles, $groupIds)) >0);;
        }
        $roles = array_filter( array_map('trim',explode(',',$role)));
        return (count(array_intersect($roles, $userAspect->getGroupNames()))>0);
    }

Actions #3

Updated by Georg Ringer about 4 years ago

  • Status changed from New to Accepted
  • Target version set to Candidate for Major Version
Actions

Also available in: Atom PDF