Set the visibility of the menu item and any sub items in accordance
with the specified user role.

@param \Zend_Acl $acl
@param string $userRole
@return \Gems_Menu_MenuAbstract (continuation pattern)
512881
protected function applyAcl(\MUtil_Acl $acl, $userRole)
    {
        parent::applyAcl($acl, $userRole);

        if ($this->isVisible()) {
            $this->set('allowed', false);
            $this->set('visible', false);

            if ($this->_subItems) {
                foreach ($this->_subItems as $item) {

                    if ($item->get('visible', true)) {
                        $this->set('allowed', true);
                        $this->set('visible', true);

                        return $this;
                    }
                }
            }
        }
        return $this;
    }
660295
protected function setPodiumUserRole($user, $role)
    {
        $rbac = Podium::getInstance()->getRbac();
        $userRoles = $rbac->getRolesByUser($user->id);
        $podiumRoles = array_filter($userRoles, function ($role) {
            return strpos($role->name, 'podium') === 0;
        });
        foreach ($podiumRoles as $podiumRole) {
            $rbac->revoke($podiumRole, $user->id);
        }
        $rbac->assign($role, $user->id);
    }
233292
public function setUser(User $user): void
    {
        $this->user = $user;
        $this->user->setAcl($this);

        $userRole = $this->user->getRole();
        if ($userRole != null && !empty($this->rules)) {
            foreach ($this->rules as $role => $rules) {
                if ($userRole == $role) {
                    foreach ($rules as $uri => $rules) {
                        $this->user->setPermissionsOf($uri, (array) explode(',', $rules) /* 'read,write' etc. */);
                    }
                    break;
                }
            }
        }
    }
273599
private function _loadRoles(array $aclConfig)
	{
		foreach ($aclConfig as $role => $acl) {
			if (isset($acl[self::CONFIG_FIELD_RESOURCE])
				and is_array($acl[self::CONFIG_FIELD_RESOURCE])) {
				$this->_roles[$role] = $acl[self::CONFIG_FIELD_RESOURCE];
			} else {
				$this->_roles[$role] = array();
			}

			if (isset($acl[self::CONFIG_FIELD_INHERIT])
				and is_array($acl[self::CONFIG_FIELD_INHERIT])) {
				foreach ($acl[self::CONFIG_FIELD_INHERIT] as $inherit) {
					if (isset($aclConfig[$inherit][self::CONFIG_FIELD_RESOURCE])
						and is_array($aclConfig[$inherit][self::CONFIG_FIELD_RESOURCE])) {
						$this->_roles[$role] = array_merge($this->_roles[$role], $aclConfig[$inherit][self::CONFIG_FIELD_RESOURCE]);
					}
				}
			}
		}

		return $this->_roles;
	}
510409
public function removeUserRole(\CanalTP\SamCoreBundle\Entity\Role $userRole)
    {
        $this->userRoles->removeElement($userRole);
    }
1244194
def visible_for?(user)
      can_view_page = (
        if dropdown?
          true
        elsif menuable.kind_of?(Effective::Page)
          menuable.roles_permit?(user)
        else
          true
        end
      )

      can_view_menu_item = (
        if roles_mask == nil
          true
        elsif roles_mask == -1 # Am I logged out?
          user.blank?
        elsif roles_mask == 0 # Am I logged in?
          user.present?
        else
          roles_permit?(user)
        end
      )

      can_view_page && can_view_menu_item
    end
794068
public function edit(User $user, Role $role)
    {
        $this->authorize(UsersPolicy::PERMISSION_UPDATE);

        $user->load(['roles', 'roles.permissions']);
        $roles = $role->all();

        $this->setTitle($title = trans('auth::users.titles.edit-user'));
        $this->addBreadcrumb($title);

        return $this->view('admin.users.edit', compact('user', 'roles'));
    }
471955
public function setUserRole(\Dacorp\ExtraBundle\Entity\UserRole $userRole = null)
    {
        $this->userRole = $userRole;
    
        return $this;
    }
399840
public function removeRole(ChildRole $role)
    {
        if ($this->getRoles()->contains($role)) { $userRole = new ChildUserRole();

            $userRole->setRole($role);
            if ($role->isUsersLoaded()) {
                //remove the back reference if available
                $role->getUsers()->removeObject($this);
            }

            $userRole->setUser($this);
            $this->removeUserRole(clone $userRole);
            $userRole->clear();

            $this->collRoles->remove($this->collRoles->search($role));

            if (null === $this->rolesScheduledForDeletion) {
                $this->rolesScheduledForDeletion = clone $this->collRoles;
                $this->rolesScheduledForDeletion->clear();
            }

            $this->rolesScheduledForDeletion->push($role);
        }


        return $this;
    }
309872
public function setRoleToRoleSubject(AbstractRoleSubject $ars, $roleName, $validate = true)
    {
        $role = $this->roleRepo->findOneBy(['name' => $roleName]);

        if ($validate) {
            $validated = $this->validateRoleInsert($ars, $role);
        } else {
            $validated = true;
        }

        if (!$validated) {
            throw new Exception\AddRoleException();
        }

        if ('Claroline\CoreBundle\Entity\Group' === get_class($ars) && 'ROLE_USER' === $role->getName()) {
            throw new Exception\AddRoleException('ROLE_USER cannot be added to groups');
        }

        if (!is_null($role)) {
            $ars->addRole($role);
            $this->om->persist($ars);
            $this->om->flush();
        }
    }
240744
private static function injectGrant(AclAuthorization $acl, $grantType, array $ruleSet)
    {
        // Add new resource to ACL
        $resource = $ruleSet['resource'];
        $acl->addResource($ruleSet['resource']);

        // Deny guest specified privileges to resource
        $privileges = isset($ruleSet['privileges']) ? $ruleSet['privileges'] : null;

        // null privileges means no permissions were setup; nothing to do
        if (null === $privileges) {
            return;
        }

        $acl->$grantType('guest', $resource, $privileges);
    }
898840
public static function getComponentNodeConfig($component, $user, $acl, array &$componentConfigs = array())
    {
        $data = parent::getNodeConfig($component);
        $enabled = $acl->isAllowed($user, $component);
        if (!$enabled && !$component instanceof Kwf_Component_Data_Root/*root nicht überprüfen, die wird immar angezeigt*/) {
            $allowedComponents = $acl->getAllowedRecursiveChildComponents($user, $component);
            $allowed = false;
            foreach ($allowedComponents as $allowedComponent) {
                $c = $allowedComponent;
                while ($c) {
                    if ($c->componentId == $component->componentId) {
                        if (!$allowedComponent->isPage) {
                            if (self::_getAllEditComponents(array($allowedComponent), $user, $acl)) {
                                //es gibt bearbeiten buttons, seite anzeigen
                                $allowed = true;
                                break;
                            }
                            if (!$allowed) {
                                 //nächste allowComponent überprüfen
                                 continue 2;
                            }
                        } else {
                            //seiten sind immer erlaubt (wegen seiteneigenschaften)
                            $allowed = true;
                        }
                        break 2;
                    }
                    $c = $c->parent;
                }
            }
            //wenn gar keine unterkomponente bearbeitet werden kann seite ausblenden
            if (!$allowed) return null;
        }
        if (!$enabled) {
            //wenn eine unterkomponente (nicht seite!) bearbeitet werden kann seite nicht ausgrauen
            $editComponents = $acl->getAllowedChildComponents($user, $component);
            if ($editComponents) $enabled = true;
        } else {
            $editComponents = array($component);
        }

        $data['disabled'] = !$enabled;

        if ($component->componentId != 'root' && !$enabled) {
            $data['iconEffects'][] = 'forbidden';
        }

        if (!$acl->isAllowed($user, $component)) {
            //wenn komponente *selbst* nicht bearbeitbar ist actions deaktivieren
            //(in dem fall ist eine unterkomponente der seite bearbeitbar)
            $data['actions'] = array_merge($data['actions'], array(
                'delete' => false,
                'copy' => false,
                'visible' => false,
                'makeHome' => false,
            ));
            $data['allowDrag'] = false;
        }

        //wenn *unter* der seite eine page möglich ist (pageGenerator vorhanden) dann
        //hinzufügen + drop erlauben
        //das kann nicht im Generator ermittelt werden, der macht nur sich selbst
        if ($acl->isAllowed($user, $component)) {
            $pageGenerator = Kwf_Component_Generator_Abstract::getInstances($component, array(
                'pageGenerator' => true
            ));
            if ($pageGenerator && $pageGenerator[0] instanceof Kwc_Root_Category_Generator) {
                $data['actions']['add'] = true;
                $data['actions']['paste'] = true;
                $data['allowDrop'] = true;
            }
        }
        $data['actions']['preview'] = (bool)$component->isPage;

        //default werte
        $data['actions'] = array_merge(array(
            'properties' => !$data['disabled'],
            'delete' => false,
            'copy' => false,
            'paste' => false,
            'visible' => false,
            'makeHome' => false,
            'add' => false,
        ), $data['actions']);

        $data['editComponents'] = self::_getAllEditComponents($editComponents, $user, $acl, $componentConfigs);

        return $data;
    }
1277907
def add_acl(self, scope, user, permission):
        
        return self.send('plugin.acl.addAcl', scope, user, permission)
320790
protected function addUserRole()
    {
        $this->controlAccess('user_role_add');

        if ($this->role->add($this->getSubmitted())) {
            $this->redirect('admin/user/role', $this->text('Role has been added'), 'success');
        }

        $this->redirect('', $this->text('Role has not been added'), 'warning');
    }
422315
public function hasPrivilege($privilege, $current = true)
    {
        if (! $this->acl) {
            return true;
        }
        $role = $this->getRole($current);

        return $this->acl->isAllowed($role, null, $privilege);
    }
582098
public function hasRole()
    {
        if ($this->role instanceof Acl\Role\RoleInterface
            || is_string($this->role)
            || static::$defaultRole instanceof Acl\Role\RoleInterface
            || is_string(static::$defaultRole)
        ) {
            return true;
        }
    
        return false;
    }
1033857
public function setRole(Role $v = null)
    {
        if ($v === null) {
            $this->setRoleId(NULL);
        } else {
            $this->setRoleId($v->getId());
        }

        $this->aRole = $v;

        // Add binding for other direction of this n:n relationship.
        // If this object has already been added to the Role object, it will not be re-added.
        if ($v !== null) {
            $v->addUserRole($this);
        }


        return $this;
    }